From 85ae9dd89b4c91f61a3517f7c41813f53cde87fd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 22 Aug 2022 22:42:59 +0000 Subject: [PATCH] Tests: Consistently skip tests for non-implemented methods in REST API test classes. WordPress core test suite uses PHPUnit's `beStrictAboutTestsThatDoNotTestAnything` option set to `true`, which marks a test as risky when no assertions are performed. REST API test classes have some empty tests for non-implemented methods because these test classes extend the abstract `WP_Test_REST_Controller_Testcase` class, which requires several methods to be implemented that don't necessarily make sense for all REST API routes. Some of these empty tests were already marked as skipped, but not in a consistent manner. Since skipping these tests is intentional for the time being, this commit aims to bring some consistency and adjust them all to be more accurately reported as skipped instead of risky. The skipping can be reconsidered in the future when the tests are either removed as unnecessary or updated to actually perform assertions related to their behavior. Follow-up to [40534], [41176], [41228]. Props Mte90, tomepajk, johnbillion, zieladam, SergeyBiryukov. See #40538, #41463, #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53921 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/rest-autosaves-controller.php | 2 +- .../rest-block-directory-controller.php | 8 +++---- .../rest-block-renderer-controller.php | 4 ++-- .../rest-api/rest-block-type-controller.php | 18 +++++++++----- .../rest-global-styles-controller.php | 2 +- .../tests/rest-api/rest-pages-controller.php | 8 +++---- .../rest-pattern-directory-controller.php | 8 +++---- .../rest-api/rest-settings-controller.php | 4 ++++ .../rest-api/rest-sidebars-controller.php | 9 ++++--- .../tests/rest-api/rest-themes-controller.php | 16 +++++++++---- .../rest-api/rest-widget-types-controller.php | 18 +++++++++----- .../rest-api/rest-widgets-controller.php | 4 +++- ...wpRestBlockPatternCategoriesController.php | 14 +++++------ .../wpRestBlockPatternsController.php | 14 +++++------ .../wpRestEditSiteExportController.php | 2 +- .../wpRestMenuLocationsController.php | 24 ++++++++++++------- .../rest-api/wpRestTemplatesController.php | 2 +- .../rest-api/wpRestUrlDetailsController.php | 12 +++++----- 18 files changed, 103 insertions(+), 66 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php index cf85a864be..5b3d450f22 100644 --- a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php +++ b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php @@ -270,7 +270,7 @@ class WP_Test_REST_Autosaves_Controller extends WP_Test_REST_Post_Type_Controlle } public function test_delete_item() { - // Doesn't exist. + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } public function test_prepare_item() { diff --git a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php index 4658b0ae7e..12af55d3e3 100644 --- a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php @@ -131,19 +131,19 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te } public function test_get_item() { - $this->markTestSkipped( 'Controller does not have get_item route.' ); + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_create_item() { - $this->markTestSkipped( 'Controller does not have create_item route.' ); + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { - $this->markTestSkipped( 'Controller does not have update_item route.' ); + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { - $this->markTestSkipped( 'Controller does not have delete_item route.' ); + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php index 454bc6da35..a2af93f990 100644 --- a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php @@ -641,10 +641,10 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca } /** - * The context_param() method does not exist for block rendering. + * The get_context_param() method is not used for block rendering. */ public function test_context_param() { - $this->markTestSkipped( 'Controller does not implement context_param().' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index 03b77d624c..58f8e755f0 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -551,17 +551,23 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase { } /** - * The test_create_item() method does not exist for block types. + * The create_item() method does not exist for block types. */ - public function test_create_item() {} + public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); + } /** - * The test_update_item() method does not exist for block types. + * The update_item() method does not exist for block types. */ - public function test_update_item() {} + public function test_update_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); + } /** - * The test_delete_item() method does not exist for block types. + * The delete_item() method does not exist for block types. */ - public function test_delete_item() {} + public function test_delete_item() { + $this->markTestSkipped( 'Controller does not implement delete_item().' ); + } } diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php index c8df046ca0..e8756cf85d 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php @@ -125,7 +125,7 @@ class WP_REST_Global_Styles_Controller_Test extends WP_Test_REST_Controller_Test } public function test_context_param() { - $this->markTestSkipped( 'Controller does not implement context_param().' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } public function test_get_items() { diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index da24a13d9b..2fc2ab2541 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -410,7 +410,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_get_item() { - + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_get_item_invalid_post_type() { @@ -421,7 +421,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_create_item() { - + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_create_item_with_template() { @@ -486,7 +486,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_update_item() { - + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { @@ -509,7 +509,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_prepare_item() { - + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } public function test_prepare_item_limit_fields() { diff --git a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php index 8c6e79f7a8..ddcaf0f0f0 100644 --- a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php @@ -311,19 +311,19 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_ } public function test_get_item() { - $this->markTestSkipped( 'Controller does not have get_item route.' ); + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_create_item() { - $this->markTestSkipped( 'Controller does not have create_item route.' ); + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { - $this->markTestSkipped( 'Controller does not have update_item route.' ); + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { - $this->markTestSkipped( 'Controller does not have delete_item route.' ); + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index 3c11935414..05adf234d5 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -71,6 +71,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase } public function test_context_param() { + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } public function test_get_item_is_not_public_not_authenticated() { @@ -379,6 +380,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { @@ -659,9 +661,11 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase } public function test_prepare_item() { + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } public function test_get_item_schema() { + $this->markTestSkipped( 'Controller does not implement get_item_schema().' ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-sidebars-controller.php b/tests/phpunit/tests/rest-api/rest-sidebars-controller.php index 91bdeeb342..66a4249f63 100644 --- a/tests/phpunit/tests/rest-api/rest-sidebars-controller.php +++ b/tests/phpunit/tests/rest-api/rest-sidebars-controller.php @@ -573,9 +573,10 @@ class WP_Test_REST_Sidebars_Controller extends WP_Test_REST_Controller_Testcase } /** - * The test_create_item() method does not exist for sidebar. + * The create_item() method does not exist for sidebar. */ public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); } /** @@ -890,15 +891,17 @@ class WP_Test_REST_Sidebars_Controller extends WP_Test_REST_Controller_Testcase } /** - * The test_delete_item() method does not exist for sidebar. + * The delete_item() method does not exist for sidebar. */ public function test_delete_item() { + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } /** - * The test_prepare_item() method does not exist for sidebar. + * The prepare_item() method does not exist for sidebar. */ public function test_prepare_item() { + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 36818f8976..e168d0da81 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -1201,12 +1201,16 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { /** * The create_item() method does not exist for themes. */ - public function test_create_item() {} + public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); + } /** * The update_item() method does not exist for themes. */ - public function test_update_item() {} + public function test_update_item() { + $this->markTestSkipped( 'Controller does not implement update_item().' ); + } /** * Test single theme. @@ -1395,10 +1399,14 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { /** * The delete_item() method does not exist for themes. */ - public function test_delete_item() {} + public function test_delete_item() { + $this->markTestSkipped( 'Controller does not implement delete_item().' ); + } /** * Context is not supported for themes. */ - public function test_context_param() {} + public function test_context_param() { + $this->markTestSkipped( 'Controller does not use get_context_param().' ); + } } diff --git a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php index a7d1d47d61..56c67ca1d5 100644 --- a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php @@ -531,17 +531,23 @@ class WP_Test_REST_Widget_Types_Controller extends WP_Test_REST_Controller_Testc } /** - * The test_create_item() method does not exist for widget types. + * The create_item() method does not exist for widget types. */ - public function test_create_item() {} + public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); + } /** - * The test_update_item() method does not exist for widget types. + * The update_item() method does not exist for widget types. */ - public function test_update_item() {} + public function test_update_item() { + $this->markTestSkipped( 'Controller does not implement update_item().' ); + } /** - * The test_delete_item() method does not exist for widget types. + * The delete_item() method does not exist for widget types. */ - public function test_delete_item() {} + public function test_delete_item() { + $this->markTestSkipped( 'Controller does not implement delete_item().' ); + } } diff --git a/tests/phpunit/tests/rest-api/rest-widgets-controller.php b/tests/phpunit/tests/rest-api/rest-widgets-controller.php index a548ab79e1..8684de31e0 100644 --- a/tests/phpunit/tests/rest-api/rest-widgets-controller.php +++ b/tests/phpunit/tests/rest-api/rest-widgets-controller.php @@ -217,6 +217,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase { * @ticket 41683 */ public function test_context_param() { + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } /** @@ -1508,9 +1509,10 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase { } /** - * The test_prepare_item() method does not exist for sidebar. + * The prepare_item() method does not exist for sidebar. */ public function test_prepare_item() { + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } /** diff --git a/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php b/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php index b69145fdcf..230c9dbc37 100644 --- a/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php +++ b/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php @@ -146,30 +146,30 @@ class Tests_REST_WpRestBlockPatternCategoriesController extends WP_Test_REST_Con } public function test_context_param() { - $this->markTestSkipped( 'Controller does not use context_param.' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } public function test_get_item() { - $this->markTestSkipped( 'Controller does not have get_item route.' ); + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_create_item() { - $this->markTestSkipped( 'Controller does not have create_item route.' ); + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { - $this->markTestSkipped( 'Controller does not have update_item route.' ); + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { - $this->markTestSkipped( 'Controller does not have delete_item route.' ); + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } public function test_prepare_item() { - $this->markTestSkipped( 'Controller does not have prepare_item route.' ); + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } public function test_get_item_schema() { - $this->markTestSkipped( 'Controller does not have get_item_schema route.' ); + $this->markTestSkipped( 'Controller does not implement get_item_schema().' ); } } diff --git a/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php b/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php index 627a9262a7..6415a06366 100644 --- a/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php +++ b/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php @@ -172,30 +172,30 @@ class Tests_REST_WpRestBlockPatternsController extends WP_Test_REST_Controller_T } public function test_context_param() { - $this->markTestSkipped( 'Controller does not use context_param.' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } public function test_get_item() { - $this->markTestSkipped( 'Controller does not have get_item route.' ); + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_create_item() { - $this->markTestSkipped( 'Controller does not have create_item route.' ); + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { - $this->markTestSkipped( 'Controller does not have update_item route.' ); + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { - $this->markTestSkipped( 'Controller does not have delete_item route.' ); + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } public function test_prepare_item() { - $this->markTestSkipped( 'Controller does not have prepare_item route.' ); + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } public function test_get_item_schema() { - $this->markTestSkipped( 'Controller does not have get_item_schema route.' ); + $this->markTestSkipped( 'Controller does not implement get_item_schema().' ); } } diff --git a/tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php b/tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php index 4683d68fed..431681926f 100644 --- a/tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php +++ b/tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php @@ -102,7 +102,7 @@ class Tests_REST_WpRestEditSiteExportController extends WP_Test_REST_Controller_ * @ticket 54448 */ public function test_context_param() { - $this->markTestSkipped( 'Controller does not implement context_param().' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } /** diff --git a/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php b/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php index 9f100719ff..425fd9223c 100644 --- a/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php +++ b/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php @@ -140,24 +140,32 @@ class Tests_REST_WpRestMenuLocationsController extends WP_Test_REST_Controller_T } /** - * The test_create_item() method does not exist for menu locations. + * The create_item() method does not exist for menu locations. */ - public function test_create_item() {} + public function test_create_item() { + $this->markTestSkipped( 'Controller does not implement create_item().' ); + } /** - * The test_update_item() method does not exist for menu locations. + * The update_item() method does not exist for menu locations. */ - public function test_update_item() {} + public function test_update_item() { + $this->markTestSkipped( 'Controller does not implement update_item().' ); + } /** - * The test_delete_item() method does not exist for menu locations. + * The delete_item() method does not exist for menu locations. */ - public function test_delete_item() {} + public function test_delete_item() { + $this->markTestSkipped( 'Controller does not implement delete_item().' ); + } /** - * The test_prepare_item() method does not exist for menu locations. + * The prepare_item() method does not exist for menu locations. */ - public function test_prepare_item() {} + public function test_prepare_item() { + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); + } /** * @ticket 40878 diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index ef4a726e30..7acb040ede 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -615,7 +615,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc } public function test_prepare_item() { - // TODO: Implement test_prepare_item() method. + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } public function test_prepare_item_limit_fields() { diff --git a/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php b/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php index 642e51235d..2bd3a17c8f 100644 --- a/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php +++ b/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php @@ -1049,27 +1049,27 @@ class Tests_REST_WpRestUrlDetailsController extends WP_Test_REST_Controller_Test } public function test_context_param() { - $this->markTestSkipped( 'Controller does not use context_param.' ); + $this->markTestSkipped( 'Controller does not use get_context_param().' ); } public function test_get_item() { - $this->markTestSkipped( 'Controller does not have get_item route.' ); + $this->markTestSkipped( 'Controller does not implement get_item().' ); } public function test_create_item() { - $this->markTestSkipped( 'Controller does not have create_item route.' ); + $this->markTestSkipped( 'Controller does not implement create_item().' ); } public function test_update_item() { - $this->markTestSkipped( 'Controller does not have update_item route.' ); + $this->markTestSkipped( 'Controller does not implement update_item().' ); } public function test_delete_item() { - $this->markTestSkipped( 'Controller does not have delete_item route.' ); + $this->markTestSkipped( 'Controller does not implement delete_item().' ); } public function test_prepare_item() { - $this->markTestSkipped( 'Controller does not have prepare_item route.' ); + $this->markTestSkipped( 'Controller does not implement prepare_item().' ); } /**