Unit tests: Remove duplicated code in ExtensionRegistry
authorKosta Harlan <kharlan@wikimedia.org>
Mon, 19 Aug 2019 08:16:06 +0000 (10:16 +0200)
committerKosta Harlan <kharlan@wikimedia.org>
Mon, 19 Aug 2019 08:16:06 +0000 (10:16 +0200)
Also use wgExtensionDirectory and wgStyleDirectory in bootstrap.php, and add
clarifying comment about why ExtensionRegistry->readFromQueue is not used.

Follows-Up: I237a9f82e4d1b05cf2f08b3e4bb7ffcd8d47111c

Bug: T226911
Change-Id: I9c8e70006600c6eebbdc46dc7483a4481859ea16

includes/registration/ExtensionRegistry.php
tests/phpunit/bootstrap.php

index 9cae73c..b30d1d8 100644 (file)
@@ -307,16 +307,6 @@ class ExtensionRegistry {
                                $autoloadNamespaces
                        );
 
-                       if ( isset( $info['AutoloadClasses'] ) ) {
-                               $autoload = $this->processAutoLoader( $dir, $info['AutoloadClasses'] );
-                               $GLOBALS['wgAutoloadClasses'] += $autoload;
-                               $autoloadClasses += $autoload;
-                       }
-                       if ( isset( $info['AutoloadNamespaces'] ) ) {
-                               $autoloadNamespaces += $this->processAutoLoader( $dir, $info['AutoloadNamespaces'] );
-                               AutoLoader::$psr4Namespaces += $autoloadNamespaces;
-                       }
-
                        // get all requirements/dependencies for this extension
                        $requires = $processor->getRequirements( $info, $this->checkDev );
 
index f227ae1..9e79496 100644 (file)
@@ -74,16 +74,19 @@ wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
 wfRequireOnceInGlobalScope( "$IP/includes/GlobalFunctions.php" );
 
-// Load extensions/skins present in filesystem so that classes can be discovered.
+// Populate classes and namespaces from extensions and skins present in filesystem.
 $directoryToJsonMap = [
-       'extensions' => [ 'extension.json', 'extension-wip.json' ],
-       'skins' => [ 'skin.json', 'skin-wip.json' ]
+       $GLOBALS['wgExtensionDirectory'] => [ 'extension.json', 'extension-wip.json' ],
+       $GLOBALS['wgStyleDirectory'] => [ 'skin.json', 'skin-wip.json' ]
 ];
 foreach ( $directoryToJsonMap as $directory => $jsonFile ) {
-       foreach ( new DirectoryIterator( __DIR__ . '/../../' . $directory ) as $iterator ) {
+       foreach ( new DirectoryIterator( $directory ) as $iterator ) {
                foreach ( $jsonFile as $file ) {
+
                        $jsonPath = $iterator->getPathname() . '/' . $file;
                        if ( file_exists( $jsonPath ) ) {
+                               // ExtensionRegistry->readFromQueue is not used as it checks extension/skin
+                               // dependencies, which we don't need or want for unit tests.
                                $json = file_get_contents( $jsonPath );
                                $info = json_decode( $json, true );
                                $dir = dirname( $jsonPath );