Skip to content

Commit f0d53f8

Browse files
Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0.
[https://github.com/sebastianbergmann/phpunit/blob/9.6/ChangeLog-9.6.md#961---2023-02-03 PHPUnit 9.6.1] deprecated the `assertObjectHasAttribute()` and `assertObjectNotHasAttribute()` methods, leading to deprecation notices in a number of tests. [https://github.com/sebastianbergmann/phpunit/blob/10.1.3/ChangeLog-10.1.md#1010---2023-04-14 PHPUnit 10.1.0] brought the methods back by popular request, though renamed as `assertObjectHasProperty()` and `assertObjectNotHasProperty()`, to prevent confusion with PHP 8.0 attributes. This meant that users which cannot (yet) upgrade to PHPUnit 10.1+ would always have deprecation notices for these methods without recourse. So, after much discussion, the new methods have been backported to [https://github.com/sebastianbergmann/phpunit/blob/9.6/ChangeLog-9.6.md#9611---2023-08-19 PHPUnit 9.6.11], leaving just the 10.0.x series with a deprecation notice and no recourse. What does this mean for WordPress? WordPress uses the [https://github.com/Yoast/PHPUnit-Polyfills PHPUnit Polyfills] to be able to write tests for the most recent versions of PHPUnit, with the Polyfills taking care of polyfilling any new PHPUnit methods on older PHPUnit versions. * The PHPUnit Polyfills 1.x series supports PHPUnit 4.x to 9.x. * The PHPUnit Polyfills 2.x series supports PHPUnit 5.x to 10.x. WordPress currently runs against PHPUnit 6.x to 9.x with PHPUnit Polyfills 1.x, while the new methods were previously only included in PHPUnit Polyfills 2.0.0+, as they were introduced in PHPUnit 10.x. Since the `assertObjectHasProperty()` and `assertObjectNotHasProperty()` methods have been backported to PHPUnit 9.x, the PHPUnit Polyfills will now include these methods in the 1.x series as well. By upgrading to the latest [https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.1.0 PHPUnit Polyfills 1.1.0] release, we can get rid of the deprecation notices related to the use of the `assertObjectHasAttribute()` and `assertObjectNotHasAttribute()` methods. This could have implications for plugins or themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series). The solution for those plugins or themes is to update their version constraints for the PHPUnit Polyfills to allow for the 1.1.x series. Follow-up to [51559], [51598]. Props jrf, ayeshrajans. Fixes #59150. git-svn-id: https://develop.svn.wordpress.org/trunk@56421 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9b8a0d2 commit f0d53f8

18 files changed

Lines changed: 48 additions & 48 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"squizlabs/php_codesniffer": "3.6.0",
1818
"wp-coding-standards/wpcs": "~2.3.0",
1919
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
20-
"yoast/phpunit-polyfills": "^1.0.1"
20+
"yoast/phpunit-polyfills": "^1.1.0"
2121
},
2222
"config": {
2323
"allow-plugins": {

tests/phpunit/includes/abstract-testcase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public function assertEqualFields( $actual, $fields, $message = '' ) {
869869
$this->assertNotEmpty( $fields, $message . ' Fields array is empty.' );
870870

871871
foreach ( $fields as $field_name => $field_value ) {
872-
$this->assertObjectHasAttribute( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
872+
$this->assertObjectHasProperty( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
873873
$this->assertSame( $field_value, $actual->$field_name, $message . " Value of property $field_name is not $field_value." );
874874
}
875875
}

tests/phpunit/includes/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
* Minimum version of the PHPUnit Polyfills package as declared in `composer.json`.
140140
* Only needs updating when new polyfill features start being used in the test suite.
141141
*/
142-
$phpunit_polyfills_minimum_version = '1.0.1';
142+
$phpunit_polyfills_minimum_version = '1.1.0';
143143
if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' )
144144
&& ( defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) === false
145145
|| version_compare( Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) )

tests/phpunit/includes/phpunit-adapter-testcase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* PHPUnit adapter layer.
77
*
88
* This class enhances the PHPUnit native `TestCase` with polyfills
9-
* for assertions and expectation methods added between PHPUnit 4.8 - 9.5.
9+
* for assertions and expectation methods added between PHPUnit 4.8 - 9.6.
1010
*
1111
* Additionally, the Polyfill TestCase offers a workaround for the addition
1212
* of the `void` return type to PHPUnit fixture methods by providing

tests/phpunit/tests/ajax/wpAjaxImageEditor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testCropImageIntoLargerOne() {
5151

5252
$ret = wp_save_image( $id );
5353

54-
$this->assertObjectHasAttribute( 'error', $ret );
54+
$this->assertObjectHasProperty( 'error', $ret );
5555
$this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error );
5656
}
5757

tests/phpunit/tests/blocks/register.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ public function test_register_block_type_accepts_editor_script_array( $editor_sc
720720

721721
$registry = WP_Block_Type_Registry::get_instance();
722722
$block_type = $registry->get_registered( 'core/test-static' );
723-
$this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
723+
$this->assertObjectHasProperty( 'editor_script_handles', $block_type );
724724
$actual_script = $block_type->editor_script;
725725
$actual_script_handles = $block_type->editor_script_handles;
726726

@@ -786,7 +786,7 @@ public function test_register_block_type_throws_doing_it_wrong( $editor_script,
786786

787787
$registry = WP_Block_Type_Registry::get_instance();
788788
$block_type = $registry->get_registered( 'core/test-static' );
789-
$this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
789+
$this->assertObjectHasProperty( 'editor_script_handles', $block_type );
790790
$actual_script = $block_type->editor_script;
791791
$actual_script_handles = $block_type->editor_script_handles;
792792

tests/phpunit/tests/comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public function test_should_output_the_author_of_an_approved_comment() {
481481
'The comment is not an instance of WP_Comment.'
482482
);
483483

484-
$this->assertObjectHasAttribute(
484+
$this->assertObjectHasProperty(
485485
'comment_author',
486486
$comment,
487487
'The comment object does not have a "comment_author" property.'

tests/phpunit/tests/customize/manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,14 +3339,14 @@ public function test_add_setting_honoring_dynamic() {
33393339
$setting_id = 'dynamic';
33403340
$setting = $manager->add_setting( $setting_id );
33413341
$this->assertSame( 'WP_Customize_Setting', get_class( $setting ) );
3342-
$this->assertObjectNotHasAttribute( 'custom', $setting );
3342+
$this->assertObjectNotHasProperty( 'custom', $setting );
33433343
$manager->remove_setting( $setting_id );
33443344

33453345
add_filter( 'customize_dynamic_setting_class', array( $this, 'return_dynamic_customize_setting_class' ), 10, 3 );
33463346
add_filter( 'customize_dynamic_setting_args', array( $this, 'return_dynamic_customize_setting_args' ), 10, 2 );
33473347
$setting = $manager->add_setting( $setting_id );
33483348
$this->assertSame( 'Test_Dynamic_Customize_Setting', get_class( $setting ) );
3349-
$this->assertObjectHasAttribute( 'custom', $setting );
3349+
$this->assertObjectHasProperty( 'custom', $setting );
33503350
$this->assertSame( 'foo', $setting->custom );
33513351
}
33523352

tests/phpunit/tests/customize/nav-menu-item-setting.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,17 +926,17 @@ public function test_value_as_wp_post_nav_menu_item() {
926926
$nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
927927
$this->assertSame( 'Custom Label', $nav_menu_item->type_label );
928928

929-
$this->assertObjectNotHasAttribute( 'nav_menu_term_id', $nav_menu_item );
930-
$this->assertObjectNotHasAttribute( 'status', $nav_menu_item );
929+
$this->assertObjectNotHasProperty( 'nav_menu_term_id', $nav_menu_item );
930+
$this->assertObjectNotHasProperty( 'status', $nav_menu_item );
931931
$this->assertSame( 'publish', $nav_menu_item->post_status );
932932
$this->assertSame( 'nav_menu_item', $nav_menu_item->post_type );
933-
$this->assertObjectNotHasAttribute( 'position', $nav_menu_item );
933+
$this->assertObjectNotHasProperty( 'position', $nav_menu_item );
934934
$this->assertSame( $post_value['position'], $nav_menu_item->menu_order );
935935
$this->assertSame( $post_value['title'], $nav_menu_item->post_title );
936936
$this->assertSame( 123, $nav_menu_item->ID );
937937
$this->assertSame( 123, $nav_menu_item->db_id );
938938
$this->assertSame( wp_get_current_user()->ID, $nav_menu_item->post_author );
939-
$this->assertObjectHasAttribute( 'type_label', $nav_menu_item );
939+
$this->assertObjectHasProperty( 'type_label', $nav_menu_item );
940940
$expected = apply_filters( 'nav_menu_attr_title', wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $post_value['attr_title'] ) ) ) );
941941
$this->assertSame( $expected, $nav_menu_item->attr_title );
942942
$this->assertSame( 'Attempted \o/ o&#8217;o markup', $nav_menu_item->description );
@@ -1070,7 +1070,7 @@ public function test_get_original_title() {
10701070
$this->assertSame( $original_post_title, $item_value['original_title'] );
10711071
$this->assertSame( '', $item_value['title'] );
10721072
$item = $setting->value_as_wp_post_nav_menu_item();
1073-
$this->assertObjectHasAttribute( 'type_label', $item );
1073+
$this->assertObjectHasProperty( 'type_label', $item );
10741074
$this->assertSame( $original_post_title, $item->original_title );
10751075
$this->assertSame( $original_post_title, $item->title );
10761076
$this->assertArrayHasKey( 'type_label', $item_value );
@@ -1097,7 +1097,7 @@ public function test_get_original_title() {
10971097
$this->assertSame( $original_post_title, $item_value['original_title'] );
10981098
$this->assertSame( '', $item_value['title'] );
10991099
$item = $setting->value_as_wp_post_nav_menu_item();
1100-
$this->assertObjectHasAttribute( 'type_label', $item );
1100+
$this->assertObjectHasProperty( 'type_label', $item );
11011101
$this->assertSame( $original_post_title, $item->original_title );
11021102
$this->assertSame( $original_post_title, $item->title );
11031103
$this->assertArrayHasKey( 'type_label', $item_value );
@@ -1124,7 +1124,7 @@ public function test_get_original_title() {
11241124
$this->assertSame( $original_term_title, $item_value['original_title'] );
11251125
$this->assertSame( '', $item_value['title'] );
11261126
$item = $setting->value_as_wp_post_nav_menu_item();
1127-
$this->assertObjectHasAttribute( 'type_label', $item );
1127+
$this->assertObjectHasProperty( 'type_label', $item );
11281128
$this->assertSame( $original_term_title, $item->original_title );
11291129
$this->assertSame( $original_term_title, $item->title );
11301130
$this->assertArrayHasKey( 'type_label', $item_value );
@@ -1151,7 +1151,7 @@ public function test_get_original_title() {
11511151
$this->assertSame( $original_term_title, $item_value['original_title'] );
11521152
$this->assertSame( '', $item_value['title'] );
11531153
$item = $setting->value_as_wp_post_nav_menu_item();
1154-
$this->assertObjectHasAttribute( 'type_label', $item );
1154+
$this->assertObjectHasProperty( 'type_label', $item );
11551155
$this->assertSame( $original_term_title, $item->original_title );
11561156
$this->assertSame( $original_term_title, $item->title );
11571157
$this->assertArrayHasKey( 'type_label', $item_value );
@@ -1177,7 +1177,7 @@ public function test_get_original_title() {
11771177
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] );
11781178
$this->assertSame( '', $item_value['title'] );
11791179
$item = $setting->value_as_wp_post_nav_menu_item();
1180-
$this->assertObjectHasAttribute( 'type_label', $item );
1180+
$this->assertObjectHasProperty( 'type_label', $item );
11811181
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
11821182
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
11831183
$this->assertArrayHasKey( 'type_label', $item_value );
@@ -1203,7 +1203,7 @@ public function test_get_original_title() {
12031203
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] );
12041204
$this->assertSame( '', $item_value['title'] );
12051205
$item = $setting->value_as_wp_post_nav_menu_item();
1206-
$this->assertObjectHasAttribute( 'type_label', $item );
1206+
$this->assertObjectHasProperty( 'type_label', $item );
12071207
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
12081208
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
12091209
$this->assertArrayHasKey( 'type_label', $item_value );

tests/phpunit/tests/post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function test_wp_count_posts_status_changes_visible() {
236236
register_post_status( 'test' );
237237

238238
$counts = wp_count_posts();
239-
$this->assertObjectHasAttribute( 'test', $counts );
239+
$this->assertObjectHasProperty( 'test', $counts );
240240
$this->assertSame( 0, $counts->test );
241241
}
242242

0 commit comments

Comments
 (0)