2013-12-06 13:52:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PHPCI\Plugin\Tests\Util;
|
|
|
|
|
|
|
|
require_once __DIR__ . "/ExamplePlugins.php";
|
|
|
|
|
|
|
|
use PHPCI\Plugin\Util\Executor;
|
2013-12-06 14:07:48 +01:00
|
|
|
use Prophecy\Argument;
|
2013-12-06 13:52:47 +01:00
|
|
|
use Prophecy\PhpUnit\ProphecyTestCase;
|
|
|
|
|
|
|
|
class ExecutorTest extends ProphecyTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Executor
|
|
|
|
*/
|
|
|
|
protected $testedExecutor;
|
|
|
|
|
|
|
|
protected $mockBuildLogger;
|
|
|
|
|
|
|
|
protected $mockFactory;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2013-12-13 17:07:11 +01:00
|
|
|
$this->mockBuildLogger = $this->prophesize('\PHPCI\Logging\BuildLogger');
|
2013-12-06 13:52:47 +01:00
|
|
|
$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';
|
|
|
|
|
|
|
|
$mockPlugin = $this->prophesize('PHPCI\Plugin');
|
|
|
|
$mockPlugin->execute()->shouldBeCalledTimes(1);
|
|
|
|
|
2013-12-06 14:07:48 +01:00
|
|
|
$this->mockFactory->buildPlugin(Argument::any(), Argument::any())->willReturn($mockPlugin->reveal());
|
2013-12-06 13:52:47 +01:00
|
|
|
|
|
|
|
$this->testedExecutor->executePlugin($pluginName, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecutePlugin_ReturnsPluginSuccess()
|
|
|
|
{
|
|
|
|
$options = array();
|
|
|
|
$pluginName = 'PhpUnit';
|
|
|
|
|
|
|
|
$expectedReturnValue = true;
|
|
|
|
|
|
|
|
$mockPlugin = $this->prophesize('PHPCI\Plugin');
|
|
|
|
$mockPlugin->execute()->willReturn($expectedReturnValue);
|
|
|
|
|
2013-12-06 14:07:48 +01:00
|
|
|
$this->mockFactory->buildPlugin(Argument::any(), Argument::any())->willReturn($mockPlugin->reveal());
|
2013-12-06 13:52:47 +01:00
|
|
|
|
|
|
|
$returnValue = $this->testedExecutor->executePlugin($pluginName, $options);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedReturnValue, $returnValue);
|
|
|
|
}
|
|
|
|
|
2013-12-06 14:04:27 +01:00
|
|
|
public function testExecutePlugin_LogsFailureForNonExistentClasses()
|
|
|
|
{
|
|
|
|
$options = array();
|
|
|
|
$pluginName = 'DOESNTEXIST';
|
|
|
|
|
|
|
|
$this->mockBuildLogger->logFailure('Plugin does not exist: ' . $pluginName)->shouldBeCalledTimes(1);
|
|
|
|
|
|
|
|
$this->testedExecutor->executePlugin($pluginName, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecutePlugin_LogsFailureWhenExceptionsAreThrownByPlugin()
|
|
|
|
{
|
|
|
|
$options = array();
|
|
|
|
$pluginName = 'PhpUnit';
|
|
|
|
|
|
|
|
$expectedException = new \RuntimeException("Generic Error");
|
|
|
|
|
|
|
|
$mockPlugin = $this->prophesize('PHPCI\Plugin');
|
|
|
|
$mockPlugin->execute()->willThrow($expectedException);
|
|
|
|
|
2013-12-06 14:07:48 +01:00
|
|
|
$this->mockFactory->buildPlugin(Argument::any(), Argument::any())->willReturn($mockPlugin->reveal());
|
2013-12-06 14:04:27 +01:00
|
|
|
|
|
|
|
$this->mockBuildLogger->logFailure('EXCEPTION: ' . $expectedException->getMessage(), $expectedException)
|
|
|
|
->shouldBeCalledTimes(1);
|
|
|
|
|
|
|
|
$this->testedExecutor->executePlugin($pluginName, $options);
|
|
|
|
}
|
|
|
|
|
2013-12-06 14:14:19 +01:00
|
|
|
public function testExecutePlugins_CallsEachPluginForStage()
|
|
|
|
{
|
|
|
|
$phpUnitPluginOptions = array();
|
|
|
|
$behatPluginOptions = array();
|
|
|
|
|
|
|
|
$config = array(
|
|
|
|
'stageOne' => array(
|
|
|
|
'PhpUnit' => $phpUnitPluginOptions,
|
|
|
|
'Behat' => $behatPluginOptions,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginNamespace = 'PHPCI\\Plugin\\';
|
|
|
|
|
|
|
|
$mockPhpUnitPlugin = $this->prophesize('PHPCI\Plugin');
|
|
|
|
$mockPhpUnitPlugin->execute()->shouldBeCalledTimes(1)->willReturn(true);
|
|
|
|
|
|
|
|
$this->mockFactory->buildPlugin($pluginNamespace . 'PhpUnit', $phpUnitPluginOptions)
|
|
|
|
->willReturn($mockPhpUnitPlugin->reveal());
|
|
|
|
|
|
|
|
|
|
|
|
$mockBehatPlugin = $this->prophesize('PHPCI\Plugin');
|
|
|
|
$mockBehatPlugin->execute()->shouldBeCalledTimes(1)->willReturn(true);
|
|
|
|
|
|
|
|
$this->mockFactory->buildPlugin($pluginNamespace . 'Behat', $behatPluginOptions)
|
|
|
|
->willReturn($mockBehatPlugin->reveal());
|
|
|
|
|
|
|
|
|
|
|
|
$this->testedExecutor->executePlugins($config, 'stageOne');
|
|
|
|
}
|
|
|
|
|
2013-12-06 13:52:47 +01:00
|
|
|
}
|
|
|
|
|