From bad0737df19c90ab846202e2b7400aa404f89135 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Fri, 6 Dec 2013 12:52:47 +0000 Subject: [PATCH] add tests for Plugin Executor --- Tests/PHPCI/Plugin/Util/ExecutorTest.php | 90 ++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Tests/PHPCI/Plugin/Util/ExecutorTest.php diff --git a/Tests/PHPCI/Plugin/Util/ExecutorTest.php b/Tests/PHPCI/Plugin/Util/ExecutorTest.php new file mode 100644 index 00000000..bf717265 --- /dev/null +++ b/Tests/PHPCI/Plugin/Util/ExecutorTest.php @@ -0,0 +1,90 @@ +mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger'); + $this->mockFactory = $this->prophesize('\PHPCI\Plugin\Util\Factory'); + $this->testedExecutor = new Executor($this->mockFactory->reveal(), $this->mockBuildLogger->reveal()); + } + + public function testExecutePlugin_AssumesPHPCINamespaceIfNoneGiven() + { + $options = array(); + $pluginName = 'PhpUnit'; + $pluginNamespace = 'PHPCI\\Plugin\\'; + + $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options) + ->shouldBeCalledTimes(1) + ->willReturn($this->prophesize('PHPCI\Plugin')->reveal()); + + $this->testedExecutor->executePlugin($pluginName, $options); + } + + public function testExecutePlugin_KeepsCalledNameSpace() + { + $options = array(); + $pluginName = 'ExamplePluginFull'; + $pluginNamespace = '\\PHPCI\\Plugin\\Tests\\Util\\'; + + $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options) + ->shouldBeCalledTimes(1) + ->willReturn($this->prophesize('PHPCI\Plugin')->reveal()); + + $this->testedExecutor->executePlugin($pluginNamespace . $pluginName, $options); + } + + public function testExecutePlugin_CallsExecuteOnFactoryBuildPlugin() + { + $options = array(); + $pluginName = 'PhpUnit'; + $pluginNamespace = 'PHPCI\\Plugin\\'; + + $mockPlugin = $this->prophesize('PHPCI\Plugin'); + $mockPlugin->execute()->shouldBeCalledTimes(1); + + $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options) + ->shouldBeCalledTimes(1) + ->willReturn($mockPlugin->reveal()); + + $this->testedExecutor->executePlugin($pluginName, $options); + } + + public function testExecutePlugin_ReturnsPluginSuccess() + { + $options = array(); + $pluginName = 'PhpUnit'; + $pluginNamespace = 'PHPCI\\Plugin\\'; + + $expectedReturnValue = true; + + $mockPlugin = $this->prophesize('PHPCI\Plugin'); + $mockPlugin->execute()->willReturn($expectedReturnValue); + + $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)->willReturn($mockPlugin->reveal()); + + $returnValue = $this->testedExecutor->executePlugin($pluginName, $options); + + $this->assertEquals($expectedReturnValue, $returnValue); + } + +} + \ No newline at end of file