Editor: Ensure PHPUnit10 compatibility for ThemeJson unit test.

Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE errors is deprecated in PHPUnit 10.
This updates the test to rely on an exception instead.

Props antonvlasenko.
Fixes #60305.

git-svn-id: https://develop.svn.wordpress.org/trunk@57332 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Riad Benguella
2024-01-23 08:57:48 +00:00
parent 2e3b292924
commit d0262ec696

View File

@@ -4281,8 +4281,8 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
* @param array $expected_output Expected output from data provider.
*/
public function test_set_spacing_sizes_should_detect_invalid_spacing_scale( $spacing_scale, $expected_output ) {
$this->expectNotice();
$this->expectNoticeMessage( 'Some of the theme.json settings.spacing.spacingScale values are invalid' );
$this->expectException( Exception::class );
$this->expectExceptionMessage( 'Some of the theme.json settings.spacing.spacingScale values are invalid' );
$theme_json = new WP_Theme_JSON(
array(
@@ -4295,6 +4295,15 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
)
);
// Ensure PHPUnit 10 compatibility.
set_error_handler(
static function ( $errno, $errstr ) {
restore_error_handler();
throw new Exception( $errstr, $errno );
},
E_ALL
);
$theme_json->set_spacing_sizes();
$this->assertSame( $expected_output, _wp_array_get( $theme_json->get_raw_data(), array( 'settings', 'spacing', 'spacingSizes', 'default' ) ) );
}