Seb35 has uploaded a new change for review.

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

Change subject: Maintenance: better sort methods, improve coverage, etc.
......................................................................

Maintenance: better sort methods, improve coverage, etc.

* Sort methods in main class with more important methods on top, helpers on down
* Moved scripts/ to bin/
* Minor schema update
* Converted a raw executable Yaml.php to a function
* Reduced cyclomatic complexity of method extractSkinsAndExtensions
* Added more tests mainly for __construct

I ran PHPUnit with code coverage activated:
* 29.41% of functions/methods covered
* 20.30% of lines (30.90% in main file)

Change-Id: Ib7e586531dc19117bb7f98ee00a01b45f71fbc20
---
R bin/mwscript.php
R bin/validate-schema.php
M docs/farms-schema.json
M src/MediaWikiFarm.php
M src/Yaml.php
M src/main.php
M tests/phpunit/MediaWikiFarmMonoversionInstallationTest.php
M tests/phpunit/MediaWikiFarmMultiversionInstallationTest.php
8 files changed, 381 insertions(+), 133 deletions(-)


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

diff --git a/scripts/mwscript.php b/bin/mwscript.php
similarity index 95%
rename from scripts/mwscript.php
rename to bin/mwscript.php
index 43468e7..101311d 100644
--- a/scripts/mwscript.php
+++ b/bin/mwscript.php
@@ -154,7 +154,7 @@
 
 
 # Display parameters
-$mwfVersion = MediaWikiFarm::getInstance()->getVariable( '$VERSION' ) ? 
MediaWikiFarm::getInstance()->getVariable( '$VERSION' ) : 'current';
+$mwfVersion = $wgMediaWikiFarm->getVariable( '$VERSION' ) ? 
$wgMediaWikiFarm->getVariable( '$VERSION' ) : 'current';
 echo <<<PARAMS
 
 Wiki:    $mwfHost (wikiID: {$wgMediaWikiFarm->getVariable( '$WIKIID' )}; 
suffix: {$wgMediaWikiFarm->getVariable( '$SUFFIX' )})
@@ -181,4 +181,4 @@
 
 
 # Update version after maintenance/update.php (the only case where another 
version is given before execution)
-MediaWikiFarm::getInstance()->updateVersionAfterMaintenance();
+$wgMediaWikiFarm->updateVersionAfterMaintenance();
diff --git a/scripts/validate-schema.php b/bin/validate-schema.php
similarity index 100%
rename from scripts/validate-schema.php
rename to bin/validate-schema.php
diff --git a/docs/farms-schema.json b/docs/farms-schema.json
index c47e8c7..85529a7 100644
--- a/docs/farms-schema.json
+++ b/docs/farms-schema.json
@@ -64,7 +64,7 @@
                                                        "type": "string",
                                                        "description": "File 
containing an array where each key is a wikiID and each value is the 
corresponding MediaWiki version similarly to 'versions', but this file contains 
actual versions, before and after the 'maintenance/update.php' script is run."
                                                },
-                                               "nonexistant": {
+                                               "HTTP404": {
                                                        "type": "string",
                                                        "description": "PHP or 
HTML file displayed in case of a nonexistant wiki."
                                                },
diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php
index ed90165..ce42145 100644
--- a/src/MediaWikiFarm.php
+++ b/src/MediaWikiFarm.php
@@ -164,6 +164,7 @@
        }
        
        
+       
        /* 
         * Entry points in normal operation
         * -------------------------------- */
@@ -253,6 +254,12 @@
                
                return self::$self;
        }
+       
+       
+       
+       /*
+        * Functions of interest in normal operations
+        * ------------------------------------------ */
        
        /**
         * Check the existence of the wiki, given variables values and files 
listing existing wikis.
@@ -412,7 +419,7 @@
        }
        
        /**
-        * Return the file where is loaded the configuration.
+        * Return the file where must be loaded the configuration from.
         * 
         * This function is important to avoid the two parts of the extension 
(checking of
         * existence and loading of configuration) are located in the same 
directory in the
@@ -732,6 +739,19 @@
        }
        
        /**
+        * Computation of secondary variables.
+        * 
+        * These can reuse previously-computed variables: URL variables 
(lowercase), '$WIKIID', '$SUFFIX', '$VERSION', '$CODE'.
+        * 
+        * @throws InvalidArgumentException
+        * @return void
+        */
+       function setOtherVariables() {
+               
+               $this->setVariable( 'data' );
+       }
+       
+       /**
         * Update the version in the deployment file.
         * 
         * @param string $version The new version, should be the version found 
in the 'expected version' file.
@@ -753,19 +773,6 @@
                # Update the deployment file
                $deployments[$this->variables['$WIKIID']] = $version;
                $this->cacheFile( $deployments, 
$this->variables['$DEPLOYMENTS'], $this->configDir );
-       }
-       
-       /**
-        * Computation of secondary variables.
-        * 
-        * These can reuse previously-computed variables: URL variables 
(lowercase), '$WIKIID', '$SUFFIX', '$VERSION', '$CODE'.
-        * 
-        * @throws InvalidArgumentException
-        * @return void
-        */
-       function setOtherVariables() {
-               
-               $this->setVariable( 'data' );
        }
        
        /**
@@ -963,7 +970,7 @@
        }
        
        /**
-        * Extract from the general configuration skin and extension 
configuration
+        * Extract skin and extension configuration from the general 
configuration.
         * 
         * @return void
         */
@@ -974,23 +981,14 @@
                # Search for skin and extension activation
                $unsetPrefixes = array();
                foreach( $globals['general'] as $setting => $value ) {
-                       if( preg_match( '/^wgUseSkin(.+)$/', $setting, $matches 
) && $value === true ) {
+                       if( preg_match( '/^wgUse(Extension|Skin)(.+)$/', 
$setting, $matches ) && $value === true ) {
                                
-                               $skin = $matches[1];
-                               $loadingMechanism = 
$this->detectLoadingMechanism( 'skin', $skin );
+                               $type = strtolower( $matches[1] );
+                               $name = $matches[2];
+                               $loadingMechanism = 
$this->detectLoadingMechanism( $type, $name );
                                
-                               if( is_null( $loadingMechanism ) ) 
$unsetPrefixes[] = $skin;
-                               else $globals['skins'][$skin] = array( 
'_loading' => $loadingMechanism );
-                               
-                               unset( $globals['general'][$setting] );
-                       }
-                       elseif( preg_match( '/^wgUseExtension(.+)$/', $setting, 
$matches ) && $value === true ) {
-                               
-                               $extension = $matches[1];
-                               $loadingMechanism = 
$this->detectLoadingMechanism( 'extension', $extension );
-                               
-                               if( is_null( $loadingMechanism ) ) 
$unsetPrefixes[] = $extension;
-                               else $globals['extensions'][$extension] = 
array( '_loading' => $loadingMechanism );
+                               if( is_null( $loadingMechanism ) ) 
$unsetPrefixes[] = $name;
+                               else $globals[$type.'s'][$name] = array( 
'_loading' => $loadingMechanism );
                                
                                unset( $globals['general'][$setting] );
                        }
@@ -1036,19 +1034,6 @@
        }
        
        /**
-        * Helper function used in extractSkinsAndExtensions.
-        * 
-        * @mediawikifarm-const
-        * @mediawikifarm-idempotent
-        * @param string $a String to be regex-escaped.
-        * @return string Escaped string.
-        */
-       static function protectRegex( $a ) {
-               
-               return preg_quote( $a, '/' );
-       }
-       
-       /**
         * Detection of the loading mechanism of extensions and skins.
         * 
         * @mediawikifarm-const
@@ -1074,6 +1059,71 @@
                        return 'composer';
                
                return null;
+       }
+       
+       /**
+        * Set a wiki property and replace placeholders (property name version).
+        * 
+        * @param string $name Name of the property.
+        * @param bool This variable is mandatory.
+        * @throws MWFConfigurationException When the variable is mandatory and 
missing.
+        * @throws InvalidArgumentException
+        * @return void
+        */
+       function setVariable( $name, $mandatory = false ) {
+               
+               if( !array_key_exists( $name, $this->farmConfig ) ) {
+                       if( $mandatory ) throw new MWFConfigurationException( 
'Missing key \'$name\' in farm configuration.' );
+                       return;
+               }
+               
+               if( !is_string( $this->farmConfig[$name] ) )
+                       return;
+               
+               $this->variables['$'.strtoupper($name)] = 
$this->replaceVariables( $this->farmConfig[$name] );
+       }
+       
+       /**
+        * Replace variables in a string.
+        * 
+        * Constant function (do not write any object property).
+        * 
+        * @param string|string[] $value Value of the property.
+        * @throws InvalidArgumentException When argument type is incorrect.
+        * @return string|string[] Input where variables were replaced.
+        */
+       function replaceVariables( $value ) {
+               
+               if( is_string( $value ) )
+                       return str_replace( array_keys( $this->variables ), 
$this->variables, $value );
+               
+               elseif( is_array( $value ) ) {
+                       
+                       foreach( $value as &$subvalue ) {
+                               $subvalue = str_replace( array_keys( 
$this->variables ), $this->variables, $subvalue );
+                       }
+                       return $value;
+               }
+               
+               throw new InvalidArgumentException( 'Argument of 
MediaWikiFarm->replaceVariables() must be a string or an array.' );
+       }
+       
+       /**
+        * Add files for unit testing.
+        * 
+        * @mediawikifarm-const
+        * @mediawikifarm-idempotent
+        * @param string[] $files The test files.
+        * @return true
+        */
+       static function onUnitTestsList( array &$files ) {
+               
+               $dir = dirname( dirname( __FILE__ ) ) . '/tests/phpunit/';
+               
+               $files[] = $dir . 
'MediaWikiFarmMonoversionInstallationTest.php';
+               $files[] = $dir . 
'MediaWikiFarmMultiversionInstallationTest.php';
+               
+               return true;
        }
        
        
@@ -1138,8 +1188,10 @@
                        # This is only included here to avoid delays (~3ms 
without OPcache) during the loading using cached files or other formats
                        if( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) {
                                
-                               $array = require dirname( __FILE__ ) . '/' . 
'Yaml.php';
-                               if( $array === false )
+                               require_once dirname( __FILE__ ) . '/Yaml.php';
+                               
+                               $array = MediaWikiFarm_readYAML( $prefixedFile 
);
+                               if( is_null( $array ) )
                                        return false;
                        }
                }
@@ -1219,50 +1271,34 @@
        }
        
        /**
-        * Set a wiki property and replace placeholders (property name version).
+        * Guess if a given directory contains MediaWiki.
         * 
-        * @param string $name Name of the property.
-        * @param bool This variable is mandatory.
-        * @throws MWFConfigurationException When the variable is mandatory and 
missing.
-        * @throws InvalidArgumentException
-        * @return void
+        * This heuristic (presence of [dir]/includes/DefaultSettings.php) has 
no false negatives
+        * (every MediaWiki from 1.1 to (at least) 1.27 has such a file) and 
probably has a few, if
+        * any, false positives (another software which has the very same file).
+        * 
+        * @mediawikifarm-const
+        * @mediawikifarm-idempotent
+        * @param string $dir The base directory which could contain MediaWiki.
+        * @return bool The directory really contains MediaWiki.
         */
-       function setVariable( $name, $mandatory = false ) {
-               
-               if( !array_key_exists( $name, $this->farmConfig ) ) {
-                       if( $mandatory ) throw new MWFConfigurationException( 
'Missing key \'$name\' in farm configuration.' );
-                       return;
-               }
-               
-               if( !is_string( $this->farmConfig[$name] ) )
-                       return;
-               
-               $this->variables['$'.strtoupper($name)] = 
$this->replaceVariables( $this->farmConfig[$name] );
+       static function isMediaWiki( $dir ) {
+               return is_file( $dir . '/includes/DefaultSettings.php' );
        }
        
        /**
-        * Replace variables in a string.
+        * Helper function used in extractSkinsAndExtensions.
         * 
-        * Constant function (do not write any object property).
+        * Isolate this function is needed for compatibility with PHP 5.2.
         * 
-        * @param string|string[] $value Value of the property.
-        * @throws InvalidArgumentException When argument type is incorrect.
-        * @return string|string[] Input where variables were replaced.
+        * @mediawikifarm-const
+        * @mediawikifarm-idempotent
+        * @param string $a String to be regex-escaped.
+        * @return string Escaped string.
         */
-       function replaceVariables( $value ) {
+       static function protectRegex( $a ) {
                
-               if( is_string( $value ) )
-                       return str_replace( array_keys( $this->variables ), 
$this->variables, $value );
-               
-               elseif( is_array( $value ) ) {
-                       
-                       foreach( $value as &$subvalue ) {
-                               $subvalue = str_replace( array_keys( 
$this->variables ), $this->variables, $subvalue );
-                       }
-                       return $value;
-               }
-               
-               throw new InvalidArgumentException( 'Argument of 
MediaWikiFarm->replaceVariables() must be a string or an array.' );
+               return preg_quote( $a, '/' );
        }
        
        /**
@@ -1296,39 +1332,5 @@
                }
                
                return $out;
-       }
-       
-       /**
-        * Guess if a given directory contains MediaWiki.
-        * 
-        * This heuristic (presence of [dir]/includes/DefaultSettings.php) has 
no false negatives
-        * (every MediaWiki from 1.1 to (at least) 1.27 has such a file) and 
probably has a few, if
-        * any, false positives (another software which has the very same file).
-        * 
-        * @mediawikifarm-const
-        * @mediawikifarm-idempotent
-        * @param string $dir The base directory which could contain MediaWiki.
-        * @return bool The directory really contains MediaWiki.
-        */
-       static function isMediaWiki( $dir ) {
-               return is_file( $dir . '/includes/DefaultSettings.php' );
-       }
-       
-       /**
-        * Add files for unit testing.
-        * 
-        * @mediawikifarm-const
-        * @mediawikifarm-idempotent
-        * @param string[] $files The test files.
-        * @return true
-        */
-       static function onUnitTestsList( array &$files ) {
-               
-               $dir = dirname( dirname( __FILE__ ) ) . '/tests/phpunit/';
-               
-               $files[] = $dir . 
'MediaWikiFarmMonoversionInstallationTest.php';
-               $files[] = $dir . 
'MediaWikiFarmMultiversionInstallationTest.php';
-               
-               return true;
        }
 }
diff --git a/src/Yaml.php b/src/Yaml.php
index af4bb97..95bf64f 100644
--- a/src/Yaml.php
+++ b/src/Yaml.php
@@ -15,15 +15,29 @@
 if( is_file( dirname( __FILE__ ) . '/../vendor/autoload.php' ) && 
!class_exists( 'Symfony\Component\Yaml\Yaml' ) )
        include_once dirname( __FILE__ ) . '/../vendor/autoload.php';
 
-# If the class doesn’t exist, return an error
-if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) || !class_exists( 
'Symfony\Component\Yaml\Exception\ParseException' ) )
-       return false;
-
-# Return the array read from YAML or an error
-try {
-       return Symfony\Component\Yaml\Yaml::parse( @file_get_contents( 
$prefixedFile ) );
-}
-catch( Symfony\Component\Yaml\Exception\ParseException $e ) {
+/**
+ * Read a YAML file.
+ * 
+ * Isolate this function is needed for compatibility with PHP 5.2.
+ * 
+ * @param string $filename Name of the YAML file.
+ * @return array|string|int|bool|null Content of the YAML file or null in case 
of error.
+ */
+function MediaWikiFarm_readYAML( $filename ) {
        
-       return false;
+       # If the class or the file don’t exist, return an error
+       if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) || !class_exists( 
'Symfony\Component\Yaml\Exception\ParseException' ) ) {
+               return null;
+       }
+       if( !is_file( $filename ) ) {
+               return null;
+       }
+       
+       # Return the array read from YAML or an error
+       try {
+               return Symfony\Component\Yaml\Yaml::parse( file_get_contents( 
$filename ) );
+       }
+       catch( Symfony\Component\Yaml\Exception\ParseException $e ) {}
+       
+       return null;
 }
diff --git a/src/main.php b/src/main.php
index 5a993c7..2616444 100644
--- a/src/main.php
+++ b/src/main.php
@@ -33,14 +33,14 @@
  */
 
 # Load skins with the require_once mechanism
-foreach( MediaWikiFarm::getInstance()->getConfiguration( 'skins' ) as $skin => 
$value ) {
+foreach( $wgMediaWikiFarm->getConfiguration( 'skins' ) as $skin => $value ) {
        
        if( $value['_loading'] == 'require_once' )
                require_once "$IP/skins/$skin/$skin.php";
 }
 
 # Load skins with the wfLoadSkin mechanism
-MediaWikiFarm::getInstance()->loadSkinsConfig();
+$wgMediaWikiFarm->loadSkinsConfig();
 
 
 /*
@@ -48,20 +48,20 @@
  */
 
 # Load extensions with the require_once mechanism
-foreach( MediaWikiFarm::getInstance()->getConfiguration( 'extensions' ) as 
$extension => $value ) {
+foreach( $wgMediaWikiFarm->getConfiguration( 'extensions' ) as $extension => 
$value ) {
        
        if( $value['_loading'] == 'require_once' )
                require_once "$IP/extensions/$extension/$extension.php";
 }
 
 # Load extensions with the wfLoadExtension mechanism
-MediaWikiFarm::getInstance()->loadExtensionsConfig();
+$wgMediaWikiFarm->loadExtensionsConfig();
 
 
 /*
  * Executable configuration
  */
-foreach( MediaWikiFarm::getInstance()->getConfiguration( 'execFiles' ) as 
$execFile ) {
+foreach( $wgMediaWikiFarm->getConfiguration( 'execFiles' ) as $execFile ) {
        
        @include $execFile;
 }
diff --git a/tests/phpunit/MediaWikiFarmMonoversionInstallationTest.php 
b/tests/phpunit/MediaWikiFarmMonoversionInstallationTest.php
index 44b8979..545c50c 100644
--- a/tests/phpunit/MediaWikiFarmMonoversionInstallationTest.php
+++ b/tests/phpunit/MediaWikiFarmMonoversionInstallationTest.php
@@ -52,7 +52,98 @@
        function testFailedConstruction() {
                
                $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data';
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirBadTest, null, 
false );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Missing host name in constructor
+        */
+       function testFailedConstruction2() {
+               
+               $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 0, $wgMediaWikiFarmConfigDirBadTest 
);
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Invalid directory for the farm 
configuration
+        */
+       function testFailedConstruction3() {
+               
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', 0 );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Invalid directory for the farm 
configuration
+        */
+       function testFailedConstruction4() {
+               
+               $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data/config/farms.php';
                $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirBadTest );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Code directory must be null or a directory
+        */
+       function testFailedConstruction5() {
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirTest, 0 );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Code directory must be null or a directory
+        */
+       function testFailedConstruction6() {
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmConfigDirTest . '/farms.php' );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Cache directory must be false, null, or a 
directory
+        */
+       function testFailedConstruction7() {
+               
+               global $IP;
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $wgMediaWikiFarmCodeDirTest = dirname( $IP );
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmCodeDirTest, 0 );
+       }
+       
+       /**
+        * Test creation of cache directory.
+        */
+       function testCacheDirectoryCreation() {
+               
+               global $IP;
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $wgMediaWikiFarmCodeDirTest = dirname( $IP );
+               $wgMediaWikiFarmCacheDirTest = dirname( __FILE__ ) . 
'/data/cache';
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmCodeDirTest, $wgMediaWikiFarmCacheDirTest );
+               
+               $this->assertEquals( $wgMediaWikiFarmCacheDirTest . 
'/testfarm-monoversion', $farm->getCacheDir() );
+               $this->assertTrue( is_dir( $wgMediaWikiFarmCacheDirTest ) );
+               $this->assertTrue( is_dir( $wgMediaWikiFarmCacheDirTest . 
'/testfarm-monoversion' ) );
        }
        
        /**
@@ -176,4 +267,29 @@
                        ),
                        $this->farm->getVariables() );
        }*/
+       
+       /**
+        * Test onUnitTestsList hook
+        */
+       function testOnUnitTestsListHook() {    
+               
+               $array = array();
+               MediaWikiFarm::onUnitTestsList( $array );
+               $this->assertEquals(
+                       array(
+                               __FILE__,
+                               dirname( __FILE__ ) . 
'/MediaWikiFarmMultiversionInstallationTest.php',
+                       ),
+                       $array );
+       }
+       
+       /**
+        * Remove 'data/cache' cache directory.
+        */
+       protected function tearDown() {
+               
+               wfRecursiveRemoveDir( dirname( __FILE__ ) . '/data/cache' );
+               
+               parent::tearDown();
+       }
 }
diff --git a/tests/phpunit/MediaWikiFarmMultiversionInstallationTest.php 
b/tests/phpunit/MediaWikiFarmMultiversionInstallationTest.php
index fa9138d..2869b64 100644
--- a/tests/phpunit/MediaWikiFarmMultiversionInstallationTest.php
+++ b/tests/phpunit/MediaWikiFarmMultiversionInstallationTest.php
@@ -74,7 +74,98 @@
        function testFailedConstruction() {
                
                $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data';
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirBadTest, null, 
false );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Missing host name in constructor
+        */
+       function testFailedConstruction2() {
+               
+               $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 0, $wgMediaWikiFarmConfigDirBadTest 
);
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Invalid directory for the farm 
configuration
+        */
+       function testFailedConstruction3() {
+               
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', 0 );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Invalid directory for the farm 
configuration
+        */
+       function testFailedConstruction4() {
+               
+               $wgMediaWikiFarmConfigDirBadTest = dirname( __FILE__ ) . 
'/data/config/farms.php';
                $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirBadTest );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Code directory must be null or a directory
+        */
+       function testFailedConstruction5() {
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirTest, 0 );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Code directory must be null or a directory
+        */
+       function testFailedConstruction6() {
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmConfigDirTest . '/farms.php' );
+       }
+       
+       /**
+        * Test bad arguments in constructor.
+        * 
+        * @expectedException InvalidArgumentException
+        * @expectedExceptionMessage Cache directory must be false, null, or a 
directory
+        */
+       function testFailedConstruction7() {
+               
+               global $IP;
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $wgMediaWikiFarmCodeDirTest = dirname( $IP );
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmCodeDirTest, 0 );
+       }
+       
+       /**
+        * Test creation of cache directory.
+        */
+       function testCacheDirectoryCreation() {
+               
+               global $IP;
+               
+               $wgMediaWikiFarmConfigDirTest = dirname( __FILE__ ) . 
'/data/config';
+               $wgMediaWikiFarmCodeDirTest = dirname( $IP );
+               $wgMediaWikiFarmCacheDirTest = dirname( __FILE__ ) . 
'/data/cache';
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', $wgMediaWikiFarmConfigDirTest, 
$wgMediaWikiFarmCodeDirTest, $wgMediaWikiFarmCacheDirTest );
+               
+               $this->assertEquals( $wgMediaWikiFarmCacheDirTest . 
'/testfarm-multiversion', $farm->getCacheDir() );
+               $this->assertTrue( is_dir( $wgMediaWikiFarmCacheDirTest ) );
+               $this->assertTrue( is_dir( $wgMediaWikiFarmCacheDirTest . 
'/testfarm-multiversion' ) );
        }
        
        /**
@@ -201,7 +292,32 @@
        }
        
        /**
-        * Remove fake 'data/config/versions.php' config file.
+        * Test onUnitTestsList hook
+        */
+       function testOnUnitTestsListHook() {    
+               
+               $array = array();
+               MediaWikiFarm::onUnitTestsList( $array );
+               $this->assertEquals(
+                       array(
+                               dirname( __FILE__ ) . 
'/MediaWikiFarmMonoversionInstallationTest.php',
+                               __FILE__,
+                       ),
+                       $array );
+       }
+       
+       /**
+        * Remove 'data/cache' cache directory.
+        */
+       protected function tearDown() {
+               
+               wfRecursiveRemoveDir( dirname( __FILE__ ) . '/data/cache' );
+               
+               parent::tearDown();
+       }
+       
+       /**
+        * Remove 'data/config/versions.php' config file.
         */
        static function tearDownAfterClass() {
                

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7e586531dc19117bb7f98ee00a01b45f71fbc20
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