Skip to content

Commit

Permalink
Tests: Remove use of assertArraySubset() in `Test_WP_Widget_Media::…
Browse files Browse the repository at this point in the history
…test_constructor()`.

The `assertArraySubset()` method has been deprecated in PHPUnit 8 and removed in PHPUnit 9.

This replaces the assertions with looping through the array and testing both the key and the value individually.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#800---2019-02-01
* sebastianbergmann/phpunit#3494

Note: There is a polyfill package available for the removed assertion: `dms/phpunit-arraysubset-asserts`, but as the assertion was only used in this one test method, adding this seems redundant.

Follow-up to [51559-51568].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51569 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov authored and SergeyBiryukov committed Aug 7, 2021
1 parent cb53fc6 commit 2fa363f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion tests/phpunit/tests/customize/nav-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,12 @@ function test_filter_wp_nav_menu() {
$this->assertStringContainsString( ' data-customize-partial-type="nav_menu_instance"', $result );
$this->assertTrue( (bool) preg_match( '/data-customize-partial-placement-context="(.+?)"/', $result, $matches ) );
$context = json_decode( html_entity_decode( $matches[1] ), true );
$this->assertSame( $original_args, wp_array_slice_assoc( $context, array_keys( $original_args ) ) ); // Because assertArraySubset is not available in PHP 5.2.

foreach ( $original_args as $key => $value ) {
$this->assertArrayHasKey( $key, $context );
$this->assertSame( $value, $context[ $key ] );
}

$this->assertTrue( $context['can_partial_refresh'] );
}

Expand Down
11 changes: 9 additions & 2 deletions tests/phpunit/tests/widgets/wpWidgetMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ function test_constructor() {
$this->assertSame( $id_base, $widget->id_base );
$this->assertSame( $name, $widget->name );

$this->assertArraySubset( $widget_options, $widget->widget_options );
$this->assertArraySubset( $control_options, $widget->control_options );
foreach ( $widget_options as $key => $value ) {
$this->assertArrayHasKey( $key, $widget->widget_options );
$this->assertSame( $value, $widget->widget_options[ $key ] );
}

foreach ( $control_options as $key => $value ) {
$this->assertArrayHasKey( $key, $widget->control_options );
$this->assertSame( $value, $widget->control_options[ $key ] );
}
}

/**
Expand Down

0 comments on commit 2fa363f

Please sign in to comment.