Skip to content

Commit

Permalink
Revert "fixup! fix(test): exit code of lime test"
Browse files Browse the repository at this point in the history
This reverts commit 8d951e2a5b1a8cf958f351a2d305a8c5007bad29.
  • Loading branch information
alquerci committed Mar 27, 2024
1 parent f25c0cd commit fa11b69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 89 deletions.
5 changes: 1 addition & 4 deletions lib/plugins/sfDoctrinePlugin/test/bin/coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,4 @@

$finder = sfFinder::type('file')->name('*.php')->prune('vendor')->prune('test')->prune('data');
$c->register($finder->in($c->base_dir));

$allTestsSucceed = $c->run();

exit($allTestsSucceed ? 0 : 1);
$c->run();
99 changes: 18 additions & 81 deletions lib/vendor/lime/lime.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@
*/
class lime_test
{
public const EPSILON = 0.0000000001;
const EPSILON = 0.0000000001;

protected $test_nb = 0;
protected $output = null;
protected $results = array();
protected $options = 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;
static protected $all_results = array();

public function __construct($plan = null, $options = array())
{
++self::$instanceCount;

// for BC
if (!is_array($options))
{
Expand Down Expand Up @@ -137,87 +129,32 @@ static public function to_xml($results = null)
}

public function __destruct()
{
$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'];
$passed = count($this->results['stats']['passed']);
$failed = count($this->results['stats']['failed']);
$total = $this->results['stats']['total'];
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));

if (null === $plan) {
$plan = $total;

$this->output->echoln(sprintf("1..%d", $plan));
}

if ($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) {
}
elseif ($total < $plan)
{
$this->output->red_bar(sprintf("# Looks like you planned %d tests but only ran %d.", $plan, $total));
}

return $total === $plan ? self::STATE_PASS : self::STATE_FAIL;
}

private function keepTheWorstState(int $state): void
{
if ($this->stateIsTheWorst($state)) {
self::$finalState = $state;
if ($failed)
{
$this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed));
}
}

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));
else if ($total == $plan)
{
$this->output->green_bar("# Looks like everything went fine.");
}
}

private function determineExitCodeFromState(int $state): int
{
switch ($state) {
case self::STATE_PASS:
return 0;
default:
return 1;
}
flush();
}

/**
Expand Down Expand Up @@ -1032,7 +969,7 @@ function lime_shutdown()
$delta = 0;
if ($return > 0)
{
$stats['status'] = $file_stats['failed'] ? 'not ok' : ($file_stats['errors'] ? 'errors' : 'dubious');
$stats['status'] = $file_stats['errors'] ? 'errors' : 'dubious';
$stats['status_code'] = $return;
}
else
Expand Down
5 changes: 1 addition & 4 deletions test/bin/coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,4 @@
$finder = sfFinder::type('file')->name($name.'.class.php')->prune('vendor')->prune('test')->prune('data');

$c->register($finder->in($c->base_dir));

$allTestsSucceed = $c->run();

exit($allTestsSucceed ? 0 : 1);
$c->run();

0 comments on commit fa11b69

Please sign in to comment.