* Move scattered pieces from tests/* in main AutoLoader.php into tests/TestsAutoLoader.php. Verified with: 'ack -Q i --ignore-dir tests/phpunit/ <classname>' on mediawiki/core that these classes are not used outside tests/phpunit/. * Moved entry for maintenance/backup.inc to the main AutoLoader. * Refactored assertion logic in maintenance/checkAutoLoader.php into a public static method used in it's execute method and in the (new) AutoLoaderTest suite. * The new test was immediately failing, added missing classes and removed old ones that don't exist. And CheckAutoLoader itself, so that it can actually be used in AutoLoaderTest.php * Per discussion on Gerrit, moved the logic into the unit test instead of refactoring the maintenance script, we no longer need the maintenance script. * Fixed the regex to also detect abstract, final and interface. The test was failing badly, claiming many classes did not exist. * Improved the logic to also catch entries in the AutoLoader configuration for inexisting classes in existing files. So far it only catched entries with wrong files and missing entries for classes in known files. An entry like "BlablaSomethingHere => includes/Action.php" did not emit any kind of warning. The refactored logic builds a reverse index and uses a simple assertEquals to find any inconsistencies (whatever the cause). Change-Id: I0a307f23175d52345180cdfc7c2d5e172536be1b
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
class AutoLoaderTest extends MediaWikiTestCase {
|
|
|
|
public function testAutoLoadConfig() {
|
|
$results = self::checkAutoLoadConf();
|
|
|
|
$this->assertEquals(
|
|
$results['expected'],
|
|
$results['actual']
|
|
);
|
|
}
|
|
|
|
protected static function checkAutoLoadConf() {
|
|
global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP;
|
|
static $supportsParsekit;
|
|
$supportsParsekit = function_exists( 'parsekit_compile_file' );
|
|
|
|
// wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
|
|
$expected = $wgAutoloadLocalClasses + $wgAutoloadClasses;
|
|
$actual = array();
|
|
|
|
$files = array_unique( $expected );
|
|
|
|
foreach ( $files as $file ) {
|
|
// Only prefix $IP if it doesn't have it already.
|
|
// Generally local classes don't have it, and those from extensions and test suites do.
|
|
if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) {
|
|
$filePath = "$IP/$file";
|
|
} else {
|
|
$filePath = $file;
|
|
}
|
|
if ( $supportsParsekit ) {
|
|
$parseInfo = parsekit_compile_file( "$filePath" );
|
|
$classes = array_keys( $parseInfo['class_table'] );
|
|
} else {
|
|
$contents = file_get_contents( "$filePath" );
|
|
$m = array();
|
|
preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER );
|
|
$classes = $m[1];
|
|
}
|
|
foreach ( $classes as $class ) {
|
|
$actual[$class] = $file;
|
|
}
|
|
}
|
|
|
|
return array(
|
|
'expected' => $expected,
|
|
'actual' => $actual,
|
|
);
|
|
}
|
|
}
|