Skip to content

Commit 31a6cd2

Browse files
Build/Test Tools: Change the inheritance order of the abstract test classes.
As things were, the inheritance order of the abstract test classes was as follows: {{{ WP_UnitTestCase (PHPUnit adapter layer) extends WP_UnitTestCase_Base (base test class) extends PHPUnit\Framework\TestCase (PHPUnit native class) }}} Concrete (child) test classes, as well as more specific abstract TestCases, are/were expected to extend the `WP_UnitTestCase`. This order is not optimal as it means that the `WP_UnitTestCase_Base` class would not be able to benefit from any polyfills and/or shims in the PHPUnit adapter layer. With that in mind, this commit changes the inheritance to: {{{ WP_UnitTestCase (empty class, left in place to not break BC for plugin/theme integration tests) extends WP_UnitTestCase_Base (base test class) extends PHPUnit_Adapter_TestCase (PHPUnit adapter layer) extends PHPUnit\Framework\TestCase (PHPUnit native class) }}} The new order allows for the `WP_UnitTestCase_Base` to also benefit from the PHPUnit adapter layer. For backward compatibility reasons the `WP_UnitTestCase`, which all test classes are (were) expected to extend, is left in place, though it is now an empty class and explicitly `abstract`. Follow-up to [51559], [51560]. Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51561 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 47303b1 commit 31a6cd2

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* All WordPress unit tests should inherit from this class.
1414
*/
15-
abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
15+
abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
1616

1717
protected static $forced_tickets = array();
1818
protected $expected_deprecated = array();

tests/phpunit/includes/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ function wp_tests_options( $value ) {
207207
require_once $phpunit_polyfills_autoloader;
208208
unset( $phpunit_polyfills_autoloader );
209209

210+
require __DIR__ . '/phpunit-adapter-testcase.php';
210211
require __DIR__ . '/abstract-testcase.php';
211212
require __DIR__ . '/testcase.php';
212213
require __DIR__ . '/testcase-rest-api.php';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
4+
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
5+
use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations;
6+
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory;
7+
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
8+
use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
9+
use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
10+
use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType;
11+
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
12+
use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;
13+
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
14+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
15+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
16+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
17+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
18+
19+
/**
20+
* PHPUnit adapter layer.
21+
*
22+
* This class enhances the PHPUnit native `TestCase` with polyfills
23+
* for assertions and expectation methods added between PHPUnit 4.8 - 9.5.
24+
*
25+
* See {@link https://github.com/Yoast/PHPUnit-Polyfills} for full
26+
* documentation on the available polyfills.
27+
*/
28+
abstract class PHPUnit_Adapter_TestCase extends PHPUnit\Framework\TestCase {
29+
30+
use AssertAttributeHelper;
31+
use AssertClosedResource;
32+
use AssertEqualsSpecializations;
33+
use AssertFileDirectory;
34+
use AssertFileEqualsSpecializations;
35+
use AssertionRenames;
36+
use AssertIsType;
37+
use AssertNumericType;
38+
use AssertObjectEquals;
39+
use AssertStringContains;
40+
use EqualToSpecializations;
41+
use ExpectException;
42+
use ExpectExceptionMessageMatches;
43+
use ExpectExceptionObject;
44+
use ExpectPHPException;
45+
}

tests/phpunit/includes/testcase.php

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,7 @@
11
<?php
2-
3-
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
4-
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
5-
use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations;
6-
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory;
7-
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
8-
use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
9-
use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
10-
use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType;
11-
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
12-
use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;
13-
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
14-
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
15-
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
16-
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
17-
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
18-
192
/**
20-
* Basic abstract test class with PHPUnit cross-version adapter layer.
21-
*
22-
* This adapter layer polyfills all PHPUnit assertion and expectation
23-
* methods which were added between PHPUnit 4.8 - 9.5 to allow tests
24-
* to benefit from the full range of available PHPUnit methods.
25-
*
26-
* See {@link https://github.com/Yoast/PHPUnit-Polyfills} for full
27-
* documentation on the available polyfills.
3+
* Basic abstract test class.
284
*
295
* All WordPress unit tests should inherit from this class.
306
*/
31-
class WP_UnitTestCase extends WP_UnitTestCase_Base {
32-
33-
use AssertAttributeHelper;
34-
use AssertClosedResource;
35-
use AssertEqualsSpecializations;
36-
use AssertFileDirectory;
37-
use AssertFileEqualsSpecializations;
38-
use AssertionRenames;
39-
use AssertIsType;
40-
use AssertNumericType;
41-
use AssertObjectEquals;
42-
use AssertStringContains;
43-
use EqualToSpecializations;
44-
use ExpectException;
45-
use ExpectExceptionMessageMatches;
46-
use ExpectExceptionObject;
47-
use ExpectPHPException;
48-
}
7+
abstract class WP_UnitTestCase extends WP_UnitTestCase_Base {}

0 commit comments

Comments
 (0)