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
This commit is contained in:
Sergey Biryukov 2023-08-21 15:53:04 +00:00
parent 9b8a0d22b0
commit f0d53f8100
18 changed files with 48 additions and 48 deletions

View File

@ -17,7 +17,7 @@
"squizlabs/php_codesniffer": "3.6.0",
"wp-coding-standards/wpcs": "~2.3.0",
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
"yoast/phpunit-polyfills": "^1.0.1"
"yoast/phpunit-polyfills": "^1.1.0"
},
"config": {
"allow-plugins": {

View File

@ -869,7 +869,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
$this->assertNotEmpty( $fields, $message . ' Fields array is empty.' );
foreach ( $fields as $field_name => $field_value ) {
$this->assertObjectHasAttribute( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
$this->assertObjectHasProperty( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
$this->assertSame( $field_value, $actual->$field_name, $message . " Value of property $field_name is not $field_value." );
}
}

View File

@ -139,7 +139,7 @@ unset( $phpunit_polyfills_autoloader, $phpunit_polyfills_error, $phpunit_polyfil
* Minimum version of the PHPUnit Polyfills package as declared in `composer.json`.
* Only needs updating when new polyfill features start being used in the test suite.
*/
$phpunit_polyfills_minimum_version = '1.0.1';
$phpunit_polyfills_minimum_version = '1.1.0';
if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' )
&& ( defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) === false
|| version_compare( Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) )

View File

@ -6,7 +6,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase as Polyfill_TestCase;
* PHPUnit adapter layer.
*
* This class enhances the PHPUnit native `TestCase` with polyfills
* for assertions and expectation methods added between PHPUnit 4.8 - 9.5.
* for assertions and expectation methods added between PHPUnit 4.8 - 9.6.
*
* Additionally, the Polyfill TestCase offers a workaround for the addition
* of the `void` return type to PHPUnit fixture methods by providing

View File

@ -51,7 +51,7 @@ class Tests_Ajax_wpAjaxImageEditor extends WP_Ajax_UnitTestCase {
$ret = wp_save_image( $id );
$this->assertObjectHasAttribute( 'error', $ret );
$this->assertObjectHasProperty( 'error', $ret );
$this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error );
}

View File

@ -720,7 +720,7 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
$registry = WP_Block_Type_Registry::get_instance();
$block_type = $registry->get_registered( 'core/test-static' );
$this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
$this->assertObjectHasProperty( 'editor_script_handles', $block_type );
$actual_script = $block_type->editor_script;
$actual_script_handles = $block_type->editor_script_handles;
@ -786,7 +786,7 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
$registry = WP_Block_Type_Registry::get_instance();
$block_type = $registry->get_registered( 'core/test-static' );
$this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
$this->assertObjectHasProperty( 'editor_script_handles', $block_type );
$actual_script = $block_type->editor_script;
$actual_script_handles = $block_type->editor_script_handles;

View File

@ -481,7 +481,7 @@ class Tests_Comment extends WP_UnitTestCase {
'The comment is not an instance of WP_Comment.'
);
$this->assertObjectHasAttribute(
$this->assertObjectHasProperty(
'comment_author',
$comment,
'The comment object does not have a "comment_author" property.'

View File

@ -3339,14 +3339,14 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$setting_id = 'dynamic';
$setting = $manager->add_setting( $setting_id );
$this->assertSame( 'WP_Customize_Setting', get_class( $setting ) );
$this->assertObjectNotHasAttribute( 'custom', $setting );
$this->assertObjectNotHasProperty( 'custom', $setting );
$manager->remove_setting( $setting_id );
add_filter( 'customize_dynamic_setting_class', array( $this, 'return_dynamic_customize_setting_class' ), 10, 3 );
add_filter( 'customize_dynamic_setting_args', array( $this, 'return_dynamic_customize_setting_args' ), 10, 2 );
$setting = $manager->add_setting( $setting_id );
$this->assertSame( 'Test_Dynamic_Customize_Setting', get_class( $setting ) );
$this->assertObjectHasAttribute( 'custom', $setting );
$this->assertObjectHasProperty( 'custom', $setting );
$this->assertSame( 'foo', $setting->custom );
}

View File

@ -926,17 +926,17 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
$this->assertSame( 'Custom Label', $nav_menu_item->type_label );
$this->assertObjectNotHasAttribute( 'nav_menu_term_id', $nav_menu_item );
$this->assertObjectNotHasAttribute( 'status', $nav_menu_item );
$this->assertObjectNotHasProperty( 'nav_menu_term_id', $nav_menu_item );
$this->assertObjectNotHasProperty( 'status', $nav_menu_item );
$this->assertSame( 'publish', $nav_menu_item->post_status );
$this->assertSame( 'nav_menu_item', $nav_menu_item->post_type );
$this->assertObjectNotHasAttribute( 'position', $nav_menu_item );
$this->assertObjectNotHasProperty( 'position', $nav_menu_item );
$this->assertSame( $post_value['position'], $nav_menu_item->menu_order );
$this->assertSame( $post_value['title'], $nav_menu_item->post_title );
$this->assertSame( 123, $nav_menu_item->ID );
$this->assertSame( 123, $nav_menu_item->db_id );
$this->assertSame( wp_get_current_user()->ID, $nav_menu_item->post_author );
$this->assertObjectHasAttribute( 'type_label', $nav_menu_item );
$this->assertObjectHasProperty( 'type_label', $nav_menu_item );
$expected = apply_filters( 'nav_menu_attr_title', wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $post_value['attr_title'] ) ) ) );
$this->assertSame( $expected, $nav_menu_item->attr_title );
$this->assertSame( 'Attempted \o/ o&#8217;o markup', $nav_menu_item->description );
@ -1070,7 +1070,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( $original_post_title, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( $original_post_title, $item->original_title );
$this->assertSame( $original_post_title, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );
@ -1097,7 +1097,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( $original_post_title, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( $original_post_title, $item->original_title );
$this->assertSame( $original_post_title, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );
@ -1124,7 +1124,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( $original_term_title, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( $original_term_title, $item->original_title );
$this->assertSame( $original_term_title, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );
@ -1151,7 +1151,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( $original_term_title, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( $original_term_title, $item->original_title );
$this->assertSame( $original_term_title, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );
@ -1177,7 +1177,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );
@ -1203,7 +1203,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] );
$this->assertSame( '', $item_value['title'] );
$item = $setting->value_as_wp_post_nav_menu_item();
$this->assertObjectHasAttribute( 'type_label', $item );
$this->assertObjectHasProperty( 'type_label', $item );
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
$this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
$this->assertArrayHasKey( 'type_label', $item_value );

View File

@ -236,7 +236,7 @@ class Tests_Post extends WP_UnitTestCase {
register_post_status( 'test' );
$counts = wp_count_posts();
$this->assertObjectHasAttribute( 'test', $counts );
$this->assertObjectHasProperty( 'test', $counts );
$this->assertSame( 0, $counts->test );
}

View File

@ -95,9 +95,9 @@ class Tests_Post_GetPostTypeLabels extends WP_UnitTestCase {
unregister_post_type( 'foo' );
$this->assertObjectHasAttribute( 'labels', $post_type_object );
$this->assertObjectHasAttribute( 'label', $post_type_object );
$this->assertObjectHasAttribute( 'not_found_in_trash', $post_type_object->labels );
$this->assertObjectHasProperty( 'labels', $post_type_object );
$this->assertObjectHasProperty( 'label', $post_type_object );
$this->assertObjectHasProperty( 'not_found_in_trash', $post_type_object->labels );
}
public function test_label_should_be_derived_from_labels_when_registering_a_post_type() {
@ -122,8 +122,8 @@ class Tests_Post_GetPostTypeLabels extends WP_UnitTestCase {
add_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
register_post_type( 'foo' );
$this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
$this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
$this->assertObjectHasProperty( 'featured_image', get_post_type_object( 'foo' )->labels );
$this->assertObjectHasProperty( 'set_featured_image', get_post_type_object( 'foo' )->labels );
unregister_post_type( 'foo' );
remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );

View File

@ -57,7 +57,7 @@ class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
'The cached post is not an object'
);
$this->assertObjectHasAttribute(
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'
@ -98,7 +98,7 @@ class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
'The cached post is not an object'
);
$this->assertObjectHasAttribute(
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'
@ -126,7 +126,7 @@ class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
'The cached post is not an object'
);
$this->assertObjectHasAttribute(
$this->assertObjectHasProperty(
'filter',
$cached_post,
'The cached post does not have a "filter" property'

View File

@ -1261,7 +1261,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
$result = json_decode( rest_get_server()->sent_body );
$this->assertObjectNotHasAttribute( 'code', $result );
$this->assertObjectNotHasProperty( 'code', $result );
}
public function test_link_header_on_requests() {

View File

@ -870,13 +870,13 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
$this->assertInstanceOf( 'stdClass', $prepared, 'The item could not be prepared for the database.' );
$this->assertObjectHasAttribute( 'post_type', $prepared, 'The "post_type" was not included in the prepared template part.' );
$this->assertObjectHasAttribute( 'post_status', $prepared, 'The "post_status" was not included in the prepared template part.' );
$this->assertObjectHasAttribute( 'tax_input', $prepared, 'The "tax_input" was not included in the prepared template part.' );
$this->assertObjectHasProperty( 'post_type', $prepared, 'The "post_type" was not included in the prepared template part.' );
$this->assertObjectHasProperty( 'post_status', $prepared, 'The "post_status" was not included in the prepared template part.' );
$this->assertObjectHasProperty( 'tax_input', $prepared, 'The "tax_input" was not included in the prepared template part.' );
$this->assertArrayHasKey( 'wp_theme', $prepared->tax_input, 'The "wp_theme" tax was not included in the prepared template part.' );
$this->assertArrayHasKey( 'wp_template_part_area', $prepared->tax_input, 'The "wp_template_part_area" tax was not included in the prepared template part.' );
$this->assertObjectHasAttribute( 'post_content', $prepared, 'The "post_content" was not included in the prepared template part.' );
$this->assertObjectHasAttribute( 'post_title', $prepared, 'The "post_title" was not included in the prepared template part.' );
$this->assertObjectHasProperty( 'post_content', $prepared, 'The "post_content" was not included in the prepared template part.' );
$this->assertObjectHasProperty( 'post_title', $prepared, 'The "post_title" was not included in the prepared template part.' );
$this->assertSame( 'wp_template_part', $prepared->post_type, 'The "post_type" in the prepared template part should be "wp_template_part".' );
$this->assertSame( 'publish', $prepared->post_status, 'The post status in the prepared template part should be "publish".' );

View File

@ -284,7 +284,7 @@ class Tests_Taxonomy extends WP_UnitTestCase {
// Create a post type to test with.
$post_type = 'test_cpt';
$this->assertFalse( get_post_type( $post_type ) );
$this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
$this->assertObjectHasProperty( 'name', register_post_type( $post_type ) );
// Core taxonomy, core post type.
$this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) );

View File

@ -402,7 +402,7 @@ class Tests_Term_Query extends WP_UnitTestCase {
$this->assertNotEmpty( $terms );
foreach ( $terms as $term ) {
$this->assertInstanceOf( 'WP_Term', $term );
$this->assertObjectHasAttribute( 'object_id', $term );
$this->assertObjectHasProperty( 'object_id', $term );
}
// Run again to check the cached response.
@ -410,7 +410,7 @@ class Tests_Term_Query extends WP_UnitTestCase {
$this->assertNotEmpty( $terms );
foreach ( $terms as $term ) {
$this->assertInstanceOf( 'WP_Term', $term );
$this->assertObjectHasAttribute( 'object_id', $term );
$this->assertObjectHasProperty( 'object_id', $term );
}
}

View File

@ -850,7 +850,7 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
}
$term = get_term( $t );
$this->assertObjectNotHasAttribute( 'object_id', $term );
$this->assertObjectNotHasProperty( 'object_id', $term );
}
/**

View File

@ -59,15 +59,15 @@ if ( is_multisite() ) :
// Each site retrieved should match the expected structure.
foreach ( $blogs_of_user as $blog_id => $blog ) {
$this->assertSame( $blog_id, $blog->userblog_id );
$this->assertObjectHasAttribute( 'userblog_id', $blog );
$this->assertObjectHasAttribute( 'blogname', $blog );
$this->assertObjectHasAttribute( 'domain', $blog );
$this->assertObjectHasAttribute( 'path', $blog );
$this->assertObjectHasAttribute( 'site_id', $blog );
$this->assertObjectHasAttribute( 'siteurl', $blog );
$this->assertObjectHasAttribute( 'archived', $blog );
$this->assertObjectHasAttribute( 'spam', $blog );
$this->assertObjectHasAttribute( 'deleted', $blog );
$this->assertObjectHasProperty( 'userblog_id', $blog );
$this->assertObjectHasProperty( 'blogname', $blog );
$this->assertObjectHasProperty( 'domain', $blog );
$this->assertObjectHasProperty( 'path', $blog );
$this->assertObjectHasProperty( 'site_id', $blog );
$this->assertObjectHasProperty( 'siteurl', $blog );
$this->assertObjectHasProperty( 'archived', $blog );
$this->assertObjectHasProperty( 'spam', $blog );
$this->assertObjectHasProperty( 'deleted', $blog );
}
// Mark each remaining site as spam, archived, and deleted.