Build/Test Tools: Unify the PHPUnit adapter TestCases.

This commit:
* Removes the PHPUnit 7 specific `TestCase`.
* Removes all existing polyfills from the PHPUnit 5.x `TestCase`.
* Imports all polyfill traits from the PHPUnit Polyfills package into the `WP_UnitTestCase` class and updates the DocBlock to reflect the actual function of the class.
 * Note: The list of polyfills needs to be verified and updated after each new release of the PHPUnit Polyfills package. Alternatively (recommended), one of the built-in `TestCase` classes from the PHPUnit Polyfills package can be used instead.

* Moves the `require` for the WP `abstract-testcase.php` to the `bootstrap.php` file.
* Adds a `require_once` for the PHPUnit Polyfills autoloader to the `bootstrap.php` file.
 * Note: while this isn't _strictly_ necessary when the tests are run via Composer, having the include in the bootstrap allows for the tests to also be run via a PHPUnit Phar, providing contributors with more flexibility.

Follow-up to [51559].

Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51560 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-08-06 00:35:01 +00:00
parent 8ebd8ec0e4
commit 47303b1f95
3 changed files with 49 additions and 447 deletions
+13 -6
View File
@@ -50,6 +50,14 @@ if ( version_compare( $phpunit_version, '5.7', '<' ) || version_compare( $phpuni
require_once __DIR__ . '/class-mockobject-autoload.php';
spl_autoload_register( 'MockObject_Autoload::load', true, true );
// Check that the PHPUnit Polyfills autoloader exists.
$phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
if ( ! file_exists( $phpunit_polyfills_autoloader ) ) {
echo "Error: You need to run `composer update` before running the tests.\n";
echo "You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.\n";
exit( 1 );
}
// If running core tests, check if all the required PHP extensions are loaded before running the test suite.
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
$required_extensions = array(
@@ -195,13 +203,12 @@ if ( version_compare( tests_get_phpunit_version(), '6.0', '>=' ) ) {
require __DIR__ . '/phpunit6/compat.php';
}
// Load separate WP_UnitTestCase classes for PHPUnit 7.5+ and older versions.
if ( version_compare( tests_get_phpunit_version(), '7.5', '>=' ) ) {
require __DIR__ . '/phpunit7/testcase.php';
} else {
require __DIR__ . '/testcase.php';
}
// Load the PHPUnit Polyfills autoloader (check for existence of the file is done earlier in the script).
require_once $phpunit_polyfills_autoloader;
unset( $phpunit_polyfills_autoloader );
require __DIR__ . '/abstract-testcase.php';
require __DIR__ . '/testcase.php';
require __DIR__ . '/testcase-rest-api.php';
require __DIR__ . '/testcase-rest-controller.php';
require __DIR__ . '/testcase-rest-post-type-controller.php';