Normalize dir path in AutoLoaderStructureTest
authorLucas Werkmeister <lucas.werkmeister@wikimedia.de>
Mon, 20 May 2019 15:09:37 +0000 (17:09 +0200)
committerLucas Werkmeister <lucas.werkmeister@wikimedia.de>
Fri, 7 Jun 2019 10:53:31 +0000 (12:53 +0200)
The file paths we inspect are always normalized (File_Iterator_Facade
applies realpath()), but the directory we compare against may not be,
depending on how wfLoadExtension() was called. Normalize the directory
before we remove the directory prefix from each file, so that we don’t
end up stripping away the wrong parts of the path.

Change-Id: Ib272fb892c18d989f8d439ed50c6a5a8fd542cc9

tests/phpunit/structure/AutoLoaderStructureTest.php

index 2ae6a78..4e1b00a 100644 (file)
@@ -49,7 +49,9 @@ class AutoLoaderStructureTest extends MediaWikiTestCase {
                        // Check that the expected class name (based on the filename) is the
                        // same as the one we found.
                        // Strip directory prefix from front of filename, and .php extension
-                       $abbrFileName = substr( substr( $file, strlen( $dir ) ), 0, -4 );
+                       $dirNameLength = strlen( realpath( $dir ) ) + 1; // +1 for the trailing slash
+                       $fileBaseName = substr( $file, $dirNameLength );
+                       $abbrFileName = substr( $fileBaseName, 0, -4 );
                        $expectedClassName = $prefix . str_replace( '/', '\\', $abbrFileName );
 
                        $this->assertSame(