X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=blobdiff_plain;f=tests%2Fcommon%2FTestsAutoLoader.php;h=b626063009e53ec50b8fc17cc0b4da3aded5c0c0;hb=f1d64e2fc641673c0b3c15a591b522f4ce813be9;hp=1173e1cc0b6e63730a6705c5c0fc259334be64f6;hpb=2c46e066763dfd968e7fc7a594ca700e4a236329;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/common/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php index 1173e1cc0b..b626063009 100644 --- a/tests/common/TestsAutoLoader.php +++ b/tests/common/TestsAutoLoader.php @@ -63,6 +63,7 @@ $wgAutoloadClasses += [ 'TestUserRegistry' => "$testDir/phpunit/includes/TestUserRegistry.php", 'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php", 'MediaWikiCoversValidator' => "$testDir/phpunit/MediaWikiCoversValidator.php", + 'PHPUnit4And6Compat' => "$testDir/phpunit/PHPUnit4And6Compat.php", # tests/phpunit/includes 'RevisionDbTestBase' => "$testDir/phpunit/includes/RevisionDbTestBase.php", @@ -184,3 +185,35 @@ $wgAutoloadClasses += [ 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php", ]; // phpcs:enable + +/** + * Alias any PHPUnit 4 era PHPUnit_... class + * to it's 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( function ( $class ) { + if ( strpos( $class, 'PHPUnit_' ) !== 0 ) { + // Skip if it doesn't start with the old prefix + return; + } + + // Classes that don't map 100% + $map = [ + 'PHPUnit_Framework_TestSuite_DataProvider' => 'PHPUnit\Framework\DataProviderTestSuite' + ]; + + if ( isset( $map[$class] ) ) { + $newForm = $map[$class]; + } else { + $newForm = str_replace( '_', '\\', $class ); + } + + if ( class_exists( $newForm ) ) { + // If the new class name exists, alias + // the old name to it. + class_alias( $newForm, $class ); + } +} );