jenkins-bot has submitted this change and it was merged.

Change subject: Method to override configuration with data
......................................................................


Method to override configuration with data

Change-Id: Ieba9ac3337365c31e2c1937c265623e9f9a4d03b
---
M Core/Configuration.php
M Tests/ConfigurationTest.php
2 files changed, 27 insertions(+), 0 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Core/Configuration.php b/Core/Configuration.php
index 41e4fe9..6b6c18b 100644
--- a/Core/Configuration.php
+++ b/Core/Configuration.php
@@ -111,6 +111,18 @@
        }
 
        /**
+        * Override configuration with an array of data
+        *
+        * This should only be used in tests--note that these overrides take
+        * precedence over every configuration file.
+        *
+        * @param $data array
+        */
+       public function override( $data ) {
+               static::treeMerge( $this->options, $data );
+       }
+
+       /**
         * Loads a configuration file from the cache if it is still valid (ie: 
source files have not
         * changed)
         *
diff --git a/Tests/ConfigurationTest.php b/Tests/ConfigurationTest.php
index 09c65dd..bf0a9c8 100644
--- a/Tests/ConfigurationTest.php
+++ b/Tests/ConfigurationTest.php
@@ -17,5 +17,20 @@
         */
        public function testTreeMergeDissimilarTypes() {
                $this->setConfig( 'aview', __DIR__ . '/data/dissimilar.yaml' );
+               // expectedException above
+       }
+
+       public function testOverride() {
+               $config = $this->setConfig();
+
+               $this->assertEquals( 'SmashPig', $config->val( 
'logging/root-context' ),
+                       'Default config was as expected.' );
+               $config->override( array(
+                       'logging' => array(
+                               'root-context' => 'FOO',
+                       ),
+               ) );
+               $this->assertEquals( 'FOO', $config->val( 
'logging/root-context' ),
+                       'Config was overridden.' );
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieba9ac3337365c31e2c1937c265623e9f9a4d03b
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to