Permalink
Browse files

Add unit tests for commands

  • Loading branch information...
1 parent fb8e5d1 commit 23ed53ebd76e05c73c659d76fb495dca08c9b640 @stephpy committed Dec 8, 2012
@@ -39,18 +39,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \InvalidArgumentException('Limit defined should be biggest than 0 ...');
}
- $container = $this->getContainer();
-
- $results = $container->get('spy_timeline.action_manager')
- ->findActionsWithStatusWantedPublished($limit);
+ $container = $this->getContainer();
+ $actionManager = $container->get('spy_timeline.action_manager');
+ $results = $actionManager->findActionsWithStatusWantedPublished($limit);
$output->writeln(sprintf('<info>There is %s action(s) to deploy</info>', count($results)));
$deployer = $container->get('spy_timeline.spread.deployer');
foreach ($results as $action) {
try {
- $deployer->deploy($action);
+ $deployer->deploy($action, $actionManager);
$output->writeln(sprintf('<comment>Deploy action %s</comment>', $action->getId()));
} catch (\Exception $e) {
$message = sprintf('[TIMELINE] Error during deploy action %s', $action->getId());
@@ -0,0 +1,96 @@
+<?php
+
+namespace Spy\TimelineBundle\Tests\Units\Command;
+
+require_once __DIR__."/../../../vendor/autoload.php";
+
+use atoum\AtoumBundle\Test\Units\Test;
+use Spy\TimelineBundle\Command\DeployActionCommand as TestedCommand;
+use Symfony\Component\Console\Tester\CommandTester;
+use Symfony\Component\Console\Application;
+
+class DeployActionCommand extends Test
+{
+ public function testNoTimeline()
+ {
+ $this->mockClass('Symfony\Component\DependencyInjection\ContainerInterface', '\Mock');
+ $this->mockClass('Spy\TimelineBundle\Driver\ActionManagerInterface', '\Mock');
+ $this->mockGenerator()->orphanize('__construct');
+ $this->mockClass('Spy\TimelineBundle\Spread\Deployer', '\Mock');
+
+ $actionManager = new \Mock\ActionManagerInterface();
+ $deployer = new \Mock\Deployer();
+
+ $actionManager->getMockController()->findActionsWithStatusWantedPublished = array();
+
+ $container = new \Mock\ContainerInterface();
+ $container->getMockController()->get = function($v) use ($actionManager, $deployer) {
+ if ($v == 'spy_timeline.action_manager') {
+ return $actionManager;
+ } elseif ($v == 'spy_timeline.spread.deployer') {
+ return $deployer;
+ }
+ };
+
+ $command = new TestedCommand();
+ $command->setContainer($container);
+
+ $application = new Application();
+ $application->add($command);
+
+ $command = $application->find('spy_timeline:deploy');
+
+ $commandTester = new CommandTester($command);
+ $commandTester->execute(array('command' => $command->getName()), array());
+
+ $this->mock($actionManager)
+ ->call('findActionsWithStatusWantedPublished')
+ ->once();
+
+ $this->string($commandTester->getDisplay())
+ ->isEqualTo('There is 0 action(s) to deploy'.chr(10).'Done'.chr(10));
+ }
+
+ public function testOneTimeline()
+ {
+ $this->mockClass('Symfony\Component\DependencyInjection\ContainerInterface', '\Mock');
+ $this->mockClass('Spy\TimelineBundle\Driver\ActionManagerInterface', '\Mock');
+ $this->mockClass('Spy\TimelineBundle\Model\ActionInterface', '\Mock');
+ $this->mockGenerator()->orphanize('__construct');
+ $this->mockClass('Spy\TimelineBundle\Spread\Deployer', '\Mock');
+
+ $action = new \Mock\ActionInterface();
+ $actionManager = new \Mock\ActionManagerInterface();
+ $deployer = new \Mock\Deployer();
+
+ $action->getMockController()->getId = 1;
+ $actionManager->getMockController()->findActionsWithStatusWantedPublished = array($action);
+
+ $container = new \Mock\ContainerInterface();
+ $container->getMockController()->get = function($v) use ($actionManager, $deployer) {
+ if ($v == 'spy_timeline.action_manager') {
+ return $actionManager;
+ } elseif ($v == 'spy_timeline.spread.deployer') {
+ return $deployer;
+ }
+ };
+
+ $command = new TestedCommand();
+ $command->setContainer($container);
+
+ $application = new Application();
+ $application->add($command);
+
+ $command = $application->find('spy_timeline:deploy');
+
+ $commandTester = new CommandTester($command);
+ $commandTester->execute(array('command' => $command->getName()), array());
+
+ $this->mock($actionManager)
+ ->call('findActionsWithStatusWantedPublished')
+ ->once();
+
+ $this->string($commandTester->getDisplay())
+ ->isEqualTo('There is 1 action(s) to deploy'.chr(10).'Deploy action 1'.chr(10).'Done'.chr(10));
+ }
+}
@@ -0,0 +1,56 @@
+<?php
+
+namespace Spy\TimelineBundle\Tests\Units\Command;
+
+require_once __DIR__."/../../../vendor/autoload.php";
+
+use atoum\AtoumBundle\Test\Units\Test;
+use Spy\TimelineBundle\Command\SpreadListCommand as TestedCommand;
+use Symfony\Component\Console\Tester\CommandTester;
+use Symfony\Component\Console\Application;
+
+class SpreadListCommand extends Test
+{
+ public function testExecute()
+ {
+ $this->mockClass('Symfony\Component\DependencyInjection\ContainerInterface', '\Mock');
+ $this->mockGenerator()->orphanize('__construct');
+ $this->mockClass('Spy\TimelineBundle\Spread\Deployer', '\Mock');
+
+ $deployer = new \Mock\Deployer();
+ $deployer->getMockController()->getSpreads = array();
+
+ $container = new \Mock\ContainerInterface();
+ $container->getMockController()->get = function($v) use ($deployer) {
+ if ($v == 'spy_timeline.spread.deployer') {
+ return $deployer;
+ }
+ };
+
+ $command = new TestedCommand();
+ $command->setContainer($container);
+
+ $application = new Application();
+ $application->add($command);
+
+ $command = $application->find('spy_timeline:spreads');
+
+ $commandTester = new CommandTester($command);
+ $commandTester->execute(array('command' => $command->getName()), array());
+
+ $this->string($commandTester->getDisplay())
+ ->isEqualTo('There is 0 timeline spread(s) defined'.chr(10));
+
+ // one spread
+ $this->mockClass('Spy\TimelineBundle\Spread\SpreadInterface', '\Mock');
+
+ $spread = new \Mock\SpreadInterface();
+ $deployer->getMockController()->getSpreads = array($spread);
+
+ $commandTester = new CommandTester($command);
+ $commandTester->execute(array('command' => $command->getName()), array());
+
+ $this->string($commandTester->getDisplay())
+ ->isEqualTo('There is 1 timeline spread(s) defined'.chr(10).'- Mock\SpreadInterface'.chr(10));
+ }
+}

0 comments on commit 23ed53e

Please sign in to comment.