Seb35 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312968

Change subject: Add standalone PHPUnit and make some tests more robust
......................................................................

Add standalone PHPUnit and make some tests more robust

Code:
* Replaced the previous parameter $entryPoint in constructor
  by an array $parameters with EntryPoint (string) and
  ExtensionRegistry (bool) keys; the second allow to test
  a specific environment
* By default, the parameter ExtensionRegistry is computed
  just before its use, i.e. in the heuristic about the
  extension loading mechanism

Tests:
* Add some tests with a fixed ExtensionRegistry parameter to
  avoid relying on the underlying MediaWiki
* Changed the default environment from the underlying MediaWiki
  to a mocked MediaWiki installation

Testing:
* PHPUnit can still be called as a standard MediaWiki script
  `mwscript --wiki mywiki.org tests/phpunit/phpunit.php` and
  can also be called with a standalone PHPUnit; in this case
  it is easier to call `composer phpunit` or `composer unit`
  because a light change must be done on the testing code,
  automatically done with the Composer command
  NB: there is a bit less tests with standalone PHPUnit because
  some tests are automatically added in MW framework and the
  ExtensionRegistry class is missing
* Tested with processIsolation; adapted a bit to get successes
  in MultiversionInstallationTest
* Tested with PHP 7.1RC1 (cli and phpdbg) 7.0.10 (cli+Xdebug
  and phpdbg), and PHP 5.6 (cli): 100% line code coverage in
  PHP 7 but two lines wrongly missing in PHP 5.6.
* Approximative duration:
  * Standalone PHPUnit: 200ms for tests alone with PHP 7,
    1.7s with code coverage
  * MediaWiki PHPUnit: 11s with PHP 7, 15s with code coverage,
    30s with PHP 5.6

Change-Id: I55a468292bb37b4fc89934f1b6f32e4139581f7e
---
M .gitignore
M composer.json
A phpunit.xml
M src/MediaWikiFarm.php
M src/MediaWikiFarmScript.php
M tests/perfs/MediaWikiFarmTestPerfs.php
M tests/phpunit/ConfigurationTest.php
M tests/phpunit/ConstructionTest.php
M tests/phpunit/FunctionsTest.php
M tests/phpunit/InstallationIndependantTest.php
M tests/phpunit/LoadingTest.php
M tests/phpunit/MediaWikiFarmScriptTest.php
M tests/phpunit/MediaWikiFarmTestCase.php
M tests/phpunit/MonoversionInstallationTest.php
M tests/phpunit/MultiversionInstallationTest.php
A tests/phpunit/data/config/varwikiversions.php
A tests/phpunit/data/config/versions.php
A tests/phpunit/data/mediawiki/vstub/maintenance/showJobs.php
A tests/phpunit/data/mediawiki/vstub2/maintenance/showJobs.php
19 files changed, 451 insertions(+), 171 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm 
refs/changes/68/312968/1

diff --git a/.gitignore b/.gitignore
index fa4674d..9a307b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,11 +12,10 @@
 /vendor
 
 # Tests
-/tests/phpunit/data/config/versions.php
-/tests/phpunit/data/config/varwikiversions.php
 /tests/phpunit/data/config/deployments.php
 /tests/phpunit/data/config/testdeploymentsfarmversions.php
 /tests/perfs/results
 
 # Compiled code documentation
 /docs/code
+/docs/coverage
diff --git a/composer.json b/composer.json
index 7eb1384..00903f4 100644
--- a/composer.json
+++ b/composer.json
@@ -26,8 +26,20 @@
                "lint": "parallel-lint --exclude vendor .",
                "phpcs": "phpcs -p -s",
                "phpdoc": "phpdoc -d bin,src -t ./docs/code",
+               "phpunit": [
+                       "sed -i 's/extends MediaWikiTestCase/extends 
PHPUnit_Framework_TestCase/' tests/phpunit/MediaWikiFarmTestCase.php",
+                       "phpdbg -qrr `which phpunit` --strict-coverage",
+                       "sed -i 's/extends PHPUnit_Framework_TestCase/extends 
MediaWikiTestCase/' tests/phpunit/MediaWikiFarmTestCase.php"
+               ],
+               "unit": [
+                       "sed -i 's/extends MediaWikiTestCase/extends 
PHPUnit_Framework_TestCase/' tests/phpunit/MediaWikiFarmTestCase.php",
+                       "phpunit --no-coverage",
+                       "sed -i 's/extends PHPUnit_Framework_TestCase/extends 
MediaWikiTestCase/' tests/phpunit/MediaWikiFarmTestCase.php"
+               ],
                "test": [
                        "composer lint",
+                       "composer unit",
+                       "composer phpunit",
                        "composer phpcs",
                        "composer phpdoc"
                ]
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..aeeb9e1
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,35 @@
+<phpunit
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd";
+         backupGlobals="false"
+         backupStaticAttributes="false"
+         cacheTokens="false"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         forceCoversAnnotation="true"
+         mapTestClassNameToCoveredClassName="false"
+         processIsolation="false"
+         stopOnError="false"
+         stopOnFailure="false"
+         stopOnIncomplete="false"
+         stopOnSkipped="false"
+         stopOnRisky="false"
+         verbose="true">
+       <testsuites>
+               <testsuite name="Complete">
+                       <directory>tests/phpunit</directory>
+               </testsuite>
+       </testsuites>
+       <filter>
+               <whitelist>
+                       <directory suffix=".php">bin</directory>
+                       <directory suffix=".php">src</directory>
+                       <directory suffix=".php">www</directory>
+                       <file>MediaWikiFarm.php</file>
+               </whitelist>
+       </filter>
+       <logging>
+               <log type="coverage-html" target="docs/coverage" />
+       </logging>
+</phpunit>
diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php
index 98d3994..f6e8885 100644
--- a/src/MediaWikiFarm.php
+++ b/src/MediaWikiFarm.php
@@ -36,8 +36,11 @@
         * Properties
         * ---------- */
 
-       /** @var string Entry point script. */
-       protected $entryPoint = '';
+       /** @var array Parameters: EntryPoint (string) and ExtensionRegistry 
(bool). */
+       protected $parameters = array(
+               'EntryPoint' => '',
+               'ExtensionRegistry' => null,
+       );
 
        /** @var string Farm code directory. */
        protected $farmDir = '';
@@ -83,15 +86,16 @@
         * --------- */
 
        /**
-        * Get entry point script.
+        * Get a parameter.
         *
-        * @mediawikifarm-const
-        * @mediawikifarm-idempotent
-        *
-        * @return string Entry point script.
+        * @param string $key Parameter name.
+        * @return mixed|null Requested parameter or null if nonexistant.
         */
-       function getEntryPoint() {
-               return $this->entryPoint;
+       function getParameter( $key ) {
+               if( array_key_exists( $key, $this->parameters ) ) {
+                       return $this->parameters[$key];
+               }
+               return null;
        }
 
        /**
@@ -179,19 +183,8 @@
         * @return array MediaWiki configuration, either entire, either a part 
depending on the parameter.
         */
        function getConfiguration( $key = null ) {
-               switch( $key ) {
-                       case 'general':
-                               return $this->configuration['general'];
-                       case 'settings':
-                               return $this->configuration['settings'];
-                       case 'arrays':
-                               return $this->configuration['arrays'];
-                       case 'skins':
-                               return $this->configuration['skins'];
-                       case 'extensions':
-                               return $this->configuration['extensions'];
-                       case 'execFiles':
-                               return $this->configuration['execFiles'];
+               if( array_key_exists( $key, $this->configuration ) ) {
+                       return $this->configuration[$key];
                }
                return $this->configuration;
        }
@@ -211,15 +204,19 @@
         *
         * @param string $entryPoint Name of the entry point, e.g. 'index.php', 
'load.php'…
         * @param string|null $host Host name (string) or null to use the 
global variables HTTP_HOST or SERVER_NAME.
+        * @param array $parameters Parameters, see object property $parameters.
         * @return string $entryPoint Identical entry point as passed in input.
         */
-       static function load( $entryPoint = '', $host = null ) {
+       static function load( $entryPoint = '', $host = null, $parameters = 
array() ) {
 
                global $wgMediaWikiFarm, $wgMediaWikiFarmConfigDir, 
$wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir;
 
                try {
                        # Initialise object
-                       $wgMediaWikiFarm = new MediaWikiFarm( $host, 
$wgMediaWikiFarmConfigDir, $wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir, 
$entryPoint );
+                       $wgMediaWikiFarm = new MediaWikiFarm( $host,
+                               $wgMediaWikiFarmConfigDir, 
$wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir,
+                               array_merge( $parameters, array( 'EntryPoint' 
=> $entryPoint ) )
+                       );
 
                        # Check existence
                        $exists = $wgMediaWikiFarm->checkExistence();
@@ -369,12 +366,10 @@
                }
 
                # Register this extension MediaWikiFarm to appear in 
Special:Version
-               if( function_exists( 'wfLoadExtension' ) ) {
+               if( $this->parameters['ExtensionRegistry'] ) {
                        wfLoadExtension( 'MediaWikiFarm', $this->codeDir ? 
$this->farmDir . '/extension.json' : null );
                }
                else {
-                       // Ignore this code coverage because tests are probably 
run on MediaWiki 1.25+
-                       // @codeCoverageIgnoreStart
                        $GLOBALS['wgExtensionCredits']['other'][] = array(
                                'path' => $this->farmDir . '/MediaWikiFarm.php',
                                'name' => 'MediaWikiFarm',
@@ -389,13 +384,12 @@
                        
$GLOBALS['wgAutoloadClasses']['MWFConfigurationException'] = 
'src/MediaWikiFarm.php';
                        $GLOBALS['wgMessagesDirs']['MediaWikiFarm'] = array( 
'i18n' );
                        $GLOBALS['wgHooks']['UnitTestsList'][] = array( 
'MediaWikiFarm::onUnitTestsList' );
-                       // @codeCoverageIgnoreEnd
                }
 
                # Load extensions with the wfLoadExtension mechanism
                foreach( $this->configuration['extensions'] as $extension => 
$value ) {
 
-                       if( $value == 'wfLoadExtension' ) {
+                       if( $value == 'wfLoadExtension' && $extension != 
'MediaWikiFarm' ) {
 
                                wfLoadExtension( $extension );
                        }
@@ -472,12 +466,12 @@
         * @param string $configDir Configuration directory.
         * @param string|null $codeDir Code directory; if null, the current 
MediaWiki installation is used.
         * @param string|false $cacheDir Cache directory; if false, the cache 
is disabled.
-        * @param string $entryPoint Entry point script.
+        * @param array $parameters Parameters: EntryPoint (string) and 
ExtensionRegistry (bool).
         * @return MediaWikiFarm
         * @throws MWFConfigurationException When no farms.yml/php/json is 
found.
         * @throws InvalidArgumentException When wrong input arguments are 
passed.
         */
-       function __construct( $host, $configDir, $codeDir = null, $cacheDir = 
false, $entryPoint = '' ) {
+       function __construct( $host, $configDir, $codeDir = null, $cacheDir = 
false, $parameters = array() ) {
 
                # Default value for host
                # Warning: do not use $GLOBALS['_SERVER']['HTTP_HOST']: bug 
with PHP7: it is not initialised in early times of a script
@@ -506,16 +500,27 @@
                if( !is_string( $cacheDir ) && $cacheDir !== false ) {
                        throw new InvalidArgumentException( 'Cache directory 
must be false or a directory' );
                }
-               if( !is_string( $entryPoint ) ) {
-                       throw new InvalidArgumentException( 'Entry point must 
be a string' );
+               if( !is_array( $parameters ) ) {
+                       throw new InvalidArgumentException( 'Parameters must be 
an array' );
+               } else {
+                       foreach( $parameters as $key => $value ) {
+                               if( $key == 'EntryPoint' && !is_string( $value 
) ) {
+                                       throw new InvalidArgumentException( 
'Entry point must be a string' );
+                               } elseif( $key == 'ExtensionRegistry' && 
!is_bool( $value ) ) {
+                                       throw new InvalidArgumentException( 
'ExtensionRegistry parameter must be a bool' );
+                               }
+                       }
                }
 
                # Set parameters
                $this->farmDir = dirname( dirname( __FILE__ ) );
-               $this->entryPoint = $entryPoint;
                $this->configDir = $configDir;
                $this->codeDir = $codeDir;
                $this->cacheDir = $cacheDir;
+               $this->parameters = array_merge( array(
+                       'EntryPoint' => '',
+                       'ExtensionRegistry' => null,
+               ), $parameters );
 
                # Create cache directory
                if( $this->cacheDir && !is_dir( $this->cacheDir ) ) {
@@ -701,7 +706,7 @@
                global $IP;
 
                # Special case for the update: new (uncached) version must be 
used
-               $cache = ( $this->entryPoint != 'maintenance/update.php' );
+               $cache = ( $this->parameters['EntryPoint'] != 
'maintenance/update.php' );
 
                # Read cache file
                $deployments = array();
@@ -1284,6 +1289,11 @@
 
                $settings = &$this->configuration['settings'];
 
+               # Autodetect if ExtensionRegistry is here
+               if( is_null( $this->parameters['ExtensionRegistry'] ) ) {
+                       $this->parameters['ExtensionRegistry'] = class_exists( 
'ExtensionRegistry' );
+               }
+
                # Search for skin and extension activation
                foreach( $settings as $setting => $value ) {
                        if( preg_match( '/^wgUse(Extension|Skin)(.+)$/', 
$setting, $matches ) && $value === true ) {
@@ -1319,6 +1329,11 @@
                                unset( $settings[$setting] );
                        }
                }
+
+               $settings['wgUseExtensionMediaWikiFarm'] = true;
+               if( $this->parameters['ExtensionRegistry'] ) {
+                       $this->configuration['extensions']['MediaWikiFarm'] = 
'wfLoadExtension';
+               }
        }
 
        /**
@@ -1337,7 +1352,7 @@
                }
 
                # An extension.json/skin.json file is in the directory -> 
assume it is the loading mechanism
-               if( function_exists( 'wfLoad' . ucfirst( $type ) ) && is_file( 
$this->variables['$CODE'].'/'.$type.'s/'.$name.'/'.$type.'.json' ) ) {
+               if( $this->parameters['ExtensionRegistry'] && is_file( 
$this->variables['$CODE'].'/'.$type.'s/'.$name.'/'.$type.'.json' ) ) {
                        return 'wfLoad' . ucfirst( $type );
                }
 
@@ -1425,12 +1440,13 @@
 
                # Extensions loaded with wfLoadExtension
                $localSettings .= "\n# Extensions\n";
-               if( function_exists( 'wfLoadExtension' ) ) {
-                       $localSettings .= "wfLoadExtension( 'MediaWikiFarm'" . 
( $this->codeDir ? ', ' . var_export( $this->farmDir . '/extension.json', true 
) : '' ) ." );\n";
-               }
                foreach( $configuration['extensions'] as $extension => $loading 
) {
                        if( $loading == 'wfLoadExtension' ) {
-                               $localSettings .= "wfLoadExtension( 
'$extension' );\n";
+                               if( $extension == 'MediaWikiFarm' ) {
+                                       $localSettings .= "wfLoadExtension( 
'MediaWikiFarm'" . ( $this->codeDir ? ', ' . var_export( $this->farmDir . 
'/extension.json', true ) : '' ) ." );\n";
+                               } else {
+                                       $localSettings .= "wfLoadExtension( 
'$extension' );\n";
+                               }
                        }
                }
 
diff --git a/src/MediaWikiFarmScript.php b/src/MediaWikiFarmScript.php
index d894999..bc88ed9 100644
--- a/src/MediaWikiFarmScript.php
+++ b/src/MediaWikiFarmScript.php
@@ -33,20 +33,17 @@
 
                parent::__construct( $argc, $argv );
 
-               $this->shortUsage = <<<HELP
-
+               $this->shortUsage = "
     Usage: php {$this->argv[0]} MediaWikiScript --wiki=hostname …
 
     Parameters:
 
-      - MediaWikiScript: name of the script, e.g. "maintenance/runJobs.php"
-      - hostname: hostname of the wiki, e.g. "mywiki.example.org"
-
-HELP;
+      - MediaWikiScript: name of the script, e.g. \"maintenance/runJobs.php\"
+      - hostname: hostname of the wiki, e.g. \"mywiki.example.org\"
+";
 
                $fullPath = realpath( $this->argv[0] );
-               $this->longUsage = <<<HELP
-    | Note simple names as "runJobs" will be converted to 
"maintenance/runJobs.php".
+               $this->longUsage = "    | Note simple names as \"runJobs\" will 
be converted to \"maintenance/runJobs.php\".
     |
     | For easier use, you can alias it in your shell:
     |
@@ -57,8 +54,7 @@
     | 1 = missing wiki (similar to HTTP 404)
     | 4 = user error, like a missing parameter (similar to HTTP 400)
     | 5 = internal error in farm configuration (similar to HTTP 500)
-
-HELP;
+";
        }
 
        /**
@@ -125,14 +121,12 @@
                $suffix = $wgMediaWikiFarm->getVariable( '$SUFFIX' );
                $version = $wgMediaWikiFarm->getVariable( '$VERSION' ) ? 
$wgMediaWikiFarm->getVariable( '$VERSION' ) : 'current';
                $code = $wgMediaWikiFarm->getVariable( '$CODE' );
-               echo <<<PARAMS
-
+               echo "
 Wiki:    {$this->host} (wikiID: $wikiID; suffix: $suffix)
 Version: $version: $code
 Script:  {$this->script}
 
-
-PARAMS;
+";
 
                # Export symbols
                $this->exportArguments();
diff --git a/tests/perfs/MediaWikiFarmTestPerfs.php 
b/tests/perfs/MediaWikiFarmTestPerfs.php
index a2b48da..f9f4cdc 100644
--- a/tests/perfs/MediaWikiFarmTestPerfs.php
+++ b/tests/perfs/MediaWikiFarmTestPerfs.php
@@ -17,7 +17,7 @@
        protected static $counters = array();
 
        /** @var float Entry point (bis). */
-       protected static $entryPoint2 = '';
+       protected static $entryPoint = '';
 
        /** @var float Profile (0=farm, 1=classical installation). */
        protected static $profile = 0;
@@ -39,7 +39,7 @@
                        file_put_contents( dirname( __FILE__ ) . 
"/results/profile-$entryPoint.php", "<?php return 0;\n" );
                }
 
-               self::$entryPoint2 = $entryPoint;
+               self::$entryPoint = $entryPoint;
                self::$profile = include dirname( __FILE__ ) . 
"/results/profile-$entryPoint.php";
 
                $profile = ( self::$profile + 1 ) % 2;
@@ -81,7 +81,7 @@
                global $IP;
 
                $profile = self::$profile;
-               $entryPoint = self::$entryPoint2;
+               $entryPoint = self::$entryPoint;
 
                if( !is_file( dirname( __FILE__ ) . 
"/results/measures-$entryPoint.php" ) && $profile == 0 ) {
 
diff --git a/tests/phpunit/ConfigurationTest.php 
b/tests/phpunit/ConfigurationTest.php
index 1100a0c..7bd539f 100644
--- a/tests/phpunit/ConfigurationTest.php
+++ b/tests/phpunit/ConfigurationTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * Installation-independant methods tests.
@@ -31,6 +32,7 @@
         * @uses MediaWikiFarm::extractSkinsAndExtensions
         * @uses MediaWikiFarm::detectLoadingMechanism
         * @uses MediaWikiFarm::arrayMerge
+        * @uses AbstractMediaWikiFarmScript::rmdirr
         */
        function testHighlevelConfiguration() {
 
@@ -85,7 +87,7 @@
                );
 
                $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
null, self::$wgMediaWikiFarmCacheDir, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
null, self::$wgMediaWikiFarmCacheDir, array( 'EntryPoint' => 'index.php' )
                        );
 
                $this->assertTrue( $farm->checkExistence() );
@@ -99,6 +101,63 @@
                $this->assertEquals( $result['execFiles'], 
$farm->getConfiguration( 'execFiles' ) );
                $this->assertEquals( $result['general'], 
$farm->getConfiguration( 'general' ) );
                $this->assertEquals( $result, $farm->getConfiguration() );
+       }
+
+       /**
+        * Test the different extensions/skins loading mechanisms.
+        *
+        * @covers MediaWikiFarm::extractSkinsAndExtensions
+        * @covers MediaWikiFarm::detectLoadingMechanism
+        * @covers MediaWikiFarm::createLocalSettings
+        * @uses MediaWikiFarm::__construct
+        * @uses MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::getMediaWikiConfig
+        * @uses MediaWikiFarm::isLocalSettingsFresh
+        * @uses MediaWikiFarm::checkExistence
+        * @uses MediaWikiFarm::populateSettings
+        * @uses MediaWikiFarm::getConfiguration
+        * @uses MediaWikiFarm::checkHostVariables
+        * @uses MediaWikiFarm::setVersion
+        * @uses MediaWikiFarm::updateVersion
+        * @uses MediaWikiFarm::setOtherVariables
+        * @uses MediaWikiFarm::setVariable
+        * @uses MediaWikiFarm::replaceVariables
+        * @uses MediaWikiFarm::readFile
+        * @uses MediaWikiFarm::isMediaWiki
+        */
+       function testLoadingMechanisms() {
+
+               # First, without ExtensionRegistry
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org',
+                       self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
+                       array( 'EntryPoint' => 'index.php', 'ExtensionRegistry' 
=> false )
+               );
+
+               $farm->checkExistence();
+               $farm->getMediaWikiConfig();
+               $extensions = $farm->getConfiguration( 'extensions' );
+               $this->assertArrayHasKey( 'TestExtensionBiLoading', $extensions 
);
+               $this->assertArrayHasKey( 'TestExtensionRequireOnce', 
$extensions );
+               $this->assertEquals( 'require_once', 
$extensions['TestExtensionBiLoading'] );
+               $this->assertEquals( 'require_once', 
$extensions['TestExtensionRequireOnce'] );
+               // $this->assertArrayHasKey( 'MediaWikiFarm', 
$this->getConfiguration( 'extensions' ) );
+               // $this->assertEquals( 'require_once', 
$this->getConfiguration( 'extensions' )['MediaWikiFarm'] );
+
+               # Now with ExtensionRegistry
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org',
+                       self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
+                       array( 'EntryPoint' => 'index.php', 'ExtensionRegistry' 
=> true )
+               );
+
+               $farm->checkExistence();
+               $farm->getMediaWikiConfig();
+               $extensions = $farm->getConfiguration( 'extensions' );
+               $this->assertArrayHasKey( 'TestExtensionBiLoading', $extensions 
);
+               $this->assertArrayHasKey( 'TestExtensionWfLoadExtension', 
$extensions );
+               $this->assertArrayHasKey( 'MediaWikiFarm', $extensions );
+               $this->assertEquals( 'wfLoadExtension', 
$extensions['TestExtensionBiLoading'] );
+               $this->assertEquals( 'wfLoadExtension', 
$extensions['TestExtensionWfLoadExtension'] );
+               $this->assertEquals( 'wfLoadExtension', 
$extensions['MediaWikiFarm'] );
        }
 
        /**
@@ -128,12 +187,14 @@
         * @uses MediaWikiFarm::arrayMerge
         * @uses MediaWikiFarm::isMediaWiki
         * @ uses MediaWikiFarm::SiteConfigurationSiteParamsCallback
+        * @uses AbstractMediaWikiFarmScript::rmdirr
         */
        function testLoadMediaWikiConfigMultiversion() {
 
                $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', self::$wgMediaWikiFarmCacheDir, 
'index.php'
-                       );
+                       self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', self::$wgMediaWikiFarmCacheDir,
+                       array( 'EntryPoint' => 'index.php' )
+               );
 
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( dirname( dirname( dirname( __FILE__ ) ) ) 
. '/src/main.php', $farm->getConfigFile() );
@@ -148,8 +209,9 @@
 
                # Re-load to use config cache
                $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', self::$wgMediaWikiFarmCacheDir, 
'index.php'
-                       );
+                       self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', self::$wgMediaWikiFarmCacheDir,
+                       array( 'EntryPoint' => 'index.php' )
+               );
                $this->assertTrue( $farm->checkExistence() );
                $farm->getMediaWikiConfig( true );
                $config = $farm->getConfiguration( 'settings' );
@@ -190,10 +252,14 @@
         * @uses MediaWikiFarm::cacheFile
         * @uses MediaWikiFarm::arrayMerge
         * @ uses MediaWikiFarm::SiteConfigurationSiteParamsCallback
+        * @uses AbstractMediaWikiFarmScript::rmdirr
         */
        function testLoadMediaWikiConfigMonoversion() {
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir, 'index.php' );
+               $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
+                       self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir,
+                       array( 'EntryPoint' => 'index.php' )
+               );
 
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( dirname( dirname( dirname( __FILE__ ) ) ) 
. '/src/main.php', $farm->getConfigFile() );
@@ -204,7 +270,10 @@
                $this->assertEquals( 200000, $config['wgMemCachedTimeout'] );
 
                # Re-load to use config cache
-               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir, 'index.php' );
+               $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
+                       self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir,
+                       array( 'EntryPoint' => 'index.php' )
+               );
                $this->assertTrue( $farm->checkExistence() );
                $farm->getMediaWikiConfig(); # This is for code coverage
                $farm->getMediaWikiConfig( true );
diff --git a/tests/phpunit/ConstructionTest.php 
b/tests/phpunit/ConstructionTest.php
index c79ed55..076b97b 100644
--- a/tests/phpunit/ConstructionTest.php
+++ b/tests/phpunit/ConstructionTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * @group MediaWikiFarm
@@ -12,7 +13,7 @@
         *
         * @covers MediaWikiFarm::__construct
         * @covers MediaWikiFarm::selectFarm
-        * @covers MediaWikiFarm::getEntryPoint
+        * @covers MediaWikiFarm::getParameter
         * @covers MediaWikiFarm::getFarmConfiguration
         * @covers MediaWikiFarm::getVariable
         * @uses MediaWikiFarm::readFile
@@ -24,11 +25,12 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
 
-               $this->assertEquals( 'index.php', $farm->getEntryPoint( 
'index.php' ) );
+               $this->assertEquals( 'index.php', $farm->getParameter( 
'EntryPoint' ) );
+               $this->assertNull( $farm->getParameter( 'entryPoint' ) );
 
                $farmConfig = array(
                        'server' => 
'(?P<wiki>[a-z])\.testfarm-multiversion\.example\.org',
@@ -63,7 +65,7 @@
         *
         * @covers MediaWikiFarm::__construct
         * @covers MediaWikiFarm::selectFarm
-        * @covers MediaWikiFarm::getEntryPoint
+        * @covers MediaWikiFarm::getParameter
         * @covers MediaWikiFarm::getFarmConfiguration
         * @covers MediaWikiFarm::getVariable
         * @uses MediaWikiFarm::readFile
@@ -75,11 +77,11 @@
                                self::$wgMediaWikiFarmConfigDir,
                                null,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-monoversion.example.org', 
$farm->getVariable( '$SERVER' ) );
 
-               $this->assertEquals( 'index.php', $farm->getEntryPoint( 
'index.php' ) );
+               $this->assertEquals( 'index.php', $farm->getParameter( 
'EntryPoint' ) );
 
                $farmConfig = array(
                        'server' => 
'(?P<wiki>[a-z])\.testfarm-monoversion\.example\.org',
@@ -131,7 +133,7 @@
                                $wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -150,7 +152,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -169,7 +171,7 @@
                                0,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -190,7 +192,7 @@
                                $wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -209,7 +211,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                0,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -228,7 +230,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir . '/farms.php',
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -247,7 +249,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                0,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -257,7 +259,7 @@
         * @covers MediaWikiFarm::selectFarm
         *
         * @expectedException InvalidArgumentException
-        * @expectedExceptionMessage Entry point must be a string
+        * @expectedExceptionMessage Parameters must be an array
         */
        function testFailedConstruction8() {
 
@@ -289,7 +291,45 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
+       }
+
+       /**
+        * Test bad arguments in constructor.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        *
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage ExtensionRegistry parameter must be a bool
+        */
+       function testFailedConstruction10() {
+
+               $farm = new MediaWikiFarm(
+                               'a.testfarm-multiversion.example.org',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'ExtensionRegistry' => 'true' ) );
+       }
+
+       /**
+        * Test bad arguments in constructor.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        *
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Entry point must be a string
+        */
+       function testFailedConstruction11() {
+
+               $farm = new MediaWikiFarm(
+                               'a.testfarm-multiversion.example.org',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 0 ) );
        }
 
        /**
@@ -311,7 +351,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
        }
@@ -335,7 +375,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
        }
@@ -348,6 +388,7 @@
         * @covers MediaWikiFarm::getCacheDir
         * @uses MediaWikiFarm::readFile
         * @uses MediaWikiFarm::cacheFile
+        * @uses AbstractMediaWikiFarmScript::rmdirr
         */
        function testCacheDirectoryCreation() {
 
@@ -356,7 +397,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                self::$wgMediaWikiFarmCacheDir,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( self::$wgMediaWikiFarmCacheDir . 
'/testfarm-multiversion', $farm->getCacheDir() );
                $this->assertTrue( is_dir( self::$wgMediaWikiFarmCacheDir ) );
@@ -381,7 +422,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                /** Check code directory. */
                $this->assertEquals( self::$wgMediaWikiFarmCodeDir, 
$farm->getCodeDir() );
@@ -411,7 +452,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                null,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                /** Check code directory. */
                $this->assertNull( $farm->getCodeDir() );
@@ -438,7 +479,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
        }
@@ -460,7 +501,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -480,7 +521,7 @@
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
-                               'index.php' );
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -500,6 +541,8 @@
         * @uses MediaWikiFarm::setOtherVariables
         * @uses MediaWikiFarm::updateVersion
         * @uses MediaWikiFarm::isMediaWiki
+        * @uses MediaWikiFarm::getConfigFile
+        * @uses MediaWikiFarm::isLocalSettingsFresh
         */
        function testLoadingCorrect() {
 
@@ -508,19 +551,14 @@
                $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCodeDir', 
self::$wgMediaWikiFarmCodeDir );
                $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCacheDir', 
false );
                $this->backupAndSetGlobalSubvariable( '_SERVER', 'HTTP_HOST', 
'a.testfarm-multiversion.example.org' );
-
-               $curdir = getcwd();
-
-               chdir( dirname( $curdir ) );
+               chdir( self::$wgMediaWikiFarmCodeDir );
 
                $code = MediaWikiFarm::load( 'index.php' );
 
                $this->assertEquals( 200, $code );
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$GLOBALS['wgMediaWikiFarm']->getVariable( '$SERVER' ) );
-               $this->assertEquals( $curdir, getcwd() );
+               $this->assertEquals( self::$wgMediaWikiFarmCodeDir . '/vstub', 
getcwd() );
                $this->assertEquals( $GLOBALS['wgMediaWikiFarmCodeDir'] . '/' . 
$GLOBALS['wgMediaWikiFarm']->getVariable( '$VERSION' ), getcwd() );
-
-               chdir( $curdir );
        }
 
        /**
diff --git a/tests/phpunit/FunctionsTest.php b/tests/phpunit/FunctionsTest.php
index bd68983..ebf41b2 100644
--- a/tests/phpunit/FunctionsTest.php
+++ b/tests/phpunit/FunctionsTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * Functions tests.
diff --git a/tests/phpunit/InstallationIndependantTest.php 
b/tests/phpunit/InstallationIndependantTest.php
index 8a627cf..25cdce5 100644
--- a/tests/phpunit/InstallationIndependantTest.php
+++ b/tests/phpunit/InstallationIndependantTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * Installation-independant methods tests.
@@ -304,6 +305,7 @@
         * @covers MediaWikiFarm::cacheFile
         * @uses MediaWikiFarm::__construct
         * @uses MediaWikiFarm::selectFarm
+        * @uses AbstractMediaWikiFarmScript::rmdirr
         */
        function testCacheFile() {
 
@@ -413,6 +415,7 @@
                                'MonoBook' => 'require_once',
                        ),
                        'extensions' => array(
+                               'MediaWikiFarm' => 'wfLoadExtension',
                                'ParserFunctions' => 'wfLoadExtension',
                                'Echo' => 'require_once',
                                'SemanticMediaWiki' => 'composer',
diff --git a/tests/phpunit/LoadingTest.php b/tests/phpunit/LoadingTest.php
index 6acc395..785c038 100644
--- a/tests/phpunit/LoadingTest.php
+++ b/tests/phpunit/LoadingTest.php
@@ -1,6 +1,15 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
+
+if( !function_exists( 'wfLoadExtension' ) ) {
+       function wfLoadExtension( $ext, $path = null ) {}
+}
+
+if( !function_exists( 'wfLoadSkin' ) ) {
+       function wfLoadSkin( $skin, $path = null ) {}
+}
 
 /**
  * Tests about extensions+skins loading.
@@ -75,6 +84,7 @@
                                'wgUseTestExtensionBiLoading' => true,
                                'wgUseTestExtensionRequireOnce' => true,
                                'wgUseTestExtensionComposer' => true,
+                               'wgUseExtensionMediaWikiFarm' => true,
 
                                'wgUseExtensionTestExtensionWfLoadExtension' => 
true,
                                'wgUseExtensionTestExtensionBiLoading' => true,
@@ -101,6 +111,7 @@
                                'TestExtensionBiLoading' => 'wfLoadExtension',
                                'TestExtensionRequireOnce' => 'require_once',
                                'TestExtensionComposer' => 'composer',
+                               'MediaWikiFarm' => 'wfLoadExtension',
                        ),
                        'skins' => array(
                                'TestSkinWfLoadSkin' => 'wfLoadSkin',
@@ -112,7 +123,7 @@
                $this->backupGlobalVariables( array_keys( $result['settings'] ) 
);
                $this->backupAndUnsetGlobalVariable( 'wgFileExtensions' );
 
-               $exists = MediaWikiFarm::load( 'index.php', 
'a.testfarm-multiversion-test-extensions.example.org' );
+               $exists = MediaWikiFarm::load( 'index.php', 
'a.testfarm-multiversion-test-extensions.example.org', array( 
'ExtensionRegistry' => true ) );
                $this->assertEquals( 200, $exists );
                $this->assertEquals( 'vstub', $wgMediaWikiFarm->getVariable( 
'$VERSION' ) );
 
@@ -121,7 +132,6 @@
                $this->assertEquals( $result['arrays'], 
$wgMediaWikiFarm->getConfiguration( 'arrays' ) );
                $this->assertEquals( $result['extensions'], 
$wgMediaWikiFarm->getConfiguration( 'extensions' ) );
                $this->assertEquals( $result['skins'], 
$wgMediaWikiFarm->getConfiguration( 'skins' ) );
-
 
                $trueGlobals = array();
                foreach( $GLOBALS as $key => $value ) {
@@ -143,6 +153,46 @@
                        $this->assertContains( $wgStyleDirectory . 
'/TestSkinWfLoadSkin/skin.json', array_keys( 
ExtensionRegistry::getInstance()->getQueue() ) );
                        $this->assertContains( $wgStyleDirectory . 
'/TestSkinBiLoading/skin.json', array_keys( 
ExtensionRegistry::getInstance()->getQueue() ) );
                }
+       }
+
+       /**
+        * Test regular loading mechanisms.
+        *
+        * @covers MediaWikiFarm::loadMediaWikiConfig
+        * @uses MediaWikiFarm::load
+        * @uses MediaWikiFarm::__construct
+        * @uses MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::checkExistence
+        * @uses MediaWikiFarm::checkHostVariables
+        * @uses MediaWikiFarm::setVersion
+        * @uses MediaWikiFarm::isMediaWiki
+        * @uses MediaWikiFarm::updateVersion
+        * @uses MediaWikiFarm::setOtherVariables
+        * @uses MediaWikiFarm::setVariable
+        * @uses MediaWikiFarm::replaceVariables
+        * @uses MediaWikiFarm::getMediaWikiConfig
+        * @uses MediaWikiFarm::populateSettings
+        * @uses MediaWikiFarm::isLocalSettingsFresh
+        * @uses MediaWikiFarm::readFile
+        * @uses MediaWikiFarm::arrayMerge
+        * @uses MediaWikiFarm::getConfiguration
+        * @uses MediaWikiFarm::getVariable
+        * @uses MediaWikiFarm::extractSkinsAndExtensions
+        * @uses MediaWikiFarm::detectLoadingMechanism
+        */
+       function testRegistrationMediaWikiFarm() {
+
+               $this->backupGlobalVariable( 'wgAutoloadClasses' );
+
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+                       self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, false,
+                       array( 'ExtensionRegistry' => false )
+               );
+               $farm->checkExistence();
+               $farm->loadMediaWikiConfig();
+
+               $this->assertArrayHasKey( 'MediaWikiFarm', 
$GLOBALS['wgAutoloadClasses'] );
+               $this->assertEquals( 'src/MediaWikiFarm.php', 
$GLOBALS['wgAutoloadClasses']['MediaWikiFarm'] );
        }
 
        /**
@@ -181,8 +231,9 @@
 
                $result = array(
                        'settings' => array(
-                               'wgUseExtensionTestExtensionWfLoadExtension' => 
true,
-                               'wgUseSkinTestSkinWfLoadSkin' => true,
+                               'wgUseExtensionTestExtensionWfLoadExtension' => 
false,
+                               'wgUseSkinTestSkinWfLoadSkin' => false,
+                               'wgUseExtensionMediaWikiFarm' => true,
 
                                'wgUsePathInfo' => true,
 
@@ -197,13 +248,16 @@
                                'wgUseTestExtensionEmpty' => true,
                                'wgUseTestSkinEmpty' => true,
                        ),
-                       'extensions' => array(
-                               'TestExtensionWfLoadExtension' => 
'wfLoadExtension',
-                       ),
-                       'skins' => array(
-                               'TestSkinWfLoadSkin' => 'wfLoadSkin',
-                       ),
+                       'extensions' => array(),
+                       'skins' => array(),
                );
+               if( class_exists( 'ExtensionRegistry' ) ) {
+                       
$result['settings']['wgUseExtensionTestExtensionWfLoadExtension'] = true;
+                       $result['settings']['wgUseSkinTestSkinWfLoadSkin'] = 
true;
+                       $result['extensions']['TestExtensionWfLoadExtension'] = 
'wfLoadExtension';
+                       $result['extensions']['MediaWikiFarm'] = 
'wfLoadExtension';
+                       $result['skins']['TestSkinWfLoadSkin'] = 'wfLoadSkin';
+               }
 
                $exists = MediaWikiFarm::load( 'index.php', 
'b.testfarm-multiversion-test-extensions.example.org' );
                $this->assertEquals( 200, $exists );
diff --git a/tests/phpunit/MediaWikiFarmScriptTest.php 
b/tests/phpunit/MediaWikiFarmScriptTest.php
index 012624b..0c713b1 100644
--- a/tests/phpunit/MediaWikiFarmScriptTest.php
+++ b/tests/phpunit/MediaWikiFarmScriptTest.php
@@ -1,6 +1,8 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarmScript.php';
 
 /**
  * Tests about class Script.
@@ -128,7 +130,7 @@
 
                $wgMediaWikiFarmScript = new MediaWikiFarmScript( 2, array( 
self::$mwscriptPath, '-h' ) );
 
-               $wgMediaWikiFarmScript->main();
+               $this->assertFalse( $wgMediaWikiFarmScript->main() );
 
                $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
        }
@@ -148,7 +150,7 @@
 
                $wgMediaWikiFarmScript = new MediaWikiFarmScript( 2, array( 
self::$mwscriptPath, '--help' ) );
 
-               $wgMediaWikiFarmScript->main();
+               $this->assertFalse( $wgMediaWikiFarmScript->main() );
 
                $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
        }
@@ -385,6 +387,8 @@
                $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmConfigDir', 
self::$wgMediaWikiFarmConfigDir );
                $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCodeDir', 
null );
                $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCacheDir', 
false );
+               $this->backupAndSetGlobalVariable( 'IP', 
self::$wgMediaWikiFarmCodeDir . '/vstub' );
+               chdir( self::$wgMediaWikiFarmCodeDir . '/vstub' );
 
                $this->expectOutputString( "Script not found.\n" );
 
@@ -433,6 +437,8 @@
                $this->backupGlobalVariable( 'argv' );
                $this->backupGlobalSubvariable( '_SERVER', 'argc' );
                $this->backupGlobalSubvariable( '_SERVER', 'argv' );
+               $this->backupAndSetGlobalVariable( 'IP', 
self::$wgMediaWikiFarmCodeDir . '/vstub' );
+               chdir( self::$wgMediaWikiFarmCodeDir . '/vstub' );
 
                $this->expectOutputString( <<<OUTPUT
 
@@ -492,6 +498,8 @@
                $this->backupGlobalVariable( 'argv' );
                $this->backupGlobalSubvariable( '_SERVER', 'argc' );
                $this->backupGlobalSubvariable( '_SERVER', 'argv' );
+               $this->backupAndSetGlobalVariable( 'IP', 
self::$wgMediaWikiFarmCodeDir . '/vstub' );
+               chdir( self::$wgMediaWikiFarmCodeDir . '/vstub' );
 
                $this->expectOutputString( <<<OUTPUT
 
@@ -527,8 +535,10 @@
 
                $wgMediaWikiFarmScript = new MediaWikiFarmScript( 3, array( 
self::$mwscriptPath, '--wiki=a.testfarm-monoversion.example.org', 'showJobs' ) 
);
 
-               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub', dirname( __FILE__ ) . '/data/copie', true, array( 
'/skins/TestSkinEmpty', 'TestSkinRequireOnce' ) );
-               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub/includes/DefaultSettings.php', dirname( __FILE__ ) . 
'/data/copie/newdir', true );
+               MediaWikiFarmScript::copyr(
+                       self::$wgMediaWikiFarmCodeDir . '/vstub', dirname( 
__FILE__ ) . '/data/copie',
+                       true, array( '/skins/TestSkinEmpty', 
'TestSkinRequireOnce' ) );
+               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir . 
'/vstub/includes/DefaultSettings.php', dirname( __FILE__ ) . 
'/data/copie/newdir', true );
                $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
                $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/newdir/DefaultSettings.php' ) );
                $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie/skins/TestSkinEmpty' ) );
@@ -537,7 +547,9 @@
                MediaWikiFarmScript::rmdirr( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php', true );
                $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
 
-               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub', dirname( __FILE__ ) . '/data/copie', true, array(), array( '/', 
'/includes', '/includes/.*' ) );
+               MediaWikiFarmScript::copyr(
+                       self::$wgMediaWikiFarmCodeDir . '/vstub', dirname( 
__FILE__ ) . '/data/copie',
+                       true, array(), array( '/', '/includes', '/includes/.*' 
) );
                $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
 
                MediaWikiFarmScript::rmdirr( dirname( __FILE__ ) . 
'/data/copie', true );
diff --git a/tests/phpunit/MediaWikiFarmTestCase.php 
b/tests/phpunit/MediaWikiFarmTestCase.php
index 5228ce0..9b5e037 100644
--- a/tests/phpunit/MediaWikiFarmTestCase.php
+++ b/tests/phpunit/MediaWikiFarmTestCase.php
@@ -7,17 +7,16 @@
  * @license AGPL-3.0+ GNU Affero General Public License v3.0 ou version 
ultérieure
  */
 
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/AbstractMediaWikiFarmScript.php';
+
 
 abstract class MediaWikiFarmTestCase extends MediaWikiTestCase {
 
        /** @var string Configuration directory for tests. */
        public static $wgMediaWikiFarmConfigDir = '';
 
-       /** @var string Code directory of the real installation. */
-       public static $wgMediaWikiFarmCodeDir = '';
-
        /** @var string Code directory created for tests. */
-       public static $wgMediaWikiFarmCodeDir2 = '';
+       public static $wgMediaWikiFarmCodeDir = '';
 
        /** @var string Cache directory for tests. */
        public static $wgMediaWikiFarmCacheDir = '';
@@ -42,23 +41,25 @@
 
                # MediaWikiTestCase disables the @backupGlobals in its 
constructor.
                # Although it speeds up greatly the tests, there is no more 
checks on global variables.
-               # Uncomment it for that. When a lot of globals are changed, as 
it could be the case in
-               # LoadingTest, PHPUnit takes a LOT of time to compute 
differences (10+ min), so the
-               # backup* functions below restore the globals to the original 
value to make the diffs
-               # easy to check and to declare what globals are to be changed 
in the test (other
-               # changes will report the test as risky). MediaWiki equivalent 
functions (setMwGlobals)
+               # This restores the defaut value (case-by-case choice). When a 
lot of globals are changed,
+               # as it could be the case in LoadingTest, PHPUnit takes a LOT 
of time to compute differences
+               # (10+ min), so the backup* functions below restore the globals 
to the original value to
+               # make the diffs easy to check and to declare what globals are 
to be changed in the test
+               # (other changes will report the test as risky). MediaWiki 
equivalent functions (setMwGlobals)
                # were introduced in MW 1.21 and always assume the global 
exists, but in counterpart
                # they are more elaborated on serialisation heuristics.
-               // $this->backupGlobals = true;
+               $this->backupGlobals = null;
 
+               # Closures are thought to be serialisable although they are 
not, so blacklist them
                $this->backupGlobalsBlacklist = array_merge(
                        $this->backupGlobalsBlacklist,
                        array(
+                               'factory',
                                'wgExtensionFunctions',
                                'wgHooks',
                                'wgParamDefinitions',
-                               'factory',
                                'wgParser',
+                               'wgFlowActions',
                        )
                );
        }
@@ -68,37 +69,10 @@
         */
        static function setUpBeforeClass() {
 
-               global $IP;
-
-               $dirIP = basename( $IP );
-
                # Set test configuration parameters
                self::$wgMediaWikiFarmConfigDir = dirname( __FILE__ ) . 
'/data/config';
-               self::$wgMediaWikiFarmCodeDir = dirname( $IP );
-               self::$wgMediaWikiFarmCodeDir2 = dirname( __FILE__ ) . 
'/data/mediawiki';
+               self::$wgMediaWikiFarmCodeDir = dirname( __FILE__ ) . 
'/data/mediawiki';
                self::$wgMediaWikiFarmCacheDir = dirname( __FILE__ ) . 
'/data/cache';
-
-               # Create versions.php: the list of existing values for variable 
'$WIKIID' with their associated versions
-               $versionsFile = <<<PHP
-<?php
-
-return array(
-       'atestfarm' => '$dirIP',
-);
-
-PHP;
-               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/versions.php', $versionsFile );
-
-               # Create varwikiversions.php: the list of existing values for 
variable '$wiki' with their associated versions
-               $versionsFile = <<<PHP
-<?php
-
-return array(
-       'a' => '$dirIP',
-);
-
-PHP;
-               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/varwikiversions.php', $versionsFile );
 
                # Move http404.php to current directory - @todo: should be 
improved
                copy( self::$wgMediaWikiFarmConfigDir . '/http404.php', 
'phpunitHTTP404.php' );
@@ -109,7 +83,9 @@
         */
        protected function tearDown() {
 
-               wfRecursiveRemoveDir( self::$wgMediaWikiFarmCacheDir );
+               if( is_dir( self::$wgMediaWikiFarmCacheDir ) ) {
+                       AbstractMediaWikiFarmScript::rmdirr( 
self::$wgMediaWikiFarmCacheDir );
+               }
 
                # Restore backuped global variables
                $this->restoreSimpleGlobalVariables();
@@ -122,9 +98,9 @@
         */
        static function tearDownAfterClass() {
 
-               unlink( self::$wgMediaWikiFarmConfigDir . '/versions.php' );
-               unlink( self::$wgMediaWikiFarmConfigDir . 
'/varwikiversions.php' );
-               unlink( 'phpunitHTTP404.php' );
+               if( is_file( 'phpunitHTTP404.php' ) ) {
+                       unlink( 'phpunitHTTP404.php' );
+               }
 
                parent::tearDownAfterClass();
        }
diff --git a/tests/phpunit/MonoversionInstallationTest.php 
b/tests/phpunit/MonoversionInstallationTest.php
index de7f273..f8ae216 100644
--- a/tests/phpunit/MonoversionInstallationTest.php
+++ b/tests/phpunit/MonoversionInstallationTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * @group MediaWikiFarm
@@ -21,7 +22,7 @@
         */
        static function constructMediaWikiFarm( $host ) {
 
-               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, null, false, 'index.php' );
+               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, null, false, array( 'EntryPoint' => 
'index.php' ) );
 
                return $farm;
        }
diff --git a/tests/phpunit/MultiversionInstallationTest.php 
b/tests/phpunit/MultiversionInstallationTest.php
index b24a03d..6e2da15 100644
--- a/tests/phpunit/MultiversionInstallationTest.php
+++ b/tests/phpunit/MultiversionInstallationTest.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'MediaWikiFarmTestCase.php';
+require_once dirname( dirname( dirname( __FILE__ ) ) ) . 
'/src/MediaWikiFarm.php';
 
 /**
  * @group MediaWikiFarm
@@ -41,7 +42,7 @@
         */
        static function constructMediaWikiFarm( $host, $entryPoint = 
'index.php' ) {
 
-               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, self::$wgMediaWikiFarmCodeDir, false, 
$entryPoint );
+               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, self::$wgMediaWikiFarmCodeDir, false, array( 
'EntryPoint' => $entryPoint ) );
 
                return $farm;
        }
@@ -78,8 +79,6 @@
         */
        function testVariables() {
 
-               global $IP;
-
                $this->farm->checkExistence();
 
                /** Check variables. */
@@ -89,8 +88,8 @@
                                '$SERVER' => 
'a.testfarm-multiversion.example.org',
                                '$SUFFIX' => 'testfarm',
                                '$WIKIID' => 'atestfarm',
-                               '$VERSION' => basename( $IP ),
-                               '$CODE' => $IP,
+                               '$VERSION' => 'vstub',
+                               '$CODE' => self::$wgMediaWikiFarmCodeDir . 
'/vstub',
                                '$VERSIONS' => 'versions.php',
                        ),
                        $this->farm->getVariables() );
@@ -226,7 +225,7 @@
        function testFamilyFarm() {
 
                $farm = new MediaWikiFarm( 
'a.a.testfarm-multiversion-with-file-versions-other-keys.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( 'afamilytestfarm', $farm->getVariable( 
'$SUFFIX' ) );
@@ -234,7 +233,7 @@
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
 
                $farm = new MediaWikiFarm( 
'b.a.testfarm-multiversion-with-file-versions-other-keys.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( 'afamilytestfarm', $farm->getVariable( 
'$SUFFIX' ) );
@@ -242,7 +241,7 @@
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
 
                $farm = new MediaWikiFarm( 
'a.b.testfarm-multiversion-with-file-versions-other-keys.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( 'bfamilytestfarm', $farm->getVariable( 
'$SUFFIX' ) );
@@ -279,7 +278,7 @@
        function testDeploymedVersions() {
 
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
                $this->assertTrue( $farm->checkExistence() );
@@ -287,7 +286,7 @@
                $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php' ) );
 
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
@@ -300,7 +299,7 @@
         */
        function testDeploymedVersions2() {
 
-               # Create versions.php: the list of existing values for variable 
'$WIKIID' with their associated versions
+               # Create testdeploymentsfarmversions.php: the list of existing 
values for variable '$WIKIID' with their associated versions
                $versionsFile = <<<PHP
 <?php
 
@@ -309,10 +308,21 @@
 );
 
 PHP;
+
+               # Create deployments.php: the list of existing values for 
variable '$WIKIID' with their associated deployed versions
+               $deploymentsFile = <<<PHP
+<?php
+
+return array(
+       'atestdeploymentsfarm' => 'vstub',
+);
+
+PHP;
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
+               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
 
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
                $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php' ) );
@@ -328,8 +338,30 @@
         */
        function testDeploymedVersions3() {
 
+               # Create testdeploymentsfarmversions.php: the list of existing 
values for variable '$WIKIID' with their associated versions
+               $versionsFile = <<<PHP
+<?php
+
+return array(
+       'atestdeploymentsfarm' => 'vstub2',
+);
+
+PHP;
+
+               # Create deployments.php: the list of existing values for 
variable '$WIKIID' with their associated deployed versions
+               $deploymentsFile = <<<PHP
+<?php
+
+return array(
+       'atestdeploymentsfarm' => 'vstub',
+);
+
+PHP;
+               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
+               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
+
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'maintenance/update.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'maintenance/update.php' )
                        );
                $farm->updateVersionAfterMaintenance();
 
@@ -352,8 +384,30 @@
         */
        function testDeploymedVersions4() {
 
+               # Create testdeploymentsfarmversions.php: the list of existing 
values for variable '$WIKIID' with their associated versions
+               $versionsFile = <<<PHP
+<?php
+
+return array(
+       'atestdeploymentsfarm' => 'vstub2',
+);
+
+PHP;
+
+               # Create deployments.php: the list of existing values for 
variable '$WIKIID' with their associated deployed versions
+               $deploymentsFile = <<<PHP
+<?php
+
+return array(
+       'atestdeploymentsfarm' => 'vstub2',
+);
+
+PHP;
+               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
+               file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
+
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
-                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, 'index.php'
+                                          self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
                $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php' ) );
@@ -388,8 +442,12 @@
         */
        static function tearDownAfterClass() {
 
-               unlink( dirname( __FILE__ ) . '/data/config/deployments.php' );
-               unlink( dirname( __FILE__ ) . 
'/data/config/testdeploymentsfarmversions.php' );
+               if( is_file( dirname( __FILE__ ) . 
'/data/config/deployments.php' ) ) {
+                       unlink( dirname( __FILE__ ) . 
'/data/config/deployments.php' );
+               }
+               if( is_file( dirname( __FILE__ ) . 
'/data/config/testdeploymentsfarmversions.php' ) ) {
+                       unlink( dirname( __FILE__ ) . 
'/data/config/testdeploymentsfarmversions.php' );
+               }
 
                parent::tearDownAfterClass();
        }
diff --git a/tests/phpunit/data/config/varwikiversions.php 
b/tests/phpunit/data/config/varwikiversions.php
new file mode 100644
index 0000000..d257c72
--- /dev/null
+++ b/tests/phpunit/data/config/varwikiversions.php
@@ -0,0 +1,5 @@
+<?php
+
+return array(
+       'a' => 'vstub',
+);
diff --git a/tests/phpunit/data/config/versions.php 
b/tests/phpunit/data/config/versions.php
new file mode 100644
index 0000000..7adad22
--- /dev/null
+++ b/tests/phpunit/data/config/versions.php
@@ -0,0 +1,5 @@
+<?php
+
+return array(
+       'atestfarm' => 'vstub',
+);
diff --git a/tests/phpunit/data/mediawiki/vstub/maintenance/showJobs.php 
b/tests/phpunit/data/mediawiki/vstub/maintenance/showJobs.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/tests/phpunit/data/mediawiki/vstub/maintenance/showJobs.php
@@ -0,0 +1 @@
+<?php
diff --git a/tests/phpunit/data/mediawiki/vstub2/maintenance/showJobs.php 
b/tests/phpunit/data/mediawiki/vstub2/maintenance/showJobs.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/tests/phpunit/data/mediawiki/vstub2/maintenance/showJobs.php
@@ -0,0 +1 @@
+<?php

-- 
To view, visit https://gerrit.wikimedia.org/r/312968
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55a468292bb37b4fc89934f1b6f32e4139581f7e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiFarm
Gerrit-Branch: master
Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to