From 22060f3b06444f5fc2ce7cd020f0941819a58392 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 7 Aug 2021 10:40:44 +0000 Subject: [PATCH] Tests: Remove use of `assertArraySubset()` in `Test_WP_Widget_Media::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 * https://github.com/sebastianbergmann/phpunit/issues/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 --- tests/phpunit/tests/customize/nav-menus.php | 7 ++++++- tests/phpunit/tests/widgets/wpWidgetMedia.php | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 1b1ab2c21a..62550a5233 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -1144,7 +1144,12 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $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'] ); } diff --git a/tests/phpunit/tests/widgets/wpWidgetMedia.php b/tests/phpunit/tests/widgets/wpWidgetMedia.php index 74b3ac8b99..921e099770 100644 --- a/tests/phpunit/tests/widgets/wpWidgetMedia.php +++ b/tests/phpunit/tests/widgets/wpWidgetMedia.php @@ -95,8 +95,15 @@ class Tests_Widgets_wpWidgetMedia extends WP_UnitTestCase { $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 ] ); + } } /**