Skip to content

Commit

Permalink
Exit Atoum with a non-zero in case of failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Jan 28, 2021
1 parent b6fa6ed commit aae2594
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
42 changes: 34 additions & 8 deletions .atoum.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,45 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

use Atoum\PraspelExtension\Manifest;
use mageekguy\atoum\observable;
use mageekguy\atoum\observer;
use mageekguy\atoum\runner;
use mageekguy\atoum\test;
use mageekguy\atoum\visibility;

if (getenv('TRAVIS_PHP_VERSION') === '7.0') {
$script
->php('php -n -ddate.timezone=Europe/Paris')
->noCodeCoverage()
;
} else {
$script->noCodeCoverageForNamespaces('Composer');
class WorkaroundForNonZeroExitCodeOnFailure implements observer
{
private $isLastObserver = false;

private $failed = false;

public function handleEvent($event, observable $observable)
{
if ($this->isLastObserver === false && $observable instanceof runner && $event === runner::runStart) {
$observable->removeObserver($this)->addObserver($this);
$this->isLastObserver = true;
}
if (class_exists(test::class, false) && in_array($event, [test::fail, test::error, test::exception, test::runtimeException], true)) {
$this->failed = true;
}
if ($observable instanceof runner && $event === runner::runStop) {
if ($this->failed) {
throw new RuntimeException('Atoum failed!', 1);
}
}
}
}

/**
* @var mageekguy\atoum\configurator $script
* @var mageekguy\atoum\runner $runner
*/
$script->noCodeCoverageForNamespaces('Composer');

$script->addTestsFromDirectory(__DIR__ . '/tests/units');
$runner
->addExtension(new \Atoum\PraspelExtension\Manifest())
->addExtension(new Manifest())
->addExtension(new visibility\extension($script))
->addObserver(new WorkaroundForNonZeroExitCodeOnFailure())
;
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.2'
run: composer run cs-check -- --using-cache=no --no-interaction
- name: Run Atoum
run: php ./vendor/atoum/atoum/scripts/coverage.php --format xml --output clover.xml
run: php ./vendor/atoum/atoum/scripts/coverage.php --format xml --output clover.xml --force-terminal
- name: Install Composer dependencies (excluding dev)
run: composer install --prefer-source --optimize-autoloader --ansi --no-interaction --no-dev
- name: Install Box
Expand Down

0 comments on commit aae2594

Please sign in to comment.