2 class AutoLoaderTest
extends MediaWikiTestCase
{
5 * Assert that there were no classes loaded that are not registered with the AutoLoader.
7 * For example foo.php having class Foo and class Bar but only registering Foo.
8 * This is important because we should not be relying on Foo being used before Bar.
10 public function testAutoLoadConfig() {
11 $results = self
::checkAutoLoadConf();
19 protected static function checkAutoLoadConf() {
20 global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP;
21 $supportsParsekit = function_exists( 'parsekit_compile_file' );
23 // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
24 $expected = $wgAutoloadLocalClasses +
$wgAutoloadClasses;
27 $files = array_unique( $expected );
29 foreach ( $files as $file ) {
30 // Only prefix $IP if it doesn't have it already.
31 // Generally local classes don't have it, and those from extensions and test suites do.
32 if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) {
33 $filePath = "$IP/$file";
37 if ( $supportsParsekit ) {
38 $parseInfo = parsekit_compile_file( "$filePath" );
39 $classes = array_keys( $parseInfo['class_table'] );
41 $contents = file_get_contents( "$filePath" );
43 preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER
);
46 foreach ( $classes as $class ) {
47 $actual[$class] = $file;
52 'expected' => $expected,