Merge "TestsAutoLoader: Remove old PHPUnit class aliasing"

This commit is contained in:
jenkins-bot 2024-04-28 15:38:47 +00:00 committed by Gerrit Code Review
commit 8c5c0edbfa
2 changed files with 2 additions and 32 deletions

View file

@ -140,6 +140,8 @@ because of Phabricator reports.
=== Other changes in 1.43 ===
* Class aliases to support the old PHPUnit 4 style un-namespaced `PHPUnit_`
classes (such as PHPUnit_Framework_Error) have been removed.
* …
== Compatibility ==

View file

@ -1,8 +1,5 @@
<?php
use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\Error\Error;
/**
* AutoLoader for the testing suite.
*
@ -349,32 +346,3 @@ $wgAutoloadClasses += [
'SuiteEventsTrait' => "$testDir/phpunit/suites/SuiteEventsTrait.php",
];
// phpcs:enable
/**
* Alias any PHPUnit 4 era PHPUnit_... class
* to its PHPUnit 6 replacement. For most classes
* this is a direct _ -> \ replacement, but for
* some others we might need to maintain a manual
* mapping. Once we drop support for PHPUnit 4 this
* should be considered deprecated and eventually removed.
*/
spl_autoload_register( static function ( $class ) {
if ( !str_starts_with( $class, 'PHPUnit_' ) ) {
// Skip if it doesn't start with the old prefix
return;
}
// Classes that don't map 100%
$map = [
'PHPUnit_Framework_TestSuite_DataProvider' => DataProviderTestSuite::class,
'PHPUnit_Framework_Error' => Error::class,
];
$newForm = $map[$class] ?? str_replace( '_', '\\', $class );
if ( class_exists( $newForm ) || interface_exists( $newForm ) ) {
// If the new class name exists, alias
// the old name to it.
class_alias( $newForm, $class );
}
} );