Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/333801 )
Change subject: Override configuration with specific instances ...................................................................... Override configuration with specific instances Homebrew dependency injection is nearly complete. Last thing we'd need would be a way to specify a runnable to return instances for nodes. This is mostly just useful for test cases, where you want to create a mock on the fly and configure some return values. Should let us get rid of the silly mock types in the Amazon SDK fork. Change-Id: I6445c01429a337482d52399c5dafb2fd32c50717 --- M Core/Configuration.php M Tests/ConfigurationTest.php 2 files changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig refs/changes/01/333801/1 diff --git a/Core/Configuration.php b/Core/Configuration.php index 7c9ec83..095daec 100644 --- a/Core/Configuration.php +++ b/Core/Configuration.php @@ -180,6 +180,18 @@ } /** + * For testing: provide a specific instance of an object to fulfil requests + * for a specific node. Helpful when using test library mocks that you can't + * declaratively configure with constructor parameters. + * + * @param $node string + * @param $object object + */ + public function overrideObjectInstance( $node, $object ) { + $this->objects[$node] = $object; + } + + /** * Obtain a value from the configuration. If the key does not exist this will throw an * exception. * diff --git a/Tests/ConfigurationTest.php b/Tests/ConfigurationTest.php index 1044a2e..dc857d0 100644 --- a/Tests/ConfigurationTest.php +++ b/Tests/ConfigurationTest.php @@ -1,6 +1,9 @@ <?php namespace SmashPig\Tests; +use SmashPig\Core\Logging\LogStreams\ConsoleLogStream; +use SmashPig\Core\Logging\LogStreams\SyslogLogStream; + /** */ class ConfigurationTest extends BaseSmashPigUnitTestCase { @@ -52,4 +55,26 @@ $this->assertEquals( $expected, $config->val( 'endpoints/listener' ), 'Deep merge went as hoped' ); } + + public function testOverrideObjectInstance() { + $config = $this->setConfig(); + + $this->assertInstanceOf( + SyslogLogStream::class, + $config->object( 'logging/log-streams/syslog' ), + 'Default config was not as expected.' + ); + + $overrideInstance = new ConsoleLogStream(); + $config->overrideObjectInstance( + 'logging/log-streams/syslog', + $overrideInstance + ); + $this->assertEquals( + spl_object_hash( $overrideInstance ), + spl_object_hash( $config->object( 'logging/log-streams/syslog' ) ), + 'Sorcery fizzled out. Do you have enough mana?' + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/333801 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6445c01429a337482d52399c5dafb2fd32c50717 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits