summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/includes/testcase-rest-controller.php
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2021-08-07 10:29:41 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2021-08-07 10:29:41 +0000
commitddb409edca5132d7aa73c2e45f166a5a915e2dbe (patch)
tree4b170a5bb4543b513fed90148d751e66c5acd408 /tests/phpunit/includes/testcase-rest-controller.php
parentcb6bf0263825f5f53b999a8a47786bbd79df29b2 (diff)
downloadwordpress-ddb409edca5132d7aa73c2e45f166a5a915e2dbe.tar.gz
wordpress-ddb409edca5132d7aa73c2e45f166a5a915e2dbe.zip
Build/Test Tools: Implement use of the `void` solution.
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches. > > The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used. > > When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`. > > The snake_case methods will automatically be called by PHPUnit. > > > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`. Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases This commit renames all declared fixture methods, and calls to parent versions of those fixture methods, from camelCase to snake_case. Follow-up to [51559-51567]. Props jrf, hellofromTonya, johnbillion, netweb, dd32, pputzer, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51568 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/testcase-rest-controller.php')
-rw-r--r--tests/phpunit/includes/testcase-rest-controller.php8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/phpunit/includes/testcase-rest-controller.php b/tests/phpunit/includes/testcase-rest-controller.php
index 2c79df11be..a0b96545bf 100644
--- a/tests/phpunit/includes/testcase-rest-controller.php
+++ b/tests/phpunit/includes/testcase-rest-controller.php
@@ -4,8 +4,8 @@ abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
protected $server;
- public function setUp() {
- parent::setUp();
+ public function set_up() {
+ parent::set_up();
add_filter( 'rest_url', array( $this, 'filter_rest_url_for_leading_slash' ), 10, 2 );
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
@@ -13,12 +13,12 @@ abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
do_action( 'rest_api_init', $wp_rest_server );
}
- public function tearDown() {
+ public function tear_down() {
remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 );
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
- parent::tearDown();
+ parent::tear_down();
}
abstract public function test_register_routes();