From 8221a7a4f28c4af2d9417f0d42cc6177d6e8529f Mon Sep 17 00:00:00 2001 From: Alangi Derick Date: Wed, 7 Nov 2018 18:15:51 +0100 Subject: [PATCH] Remove array_unique() on expected classes in checkAutoLoadConf() Sometimes classes can be loaded via autoload (PSR-4) and class_aliasing and due to this calling array_unique() on expected classes will remove one of these classes due to them sharing the same file (and array_unique() works on array values). Also allow for ::class suffixed classes to be namespaced (ie look for \ in the regexes) Cleanup some of the regexes, remove redunant code (don't need multi cased letters when we have /i), simplify them Bug: T206728 Change-Id: I235274d579b1bfd12a448448ddf020546c9aa89b --- .../structure/AutoLoaderStructureTest.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/structure/AutoLoaderStructureTest.php b/tests/phpunit/structure/AutoLoaderStructureTest.php index 8be5760176..75e21ae085 100644 --- a/tests/phpunit/structure/AutoLoaderStructureTest.php +++ b/tests/phpunit/structure/AutoLoaderStructureTest.php @@ -40,8 +40,11 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { list( $classesInFile, $aliasesInFile ) = self::parseFile( $contents ); $classes = array_keys( $classesInFile ); if ( $classes ) { - $this->assertCount( 1, $classes, - "Only one class per file in PSR-4 autoloaded classes ($file)" ); + $this->assertCount( + 1, + $classes, + "Only one class per file in PSR-4 autoloaded classes ($file)" + ); // Check that the expected class name (based on the filename) is the // same as the one we found. @@ -78,7 +81,7 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { preg_match_all( '/ ^ [\t ]* (?: (?:final\s+)? (?:abstract\s+)? (?:class|interface|trait) \s+ - (?P [a-zA-Z0-9_]+) + (?P \w+) | class_alias \s* \( \s* ([\'"]) (?P [^\'"]+) \g{-2} \s* , \s* @@ -86,7 +89,7 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { \) \s* ; | class_alias \s* \( \s* - (?P [a-zA-Z0-9_]+)::class \s* , \s* + (?P [\w\\\\]+)::class \s* , \s* ([\'"]) (?P [^\'"]+ ) \g{-2} \s* \) \s* ; ) @@ -96,7 +99,7 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { preg_match( '/ ^ [\t ]* namespace \s+ - ([a-zA-Z0-9_]+(\\\\[a-zA-Z0-9_]+)*) + (\w+(\\\\\w+)*) \s* ; /imx', $contents, $namespaceMatch ); $fileNamespace = $namespaceMatch ? $namespaceMatch[1] . '\\' : ''; @@ -135,9 +138,7 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { $psr4Namespaces[rtrim( $ns, '\\' ) . '\\'] = rtrim( $path, '/' ); } - $files = array_unique( $expected ); - - foreach ( $files as $class => $file ) { + foreach ( $expected as $class => $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 ) != ':' ) { -- 2.20.1