From e298f548f69561a5df55114afc05d22b5e57a4df Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 24 May 2018 22:13:22 -0700 Subject: [PATCH] Split AutoloaderTest into a structure and class test AutoloaderTest covers the AutoLoader class, and AutoLoaderStructureTest covers the structure part of the test. Change-Id: Ic4e7bfd670e1c3413631bda31260cc1cc825b1a2 --- includes/utils/AutoloadGenerator.php | 2 +- tests/phpunit/includes/AutoLoaderTest.php | 48 ++++++++++++++++++ ...erTest.php => AutoLoaderStructureTest.php} | 50 ++----------------- 3 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 tests/phpunit/includes/AutoLoaderTest.php rename tests/phpunit/structure/{AutoLoaderTest.php => AutoLoaderStructureTest.php} (77%) diff --git a/includes/utils/AutoloadGenerator.php b/includes/utils/AutoloadGenerator.php index 98d2c0e550..b437653975 100644 --- a/includes/utils/AutoloadGenerator.php +++ b/includes/utils/AutoloadGenerator.php @@ -389,7 +389,7 @@ class ClassCollector { return; } // Note: When changing class name discovery logic, - // AutoLoaderTest.php may also need to be updated. + // AutoLoaderStructureTest.php may also need to be updated. switch ( $token[0] ) { case T_NAMESPACE: case T_CLASS: diff --git a/tests/phpunit/includes/AutoLoaderTest.php b/tests/phpunit/includes/AutoLoaderTest.php new file mode 100644 index 0000000000..980fd8d40c --- /dev/null +++ b/tests/phpunit/includes/AutoLoaderTest.php @@ -0,0 +1,48 @@ +mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [ + 'TestAutoloadedLocalClass' => + __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', + 'TestAutoloadedCamlClass' => + __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', + 'TestAutoloadedSerializedClass' => + __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php', + ] ); + AutoLoader::resetAutoloadLocalClassesLower(); + + $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [ + 'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php', + ] ); + } + + public function testCoreClass() { + $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) ); + } + + public function testExtensionClass() { + $this->assertTrue( class_exists( 'TestAutoloadedClass' ) ); + } + + public function testWrongCaseClass() { + $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); + + $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) ); + } + + public function testWrongCaseSerializedClass() { + $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); + + $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}'; + $uncerealized = unserialize( $dummyCereal ); + $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class, + "unserialize() can load classes case-insensitively." ); + } +} diff --git a/tests/phpunit/structure/AutoLoaderTest.php b/tests/phpunit/structure/AutoLoaderStructureTest.php similarity index 77% rename from tests/phpunit/structure/AutoLoaderTest.php rename to tests/phpunit/structure/AutoLoaderStructureTest.php index 46255f31ab..4d6867f8e2 100644 --- a/tests/phpunit/structure/AutoLoaderTest.php +++ b/tests/phpunit/structure/AutoLoaderStructureTest.php @@ -1,25 +1,9 @@ mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', [ - 'TestAutoloadedLocalClass' => - __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', - 'TestAutoloadedCamlClass' => - __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', - 'TestAutoloadedSerializedClass' => - __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php', - ] ); - AutoLoader::resetAutoloadLocalClassesLower(); - - $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [ - 'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php', - ] ); - } - +/** + * @coversNothing + */ +class AutoLoaderStructureTest extends MediaWikiTestCase { /** * Assert that there were no classes loaded that are not registered with the AutoLoader. * @@ -48,7 +32,6 @@ class AutoLoaderTest extends MediaWikiTestCase { } /** - * @coversNothing * @dataProvider providePSR4Completeness */ public function testPSR4Completeness( $prefix, $file ) { @@ -181,30 +164,7 @@ class AutoLoaderTest extends MediaWikiTestCase { ]; } - function testCoreClass() { - $this->assertTrue( class_exists( 'TestAutoloadedLocalClass' ) ); - } - - function testExtensionClass() { - $this->assertTrue( class_exists( 'TestAutoloadedClass' ) ); - } - - function testWrongCaseClass() { - $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); - - $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) ); - } - - function testWrongCaseSerializedClass() { - $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); - - $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}'; - $uncerealized = unserialize( $dummyCereal ); - $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class, - "unserialize() can load classes case-insensitively." ); - } - - function testAutoloadOrder() { + public function testAutoloadOrder() { $path = realpath( __DIR__ . '/../../..' ); $oldAutoload = file_get_contents( $path . '/autoload.php' ); $generator = new AutoloadGenerator( $path, 'local' ); -- 2.20.1