diff --git a/lib/plugins/sfDoctrinePlugin/test/bin/coverage.php b/lib/plugins/sfDoctrinePlugin/test/bin/coverage.php index f3f3b3321..616359482 100644 --- a/lib/plugins/sfDoctrinePlugin/test/bin/coverage.php +++ b/lib/plugins/sfDoctrinePlugin/test/bin/coverage.php @@ -32,4 +32,7 @@ $finder = sfFinder::type('file')->name('*.php')->prune('vendor')->prune('test')->prune('data'); $c->register($finder->in($c->base_dir)); -$c->run(); + +$allTestsSucceed = $c->run(); + +exit($allTestsSucceed ? 0 : 1); diff --git a/lib/vendor/lime/lime.php b/lib/vendor/lime/lime.php index 59a99de34..0def1faba 100644 --- a/lib/vendor/lime/lime.php +++ b/lib/vendor/lime/lime.php @@ -16,17 +16,25 @@ */ class lime_test { - const EPSILON = 0.0000000001; + public const EPSILON = 0.0000000001; protected $test_nb = 0; protected $output = null; protected $results = array(); protected $options = array(); - static protected $all_results = array(); + protected static $all_results = array(); + + private const STATE_PASS = 0; + private const STATE_FAIL = 1; + + private static $instanceCount = 0; + private static $finalState = self::STATE_PASS; public function __construct($plan = null, $options = array()) { + ++self::$instanceCount; + // for BC if (!is_array($options)) { @@ -130,31 +138,86 @@ static public function to_xml($results = null) public function __destruct() { - $plan = $this->results['stats']['plan']; - $passed = count($this->results['stats']['passed']); + $testSuiteState = $this->determineAndPrintStateOfTestSuite(); + + flush(); + + $this->keepTheWorstState($testSuiteState); + + $this->finalizeLastInstanceDestructorWithProcessExit(); + } + + private function determineAndPrintStateOfTestSuite(): int + { + $planState = $this->determineAndPrintStateOfPlan(); $failed = count($this->results['stats']['failed']); + + if ($failed) { + $passed = count($this->results['stats']['passed']); + + $this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed)); + + return self::STATE_FAIL; + } + + if (self::STATE_FAIL === $planState) { + return self::STATE_FAIL; + } + + $this->output->green_bar("# Looks like everything went fine."); + + return self::STATE_PASS; + } + + private function determineAndPrintStateOfPlan(): int + { + $plan = $this->results['stats']['plan']; $total = $this->results['stats']['total']; - is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); - if ($total > $plan) - { - $this->output->red_bar(sprintf("# Looks like you planned %d tests but ran %d extra.", $plan, $total - $plan)); + if (null === $plan) { + $plan = $total; + + $this->output->echoln(sprintf("1..%d", $plan)); } - elseif ($total < $plan) - { + + if ($total > $plan) { + $this->output->red_bar(sprintf("# Looks like you planned %d tests but ran %d extra.", $plan, $total - $plan)); + } elseif ($total < $plan) { $this->output->red_bar(sprintf("# Looks like you planned %d tests but only ran %d.", $plan, $total)); } - if ($failed) - { - $this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed)); + return $total === $plan ? self::STATE_PASS : self::STATE_FAIL; + } + + private function keepTheWorstState(int $state): void + { + if ($this->stateIsTheWorst($state)) { + self::$finalState = $state; } - else if ($total == $plan) - { - $this->output->green_bar("# Looks like everything went fine."); + } + + private function stateIsTheWorst(int $state): bool + { + return self::$finalState < $state; + } + + private function finalizeLastInstanceDestructorWithProcessExit(): void + { + --self::$instanceCount; + + if (0 === self::$instanceCount) { + exit($this->determineExitCodeFromState(self::$finalState)); } + } - flush(); + private function determineExitCodeFromState(int $state): int + { + switch ($state) { + case self::STATE_PASS: + return 0; + default: + return 1; + } } /** @@ -969,7 +1032,7 @@ function lime_shutdown() $delta = 0; if ($return > 0) { - $stats['status'] = $file_stats['errors'] ? 'errors' : 'dubious'; + $stats['status'] = $file_stats['failed'] ? 'not ok' : ($file_stats['errors'] ? 'errors' : 'dubious'); $stats['status_code'] = $return; } else diff --git a/test/bin/coverage.php b/test/bin/coverage.php index 409634821..c7bc90e3f 100644 --- a/test/bin/coverage.php +++ b/test/bin/coverage.php @@ -42,4 +42,7 @@ $finder = sfFinder::type('file')->name($name.'.class.php')->prune('vendor')->prune('test')->prune('data'); $c->register($finder->in($c->base_dir)); -$c->run(); + +$allTestsSucceed = $c->run(); + +exit($allTestsSucceed ? 0 : 1);