Make WordPress Core

Changeset 51544


Ignore:
Timestamp:
08/04/2021 07:24:14 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Use a custom autoloader for the PHPUnit 9.x mock object classes.

This prevents the classes from being loaded automatically via the autoload-dev directives when a Composer-installed PHPUnit 5.x or 6.x version is used, as that would break the test run.

It is expected that this autoloader will be removed soon, as it should no longer be needed when the PHPUnit version constraints are widened.

Notes:

  • The autoloader file will be loaded from the Test bootstrap.
  • The autoloader will always be registered and directed to queue itself _before_ the Composer autoload file (which will already have been registered).
  • The autoloader will only actually load the WP copies of the files/classes when PHP 8.0 in combination with PHPUnit 7.x is detected. In all other cases, the autoloader will bow out, which effectively then defers to the Composer autoload file to load the files as shipped with the installed PHPUnit version.

Follow-up to [48957], [49037], [51543].

Props jrf.
See #47381.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/composer.json

    r51543 r51544  
    2020        "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5"
    2121    },
    22     "autoload-dev": {
    23         "files": [
    24             "tests/phpunit/includes/phpunit7/MockObject/Builder/NamespaceMatch.php",
    25             "tests/phpunit/includes/phpunit7/MockObject/Builder/ParametersMatch.php",
    26             "tests/phpunit/includes/phpunit7/MockObject/InvocationMocker.php",
    27             "tests/phpunit/includes/phpunit7/MockObject/MockMethod.php"
    28         ],
    29         "exclude-from-classmap": [
    30             "vendor/phpunit/phpunit/src/Framework/MockObject/Builder/NamespaceMatch.php",
    31             "vendor/phpunit/phpunit/src/Framework/MockObject/Builder/ParametersMatch.php",
    32             "vendor/phpunit/phpunit/src/Framework/MockObject/InvocationMocker.php",
    33             "vendor/phpunit/phpunit/src/Framework/MockObject/MockMethod.php"
    34         ]
    35     },
    3622    "scripts": {
    3723        "compat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist --report=summary,source",
  • trunk/tests/phpunit/includes/bootstrap.php

    r51543 r51544  
    4646    exit( 1 );
    4747}
     48
     49// Register a custom autoloader for the PHPUnit 9.x Mockobject classes for compatibility with PHP 8.0.
     50require_once __DIR__ . '/class-mockobject-autoload.php';
     51spl_autoload_register( 'MockObject_Autoload::load', true, true );
    4852
    4953// If running core tests, check if all the required PHP extensions are loaded before running the test suite.
Note: See TracChangeset for help on using the changeset viewer.