Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change error handling in WP_Theme_JSON_Gutenberg::set_spacing_sizes() #55354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3389,7 +3389,7 @@ public function set_spacing_sizes() {
|| ! is_numeric( $spacing_scale['mediumStep'] )
|| ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) {
if ( ! empty( $spacing_scale ) ) {
_doing_it_wrong( __METHOD__, __( 'Some of the theme.json settings.spacing.spacingScale values are invalid', 'gutenberg' ), '6.1.0' );
trigger_error( __( 'Some of the theme.json settings.spacing.spacingScale values are invalid', 'gutenberg' ), E_USER_NOTICE );
}
return null;
}
Expand Down
12 changes: 11 additions & 1 deletion phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,8 @@ public function data_generate_spacing_scale_fixtures() {
* @dataProvider data_set_spacing_sizes_when_invalid
*/
public function test_set_spacing_sizes_when_invalid( $spacing_scale, $expected_output ) {
$this->setExpectedIncorrectUsage( 'WP_Theme_JSON_Gutenberg::set_spacing_sizes' );
$this->expectException( Exception::class );
$this->expectExceptionMessage( 'Some of the theme.json settings.spacing.spacingScale values are invalid' );

$theme_json = new WP_Theme_JSON_Gutenberg(
array(
Expand All @@ -1295,6 +1296,15 @@ public function test_set_spacing_sizes_when_invalid( $spacing_scale, $expected_o
)
);

// 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' ) ) );
}
Expand Down