Make WordPress Core

Changeset 60693


Ignore:
Timestamp:
08/30/2025 01:59:02 PM (14 months ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Check if PHPUnit classes exist before calling class_alias().

This resolves Class not found warnings when running the tests in PHPUnit 10 or later.

Follow-up to [40536], [51570].

Props danielmorell, devasheeshkaul, SergeyBiryukov.
Fixes #63833.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/phpunit6/compat.php

    r56547 r60693  
    33if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
    44
    5         class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
    6         class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' );
    7         class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' );
    8         class_alias( 'PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated' );
    9         class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
    10         class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
    11         class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' );
    12         class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' );
    13         class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' );
    14         class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' );
    15         class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' );
    16         class_alias( 'PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState' );
    17         if ( class_exists( 'PHPUnit\Util\Getopt' ) ) {
    18                 class_alias( 'PHPUnit\Util\Getopt', 'PHPUnit_Util_Getopt' );
     5        $aliases = array(
     6                'PHPUnit\Framework\TestCase'                   => 'PHPUnit_Framework_TestCase',
     7                'PHPUnit\Framework\Exception'                  => 'PHPUnit_Framework_Exception',
     8                'PHPUnit\Framework\ExpectationFailedException' => 'PHPUnit_Framework_ExpectationFailedException',
     9                'PHPUnit\Framework\Error\Deprecated'           => 'PHPUnit_Framework_Error_Deprecated',
     10                'PHPUnit\Framework\Error\Notice'               => 'PHPUnit_Framework_Error_Notice',
     11                'PHPUnit\Framework\Error\Warning'              => 'PHPUnit_Framework_Error_Warning',
     12                'PHPUnit\Framework\Test'                       => 'PHPUnit_Framework_Test',
     13                'PHPUnit\Framework\Warning'                    => 'PHPUnit_Framework_Warning',
     14                'PHPUnit\Framework\AssertionFailedError'       => 'PHPUnit_Framework_AssertionFailedError',
     15                'PHPUnit\Framework\TestSuite'                  => 'PHPUnit_Framework_TestSuite',
     16                'PHPUnit\Framework\TestListener'               => 'PHPUnit_Framework_TestListener',
     17                'PHPUnit\Util\GlobalState'                     => 'PHPUnit_Util_GlobalState',
     18                'PHPUnit\Util\Getopt'                          => 'PHPUnit_Util_Getopt',
     19        );
     20
     21        foreach ( $aliases as $original => $alias ) {
     22                if ( class_exists( $original ) ) {
     23                        class_alias( $original, $alias );
     24                }
    1925        }
    2026
Note: See TracChangeset for help on using the changeset viewer.