Skip to content

Commit da59c19

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60693 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4d170e3 commit da59c19

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

tests/phpunit/includes/phpunit6/compat.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
if ( 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

2127
class PHPUnit_Util_Test {

0 commit comments

Comments
 (0)