Make WordPress Core

Changeset 51569


Ignore:
Timestamp:
08/07/2021 10:40:44 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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:

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.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r51568 r51569  
    11451145        $this->assertTrue( (bool) preg_match( '/data-customize-partial-placement-context="(.+?)"/', $result, $matches ) );
    11461146        $context = json_decode( html_entity_decode( $matches[1] ), true );
    1147         $this->assertSame( $original_args, wp_array_slice_assoc( $context, array_keys( $original_args ) ) ); // Because assertArraySubset is not available in PHP 5.2.
     1147
     1148        foreach ( $original_args as $key => $value ) {
     1149            $this->assertArrayHasKey( $key, $context );
     1150            $this->assertSame( $value, $context[ $key ] );
     1151        }
     1152
    11481153        $this->assertTrue( $context['can_partial_refresh'] );
    11491154    }
  • trunk/tests/phpunit/tests/widgets/wpWidgetMedia.php

    r51493 r51569  
    9696        $this->assertSame( $name, $widget->name );
    9797
    98         $this->assertArraySubset( $widget_options, $widget->widget_options );
    99         $this->assertArraySubset( $control_options, $widget->control_options );
     98        foreach ( $widget_options as $key => $value ) {
     99            $this->assertArrayHasKey( $key, $widget->widget_options );
     100            $this->assertSame( $value, $widget->widget_options[ $key ] );
     101        }
     102
     103        foreach ( $control_options as $key => $value ) {
     104            $this->assertArrayHasKey( $key, $widget->control_options );
     105            $this->assertSame( $value, $widget->control_options[ $key ] );
     106        }
    100107    }
    101108
Note: See TracChangeset for help on using the changeset viewer.