jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/355440 )
Change subject: test: factor out wgConf loading ...................................................................... test: factor out wgConf loading Several tests attempts to load $wgConf from InitialiseSettings.php. Factor out common code to WgConfTestCase::loadWgConf() Remove calls to restoreGlobals() which are no more needed. This make it rather trivial to add tests for a given setting. Change-Id: I41e797745a2ba3c24a043e9ee93ac8f33946388c --- M tests/WgConfTestCase.php M tests/cirrusTest.php M tests/loggingTest.php 3 files changed, 40 insertions(+), 53 deletions(-) Approvals: Krinkle: Looks good to me, approved Hashar: Looks good to me, but someone else must approve EBernhardson: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/tests/WgConfTestCase.php b/tests/WgConfTestCase.php index 03a45d1..c5e6b14 100644 --- a/tests/WgConfTestCase.php +++ b/tests/WgConfTestCase.php @@ -8,6 +8,8 @@ * @file */ +require_once __DIR__ . '/SiteConfiguration.php'; + class WgConfTestCase extends PHPUnit_Framework_TestCase { protected $globals = array(); @@ -58,4 +60,40 @@ } } + /** + * Load $wgConf from InitialiseSettings.php + * + * Example usage: + * + * $wgLogoHD = $this->loadWgConf( 'production' )->settings['wgLogoHD']; + * + * @param string $wmfRealm Realm to use for example: 'labs' or 'production' + * @return SiteConfiguration + */ + final protected function loadWgConf( $wmfRealm ) { + // Variables required for wgConf.php + $wmfConfigDir = __DIR__ . "/../wmf-config"; + + require "{$wmfConfigDir}/wgConf.php"; + + // InitialiseSettings.php explicitly declares these as global, so we must too + $this->setGlobals( array( + 'wmfUdp2logDest' => 'localhost', + 'wmfDatacenter' => 'unittest', + 'wmfMasterDatacenter' => 'unittest', + 'wmfRealm' => $wmfRealm, + 'wmfConfigDir' => $wmfConfigDir, + 'wgConf' => $wgConf, + ) ); + + require __DIR__ . '/TestServices.php'; + require "{$wmfConfigDir}/InitialiseSettings.php"; + + $ret = $wgConf; + // Make sure globals are restored, else they will be serialized on each + // test run which slow the test run dramatically. + $this->restoreGlobals(); + return $ret; + } + } diff --git a/tests/cirrusTest.php b/tests/cirrusTest.php index 4c8265d..65c4f13 100644 --- a/tests/cirrusTest.php +++ b/tests/cirrusTest.php @@ -76,28 +76,6 @@ } } - private function loadWgConf( $wmfRealm ) { - // Variables required for wgConf.php - $wmfConfigDir = __DIR__ . "/../wmf-config"; - - require "{$wmfConfigDir}/wgConf.php"; - - // InitialiseSettings.php explicitly declares these as global, so we must too - $this->setGlobals( array( - 'wmfUdp2logDest' => 'localhost', - 'wmfDatacenter' => 'unittest', - 'wmfMasterDatacenter' => 'unittest', - 'wmfRealm' => $wmfRealm, - 'wmfConfigDir' => $wmfConfigDir, - 'wgConf' => $wgConf, - ) ); - - require __DIR__ . '/TestServices.php'; - require "{$wmfConfigDir}/InitialiseSettings.php"; - - return $wgConf; - } - private function loadCirrusConfig( $wmfRealm, $wgDBname, $dbSuffix ) { $wmfConfigDir = __DIR__ . "/../wmf-config"; require __DIR__ . '/../private/PrivateSettings.php.example'; @@ -148,7 +126,6 @@ require "{$wmfConfigDir}/CirrusSearch-common.php"; $ret = compact( array_keys( get_defined_vars() ) ); - $this->restoreGlobals(); return $ret; } @@ -227,7 +204,6 @@ } } - $this->restoreGlobals(); return $tests; } diff --git a/tests/loggingTest.php b/tests/loggingTest.php index 6e7e701..146d505 100644 --- a/tests/loggingTest.php +++ b/tests/loggingTest.php @@ -84,25 +84,12 @@ } public function provideAvroSchemas() { - $wgConf = new stdClass; - $wmfConfigDir = __DIR__ . '/../wmf-config'; - - $this->setGlobals( array( - 'wmfUdp2logDest' => 'localhost', - 'wmfDatacenter' => 'unittest', - 'wmfRealm' => 'production', - 'wmfConfigDir' => $wmfConfigDir, - 'wgConf' => $wgConf, - ) ); - - require __DIR__ . "/TestServices.php"; - require "{$wmfConfigDir}/InitialiseSettings.php"; + $wgConf = $this->loadWgConf( 'production' ); $tests = array(); foreach ( $wgConf->settings['wmgMonologAvroSchemas']['default'] as $name => $schemaConfig ) { $tests[$name] = array( $schemaConfig ); } - $this->restoreGlobals(); return $tests; } @@ -117,28 +104,14 @@ } public function provideConfiguredChannels() { - // InitializeSettings.php explicitly declares these as global, so we need - // to as well. - $this->setGlobals( array( - 'wmfUdp2logDest' => 'localhost', - 'wmfDatacenter' => 'test', - 'wmfConfigDir' => __DIR__ . '/../wmf-config', - ) ); - global $wgConf; foreach ( array( 'production', 'labs' ) as $realm ) { - $this->setGlobals( array( - 'wgConf' => new stdClass(), - 'wmfRealm' => $realm, - ) ); - include __DIR__ . '/../wmf-config/InitialiseSettings.php'; + $wgConf = $this->loadWgConf( $realm ); foreach ( $wgConf->settings['wmgMonologChannels'] as $wiki => $channels ) { foreach ( $channels as $name => $config ) { $tests["\$wmgMonologChannels['$wiki']['$name']"] = array( $config ); } } } - - $this->restoreGlobals(); return $tests; } -- To view, visit https://gerrit.wikimedia.org/r/355440 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I41e797745a2ba3c24a043e9ee93ac8f33946388c Gerrit-PatchSet: 2 Gerrit-Project: operations/mediawiki-config Gerrit-Branch: master Gerrit-Owner: Hashar <has...@free.fr> Gerrit-Reviewer: DCausse <dcau...@wikimedia.org> Gerrit-Reviewer: Dereckson <dereck...@espace-win.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits