diff --git a/composer.json b/composer.json index 049343a9ef..46cc81b28a 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index f590642ef9..251d187a25 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -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." ); } } diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 1113a87eea..96a84b33f8 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -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, '<' ) ) diff --git a/tests/phpunit/includes/phpunit-adapter-testcase.php b/tests/phpunit/includes/phpunit-adapter-testcase.php index 423a9d2213..13ac7bdd06 100644 --- a/tests/phpunit/includes/phpunit-adapter-testcase.php +++ b/tests/phpunit/includes/phpunit-adapter-testcase.php @@ -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 diff --git a/tests/phpunit/tests/ajax/wpAjaxImageEditor.php b/tests/phpunit/tests/ajax/wpAjaxImageEditor.php index a06afa1f5c..ac761c3520 100644 --- a/tests/phpunit/tests/ajax/wpAjaxImageEditor.php +++ b/tests/phpunit/tests/ajax/wpAjaxImageEditor.php @@ -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 ); } diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index f3617f5fad..0a5047c6d1 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -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; diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index e3c6397b69..5be490107f 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -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.' diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index f9b9b49cec..d42133a1ba 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -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 ); } diff --git a/tests/phpunit/tests/customize/nav-menu-item-setting.php b/tests/phpunit/tests/customize/nav-menu-item-setting.php index 256e5f577c..22d4bc7de7 100644 --- a/tests/phpunit/tests/customize/nav-menu-item-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-item-setting.php @@ -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’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 ); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index e895dd9e76..548c5eb2ca 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -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 ); } diff --git a/tests/phpunit/tests/post/getPostTypeLabels.php b/tests/phpunit/tests/post/getPostTypeLabels.php index 9761e419b0..2a0e7f0d32 100644 --- a/tests/phpunit/tests/post/getPostTypeLabels.php +++ b/tests/phpunit/tests/post/getPostTypeLabels.php @@ -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' ) ); diff --git a/tests/phpunit/tests/post/updatePostCache.php b/tests/phpunit/tests/post/updatePostCache.php index cfb279b67c..9427ec6fbd 100644 --- a/tests/phpunit/tests/post/updatePostCache.php +++ b/tests/phpunit/tests/post/updatePostCache.php @@ -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' diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 9a12c2247b..b752b83872 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -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() { diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index f7f6bed9c5..266ca89a33 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -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".' ); diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 9b31b573a2..ce04e22a1b 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -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' ) ); diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 8a7e6e91eb..0e118a3c16 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -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 ); } } diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index 5c0faec53b..948ba1e1c3 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -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 ); } /** diff --git a/tests/phpunit/tests/user/multisite.php b/tests/phpunit/tests/user/multisite.php index 23079f4799..e3173db43e 100644 --- a/tests/phpunit/tests/user/multisite.php +++ b/tests/phpunit/tests/user/multisite.php @@ -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.