mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
Build/Test Tools: Fix test forward-compatibility layer.
In [51840], the test wrapper methods were not being called due to the names not being recognized as supported PHPUnit "hook" names for fixtures. This commit: - Fixes the problem by adding extra camelCase wrappers to the `WP_UnitTestCase` to call the methods in the right order. - Adds wrappers for the `assertPreConditions()` and `assertPostConditions()` fixture methods to make the backport feature complete for the fixture wrappers. Test wrapper methods call fix: By adding method overloads for the PHPUnit native camelCase fixture methods and letting those call the (camelCase) parent method first and only calling the snake_case fixture methods after, the snake_case methods can be supported and the typical run order safeguarded. As not all test classes will have declared snake_case fixture methods, the snake_case fixture methods are also declared in the `WP_UnitTestCase`. Why? This prevents having to wrap these method calls in `method_exists()` conditions checking for the existence of the snake_case methods in an unknown Test child class. And with the normal inheritance rules in combination with calling the method using `static`, the right method will be called anyway without fatal "calling undeclared method" errors. Note: While it will be rare, there ''may'' be cases where a test class does not adhere to the normal execution order for fixtures, i.e. for the setup methods, parent first, own code second; and for the teardown methods, own code first, parent second. For example a test class which has "some code - `parent::setUp()` call - some more code" in their `setUp()` method. In those (rare) cases, the execution order of the code will now be changed, which may have side-effects. This rare case will be identified in the dev note. Follow-up to [51840]. Props bjorsch, swissspidy, jrf, hellofromTonya. See #53911. git-svn-id: https://develop.svn.wordpress.org/branches/5.6@51863 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
279d36ebf3
commit
2283fe0cbf
@ -46,30 +46,80 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
|
||||
use ExpectPHPException;
|
||||
|
||||
/**
|
||||
* Wrapper method for the `setUpBeforeClass()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `set_up_before_class()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function set_up_before_class() {
|
||||
static::setUpBeforeClass();
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
static::set_up_before_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `tearDownAfterClass()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `tear_down_after_class()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function tear_down_after_class() {
|
||||
static::tearDownAfterClass();
|
||||
public static function tearDownAfterClass() {
|
||||
static::tear_down_after_class();
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `setUp()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `set_up()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public function set_up() {
|
||||
static::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->set_up();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `tearDown()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `tear_down()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public function tear_down() {
|
||||
static::tearDown();
|
||||
public function tearDown() {
|
||||
$this->tear_down();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `assert_pre_conditions()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assertPreConditions() {
|
||||
parent::assertPreConditions();
|
||||
$this->assert_pre_conditions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `assert_post_conditions()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assertPostConditions() {
|
||||
parent::assertPostConditions();
|
||||
$this->assert_post_conditions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function set_up_before_class() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function tear_down_after_class() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function set_up() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function tear_down() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assert_pre_conditions() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assert_post_conditions() {}
|
||||
}
|
||||
|
@ -46,30 +46,80 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
|
||||
use ExpectPHPException;
|
||||
|
||||
/**
|
||||
* Wrapper method for the `setUpBeforeClass()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `set_up_before_class()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function set_up_before_class() {
|
||||
static::setUpBeforeClass();
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
static::set_up_before_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `tearDownAfterClass()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `tear_down_after_class()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function tear_down_after_class() {
|
||||
static::tearDownAfterClass();
|
||||
public static function tearDownAfterClass() {
|
||||
static::tear_down_after_class();
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `setUp()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `set_up()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public function set_up() {
|
||||
static::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->set_up();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `tearDown()` method for forward-compatibility with WP 5.9.
|
||||
* Wrapper method for the `tear_down()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public function tear_down() {
|
||||
static::tearDown();
|
||||
public function tearDown() {
|
||||
$this->tear_down();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `assert_pre_conditions()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assertPreConditions() {
|
||||
parent::assertPreConditions();
|
||||
$this->assert_pre_conditions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for the `assert_post_conditions()` method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assertPostConditions() {
|
||||
parent::assertPostConditions();
|
||||
$this->assert_post_conditions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function set_up_before_class() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
public static function tear_down_after_class() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function set_up() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function tear_down() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assert_pre_conditions() {}
|
||||
|
||||
/**
|
||||
* Placeholder method for forward-compatibility with WP 5.9.
|
||||
*/
|
||||
protected function assert_post_conditions() {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user