WordPress.org

Make WordPress Core

Changeset 51561


Ignore:
Timestamp:
08/06/2021 12:44:00 AM (3 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/tests/phpunit/includes
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r51481 r51561  
    1313 * All WordPress unit tests should inherit from this class.
    1414 */
    15 abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
     15abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
    1616
    1717    protected static $forced_tickets   = array();
  • trunk/tests/phpunit/includes/bootstrap.php

    r51560 r51561  
    208208unset( $phpunit_polyfills_autoloader );
    209209
     210require __DIR__ . '/phpunit-adapter-testcase.php';
    210211require __DIR__ . '/abstract-testcase.php';
    211212require __DIR__ . '/testcase.php';
  • trunk/tests/phpunit/includes/testcase.php

    r51560 r51561  
    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 }
     7abstract class WP_UnitTestCase extends WP_UnitTestCase_Base {}
Note: See TracChangeset for help on using the changeset viewer.