Improve AutoLoader test coverage
authorKunal Mehta <legoktm@member.fsf.org>
Sun, 27 May 2018 04:29:36 +0000 (21:29 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sun, 27 May 2018 04:29:36 +0000 (21:29 -0700)
Change-Id: Iddb24cad41979a4798392ab08d104dac41ed736d

includes/AutoLoader.php
tests/phpunit/data/autoloader/psr4/TestFooBar.php [new file with mode: 0644]
tests/phpunit/includes/AutoLoaderTest.php

index 62b1d39..9fc063a 100644 (file)
@@ -123,6 +123,7 @@ class AutoLoader {
         *
         * @see <http://www.php-fig.org/psr/psr-4/>
         * @private Only public for usage in AutoloadGenerator
+        * @codeCoverageIgnore
         * @since 1.31
         * @return string[]
         */
diff --git a/tests/phpunit/data/autoloader/psr4/TestFooBar.php b/tests/phpunit/data/autoloader/psr4/TestFooBar.php
new file mode 100644 (file)
index 0000000..4a2e11f
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+
+namespace Test\MediaWiki\AutoLoader;
+
+class TestFooBar {
+}
index 980fd8d..af6911d 100644 (file)
@@ -4,6 +4,9 @@
  * @covers AutoLoader
  */
 class AutoLoaderTest extends MediaWikiTestCase {
+
+       private $oldPsr4;
+
        protected function setUp() {
                parent::setUp();
 
@@ -21,6 +24,15 @@ class AutoLoaderTest extends MediaWikiTestCase {
                $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', [
                        'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
                ] );
+
+               $this->oldPsr4 = AutoLoader::$psr4Namespaces;
+               AutoLoader::$psr4Namespaces['Test\\MediaWiki\\AutoLoader\\'] =
+                       __DIR__ . '/../data/autoloader/psr4';
+       }
+
+       protected function tearDown() {
+               AutoLoader::$psr4Namespaces = $this->oldPsr4;
+               parent::tearDown();
        }
 
        public function testCoreClass() {
@@ -45,4 +57,8 @@ class AutoLoaderTest extends MediaWikiTestCase {
                $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class,
                        "unserialize() can load classes case-insensitively." );
        }
+
+       public function testPsr4() {
+               $this->assertTrue( class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ) );
+       }
 }