Merge "registration: Initialize PSR-4 namespaces at same stage as normal autoloader"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 31 May 2018 07:39:04 +0000 (07:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 31 May 2018 07:39:04 +0000 (07:39 +0000)
includes/registration/ExtensionRegistry.php
tests/phpunit/data/registration/autoload_namespaces.json [new file with mode: 0644]
tests/phpunit/includes/registration/ExtensionRegistryTest.php

index b34a123..c91d6d6 100644 (file)
@@ -247,6 +247,7 @@ class ExtensionRegistry {
                        }
                        if ( isset( $info['AutoloadNamespaces'] ) ) {
                                $autoloadNamespaces += $this->processAutoLoader( $dir, $info['AutoloadNamespaces'] );
+                               AutoLoader::$psr4Namespaces += $autoloadNamespaces;
                        }
 
                        // get all requirements/dependencies for this extension
diff --git a/tests/phpunit/data/registration/autoload_namespaces.json b/tests/phpunit/data/registration/autoload_namespaces.json
new file mode 100644 (file)
index 0000000..19c502c
--- /dev/null
@@ -0,0 +1,7 @@
+{
+       "manifest_version": 2,
+       "name": "WithAutoloadNamespaces",
+       "AutoloadNamespaces": {
+               "Test\\MediaWiki\\AutoLoader\\": "../autoloader/psr4/"
+       }
+}
index a372c8c..7120a91 100644 (file)
@@ -71,6 +71,17 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                ] );
        }
 
+       public function testReadFromQueueInitializeAutoloaderWithPsr4Namespaces() {
+               $registry = new ExtensionRegistry();
+               $registry->readFromQueue( [
+                       "{$this->dataDir}/autoload_namespaces.json" => 1
+               ] );
+               $this->assertTrue(
+                       class_exists( 'Test\\MediaWiki\\AutoLoader\\TestFooBar' ),
+                       "Registry initializes Autoloader from AutoloadNamespaces"
+               );
+       }
+
        /**
         * @dataProvider provideExportExtractedDataGlobals
         */