4 protected function setUp() {
9 'TestAutoloadedLocalClass' =>
10 __DIR__ .
'/../data/autoloader/TestAutoloadedLocalClass.php',
11 'TestAutoloadedCamlClass' =>
12 __DIR__ .
'/../data/autoloader/TestAutoloadedCamlClass.php',
13 'TestAutoloadedSerializedClass' =>
14 __DIR__ .
'/../data/autoloader/TestAutoloadedSerializedClass.php',
19 'TestAutoloadedClass' => __DIR__ .
'/../data/autoloader/TestAutoloadedClass.php',
45 $files = array_unique( $expected );
47 foreach ( $files
as $class => $file ) {
50 if ( substr( $file, 0, 1 ) !=
'/' && substr( $file, 1, 1 ) !=
':' ) {
51 $filePath =
"$IP/$file";
56 if ( !file_exists( $filePath ) ) {
57 $actual[$class] =
"[file '$filePath' does not exist]";
61 MediaWiki\suppressWarnings();
62 $contents = file_get_contents( $filePath );
63 MediaWiki\restoreWarnings();
65 if ( $contents ===
false ) {
66 $actual[$class] =
"[couldn't read file '$filePath']";
75 (?:final\s+)? (?:abstract\s+)? (?:class|interface|trait) \s+
76 (?P<class> [a-zA-Z0-9_]+)
78 class_alias \s* \( \s*
79 ([\'"]) (?P<original> [^\'"]+) \g{-2} \s* , \s*
80 ([\'"]) (?P<alias> [^\'"]+ ) \g{-2} \s*
83 class_alias \s* \( \s*
84 (?P<originalStatic> [a-zA-Z0-9_]+)::class \s* , \s*
85 ([\'"]) (?P<aliasString> [^\'"]+ ) \g{-2} \s*
88 /imx', $contents,
$matches, PREG_SET_ORDER );
94 ([a-zA-Z0-9_]+(\\\\[a-zA-Z0-9_]+)*)
96 /imx', $contents, $namespaceMatch );
97 $fileNamespace = $namespaceMatch ? $namespaceMatch[1] .
'\\' :
'';
103 if ( !empty( $match[
'class'] ) ) {
105 $class = $fileNamespace . $match[
'class'];
106 $actual[$class] = $file;
107 $classesInFile[$class] =
true;
109 if ( !empty( $match[
'original'] ) ) {
111 $aliasesInFile[$match[
'alias']] = $match[
'original'];
114 $aliasesInFile[$match[
'aliasString']] = $fileNamespace . $match[
'originalStatic'];
122 foreach ( $aliasesInFile
as $alias => $class ) {
123 if ( isset( $classesInFile[$class] ) ) {
124 $actual[$alias] = $file;
126 $actual[$alias] =
"[original class not in $file]";
132 'expected' => $expected,
138 $this->assertTrue( class_exists(
'TestAutoloadedLocalClass' ) );
142 $this->assertTrue( class_exists(
'TestAutoloadedClass' ) );
146 $this->
setMwGlobals(
'wgAutoloadAttemptLowercase',
true );
148 $this->assertTrue( class_exists(
'testautoLoadedcamlCLASS' ) );
152 $this->
setMwGlobals(
'wgAutoloadAttemptLowercase',
true );
154 $dummyCereal =
'O:29:"testautoloadedserializedclass":0:{}';
156 $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
157 "unserialize() can load classes case-insensitively." );
161 $path = realpath( __DIR__ .
'/../../..' );
162 $oldAutoload = file_get_contents(
$path .
'/autoload.php' );
165 $newAutoload =
$generator->getAutoload(
'maintenance/generateLocalAutoload.php' );
167 $this->assertEquals( $oldAutoload, $newAutoload,
'autoload.php does not match' .
168 ' output of generateLocalAutoload.php script.' );