Skip to content

Commit

Permalink
Merge pull request #5 from robiningelbrecht/fix-final-status-bug
Browse files Browse the repository at this point in the history
Fix final status bug
  • Loading branch information
robiningelbrecht committed Sep 13, 2023
2 parents 3eef6d6 + 8fb6565 commit 4be207c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/MinCoverage/ResultStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ enum ResultStatus: string
case WARNING = 'warning';
case FAILED = 'failed';

public static function fromWeight(int $weight): self
{
return match ($weight) {
1 => self::SUCCESS ,
2 => self::WARNING,
3 => self::FAILED,
default => throw new \InvalidArgumentException('Invalid weight '.$weight),
};
}

public function getWeight(): int
{
return match ($this) {
Expand Down
5 changes: 4 additions & 1 deletion src/Subscriber/Application/ApplicationFinishedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public function notify(Finished $event): void
metrics: $metrics,
metricTotal: $metricTotal,
);
$finalStatus = array_values($results)[0]->getStatus();
$statusWeights = array_map(fn (MinCoverageResult $result) => $result->getStatus()->getWeight(), $results);
rsort($statusWeights, SORT_NUMERIC);

$finalStatus = ResultStatus::fromWeight($statusWeights[0]);

$this->consoleOutput->print($results, $finalStatus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testNotifyWhenCoverageIsOk(): void
$this->assertMatchesTextSnapshot($spyOutput);
}

public function testNotifyWhitOnlyTotal(): void
public function testNotifyWithOnlyTotal(): void
{
$spyOutput = new SpyOutput();
$subscriber = new ApplicationFinishedSubscriber(
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testNotifyWhitOnlyTotal(): void
$this->assertMatchesTextSnapshot($spyOutput);
}

public function testNotifyWhitInvalidRules(): void
public function testNotifyWithInvalidRules(): void
{
$spyOutput = new SpyOutput();

Expand Down

0 comments on commit 4be207c

Please sign in to comment.