From: Antoine Musso Date: Wed, 30 May 2018 19:02:46 +0000 (+0200) Subject: registration: Initialize PSR-4 namespaces at same stage as normal autoloader X-Git-Tag: 1.34.0-rc.0~5235^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=224864ebddab2e448f9ae4f247b85c652d9df42e;p=lhc%2Fweb%2Fwiklou.git registration: Initialize PSR-4 namespaces at same stage as normal autoloader readFromQueue() injects the content of AutoloadClasses to $wgAutoloadClasses however it missed doing the same for AutoloadNamespaces. When using the installer with an extension having AutoloadNamespaces set, its classes would not be found. Make ExtensionRegistry append to AutoLoader::$psr4Namespaces, and add a test to cover the new behavior. Bug: T195783 Change-Id: Id61155867a4ca7d9bc4a347f8671da74b0fa490b --- diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index b34a123635..c91d6d6e85 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -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 index 0000000000..19c502c7b3 --- /dev/null +++ b/tests/phpunit/data/registration/autoload_namespaces.json @@ -0,0 +1,7 @@ +{ + "manifest_version": 2, + "name": "WithAutoloadNamespaces", + "AutoloadNamespaces": { + "Test\\MediaWiki\\AutoLoader\\": "../autoloader/psr4/" + } +} diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index a372c8c26d..7120a91a97 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -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 */