Skip to content

Commit

Permalink
Merge pull request #98 from atoum/exit-code
Browse files Browse the repository at this point in the history
Fix atoum command exit codes
  • Loading branch information
jubianchi committed May 16, 2016
2 parents dd9c3d5 + efa0841 commit 47b5a60
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# `dev-master`

## Bugfix

* [#98](https://github.com/atoum/AtoumBundle/pull/98) Fix atoum command exit codes ([@jubianchi])

1.4.0
=====

Expand Down Expand Up @@ -37,3 +43,5 @@

* Move the bundle to atoum vendor namespace
* Add ControllerTest class

[@jubianchi]: https://github.com/jubianchi
22 changes: 21 additions & 1 deletion Command/AtoumCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
$reportCli->addWriter($writerCli);
}

$runner->run($this->getAtoumArguments());
try {
$score = $runner->run($this->getAtoumArguments())->getRunner()->getScore();

$isSuccess = $score->getFailNumber() <= 0 && $score->getErrorNumber() <= 0 && $score->getExceptionNumber() <= 0;

if ($runner->shouldFailIfVoidMethods() && $score->getVoidMethodNumber() > 0)
{
$isSuccess = false;
}

if ($runner->shouldFailIfSkippedMethods() && $score->getSkippedMethodNumber() > 0)
{
$isSuccess = false;
}

return $isSuccess ? 0 : 1;
} catch (\Exception $exception) {
$this->getApplication()->renderException($exception, $output);

return 2;
}
}

/**
Expand Down
11 changes: 5 additions & 6 deletions tests/units/Test/Units/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ public function testCreateCommandTester()
$this
->given(
$command = new \mock\Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand($commandName = uniqid()),
$command->getMockController()->run = $status = uniqid()
)
->given(
$kernel = new \mock\Symfony\Component\HttpKernel\KernelInterface(),
$application = new \mock\Symfony\Bundle\FrameworkBundle\Console\Application($kernel)
)
->given(
$container = new \mock\Symfony\Component\DependencyInjection\ContainerInterface(),
$application = new \mock\Symfony\Bundle\FrameworkBundle\Console\Application($kernel),
$object = new \mock\atoum\AtoumBundle\Test\Units\CommandTestCase(),
$command->getMockController()->run = $status = uniqid(),
$kernel->getMockController()->getBundles = array(),
$kernel->getMockController()->getContainer = $container,
$object->getMockController()->getKernel = $kernel
)
->if($commandTester = $object->createCommandTester($command))
Expand Down

0 comments on commit 47b5a60

Please sign in to comment.