Skip to content

Commit

Permalink
Don't change error handling in WP_Theme_JSON_Gutenberg::set_spacing_s…
Browse files Browse the repository at this point in the history
…izes() (#55354)

Revert #55313  to mantain compability with Core.
  • Loading branch information
anton-vlasenko authored Oct 16, 2023
1 parent 3662bc4 commit 624f430
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

1 comment on commit 624f430

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 624f430.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6532551088
📝 Reported issues:

Please sign in to comment.