mirror of
git://develop.git.wordpress.org/
synced 2025-04-21 20:51:55 +02:00
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
This commit is contained in:
parent
47303b1f95
commit
31a6cd2f78
@ -12,7 +12,7 @@ require_once __DIR__ . '/trac.php';
|
||||
*
|
||||
* All WordPress unit tests should inherit from this class.
|
||||
*/
|
||||
abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
|
||||
abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
|
||||
|
||||
protected static $forced_tickets = array();
|
||||
protected $expected_deprecated = array();
|
||||
|
@ -207,6 +207,7 @@ if ( version_compare( tests_get_phpunit_version(), '6.0', '>=' ) ) {
|
||||
require_once $phpunit_polyfills_autoloader;
|
||||
unset( $phpunit_polyfills_autoloader );
|
||||
|
||||
require __DIR__ . '/phpunit-adapter-testcase.php';
|
||||
require __DIR__ . '/abstract-testcase.php';
|
||||
require __DIR__ . '/testcase.php';
|
||||
require __DIR__ . '/testcase-rest-api.php';
|
||||
|
45
tests/phpunit/includes/phpunit-adapter-testcase.php
Normal file
45
tests/phpunit/includes/phpunit-adapter-testcase.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
|
||||
|
||||
/**
|
||||
* PHPUnit adapter layer.
|
||||
*
|
||||
* This class enhances the PHPUnit native `TestCase` with polyfills
|
||||
* for assertions and expectation methods added between PHPUnit 4.8 - 9.5.
|
||||
*
|
||||
* See {@link https://github.com/Yoast/PHPUnit-Polyfills} for full
|
||||
* documentation on the available polyfills.
|
||||
*/
|
||||
abstract class PHPUnit_Adapter_TestCase extends PHPUnit\Framework\TestCase {
|
||||
|
||||
use AssertAttributeHelper;
|
||||
use AssertClosedResource;
|
||||
use AssertEqualsSpecializations;
|
||||
use AssertFileDirectory;
|
||||
use AssertFileEqualsSpecializations;
|
||||
use AssertionRenames;
|
||||
use AssertIsType;
|
||||
use AssertNumericType;
|
||||
use AssertObjectEquals;
|
||||
use AssertStringContains;
|
||||
use EqualToSpecializations;
|
||||
use ExpectException;
|
||||
use ExpectExceptionMessageMatches;
|
||||
use ExpectExceptionObject;
|
||||
use ExpectPHPException;
|
||||
}
|
@ -1,48 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
|
||||
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
|
||||
|
||||
/**
|
||||
* Basic abstract test class with PHPUnit cross-version adapter layer.
|
||||
*
|
||||
* This adapter layer polyfills all PHPUnit assertion and expectation
|
||||
* methods which were added between PHPUnit 4.8 - 9.5 to allow tests
|
||||
* to benefit from the full range of available PHPUnit methods.
|
||||
*
|
||||
* See {@link https://github.com/Yoast/PHPUnit-Polyfills} for full
|
||||
* documentation on the available polyfills.
|
||||
* Basic abstract test class.
|
||||
*
|
||||
* All WordPress unit tests should inherit from this class.
|
||||
*/
|
||||
class WP_UnitTestCase extends WP_UnitTestCase_Base {
|
||||
|
||||
use AssertAttributeHelper;
|
||||
use AssertClosedResource;
|
||||
use AssertEqualsSpecializations;
|
||||
use AssertFileDirectory;
|
||||
use AssertFileEqualsSpecializations;
|
||||
use AssertionRenames;
|
||||
use AssertIsType;
|
||||
use AssertNumericType;
|
||||
use AssertObjectEquals;
|
||||
use AssertStringContains;
|
||||
use EqualToSpecializations;
|
||||
use ExpectException;
|
||||
use ExpectExceptionMessageMatches;
|
||||
use ExpectExceptionObject;
|
||||
use ExpectPHPException;
|
||||
}
|
||||
abstract class WP_UnitTestCase extends WP_UnitTestCase_Base {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user