Make WordPress Core

08/06/2021 12:35:01 AM (2 years ago)

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.

1 edited


  • trunk/tests/phpunit/includes/bootstrap.php

    r51544 r51560  
    5050require_once __DIR__ . '/class-mockobject-autoload.php';
    5151spl_autoload_register( 'MockObject_Autoload::load', true, true );
     53// Check that the PHPUnit Polyfills autoloader exists.
     54$phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
     55if ( ! file_exists( $phpunit_polyfills_autoloader ) ) {
     56    echo "Error: You need to run `composer update` before running the tests.\n";
     57    echo "You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.\n";
     58    exit( 1 );
    5361// If running core tests, check if all the required PHP extensions are loaded before running the test suite.
    198 // Load separate WP_UnitTestCase classes for PHPUnit 7.5+ and older versions.
    199 if ( version_compare( tests_get_phpunit_version(), '7.5', '>=' ) ) {
    200     require __DIR__ . '/phpunit7/testcase.php';
    201 } else {
    202     require __DIR__ . '/testcase.php';
    203 }
     206// Load the PHPUnit Polyfills autoloader (check for existence of the file is done earlier in the script).
     207require_once $phpunit_polyfills_autoloader;
     208unset( $phpunit_polyfills_autoloader );
     210require __DIR__ . '/abstract-testcase.php';
     211require __DIR__ . '/testcase.php';
    205212require __DIR__ . '/testcase-rest-api.php';
    206213require __DIR__ . '/testcase-rest-controller.php';
Note: See TracChangeset for help on using the changeset viewer.