From e7ae019fc0a5ff9784f7369c07defc598afda0d4 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 26 May 2018 16:51:56 -0700 Subject: [PATCH] AutoLoaderStructureTest: Allow PSR-4 directories to have files with 0 classes Files like ServiceWiring.php can be safely located in a PSR-4 autoloaded directory, because they have no classes. Change-Id: I359b305df9071d6bc5afe4b5f29e762041f4aaef --- .../structure/AutoLoaderStructureTest.php | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/structure/AutoLoaderStructureTest.php b/tests/phpunit/structure/AutoLoaderStructureTest.php index 4d6867f8e2..50ec5fa670 100644 --- a/tests/phpunit/structure/AutoLoaderStructureTest.php +++ b/tests/phpunit/structure/AutoLoaderStructureTest.php @@ -39,20 +39,28 @@ class AutoLoaderStructureTest extends MediaWikiTestCase { $contents = file_get_contents( $file ); list( $classesInFile, $aliasesInFile ) = self::parseFile( $contents ); $classes = array_keys( $classesInFile ); - $this->assertCount( 1, $classes, - "Only one class per file in PSR-4 autoloaded classes ($file)" ); - - $this->assertStringStartsWith( $prefix, $classes[0] ); - $this->assertTrue( - class_exists( $classes[0] ) || interface_exists( $classes[0] ) || trait_exists( $classes[0] ), - "Class {$classes[0]} not autoloaded properly" - ); - - $otherClasses = $wgAutoloadLocalClasses + $wgAutoloadClasses; - foreach ( $aliasesInFile as $alias => $class ) { - $this->assertArrayHasKey( $alias, $otherClasses, - 'Alias must be in the classmap autoloader' + if ( $classes ) { + $this->assertCount( 1, $classes, + "Only one class per file in PSR-4 autoloaded classes ($file)" ); + + $this->assertStringStartsWith( $prefix, $classes[0] ); + $this->assertTrue( + class_exists( $classes[0] ) || interface_exists( $classes[0] ) || trait_exists( $classes[0] ), + "Class {$classes[0]} not autoloaded properly" ); + } else { + // Dummy assertion so this test isn't marked in risky + // if the file has no classes nor aliases in it + $this->assertCount( 0, $classes ); + } + + if ( $aliasesInFile ) { + $otherClasses = $wgAutoloadLocalClasses + $wgAutoloadClasses; + foreach ( $aliasesInFile as $alias => $class ) { + $this->assertArrayHasKey( $alias, $otherClasses, + 'Alias must be in the classmap autoloader' + ); + } } } -- 2.20.1