Skip to content

Commit 8fb6565

Browse files
Fix final status bug
1 parent 3eef6d6 commit 8fb6565

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/MinCoverage/ResultStatus.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ enum ResultStatus: string
88
case WARNING = 'warning';
99
case FAILED = 'failed';
1010

11+
public static function fromWeight(int $weight): self
12+
{
13+
return match ($weight) {
14+
1 => self::SUCCESS ,
15+
2 => self::WARNING,
16+
3 => self::FAILED,
17+
default => throw new \InvalidArgumentException('Invalid weight '.$weight),
18+
};
19+
}
20+
1121
public function getWeight(): int
1222
{
1323
return match ($this) {

src/Subscriber/Application/ApplicationFinishedSubscriber.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public function notify(Finished $event): void
7474
metrics: $metrics,
7575
metricTotal: $metricTotal,
7676
);
77-
$finalStatus = array_values($results)[0]->getStatus();
77+
$statusWeights = array_map(fn (MinCoverageResult $result) => $result->getStatus()->getWeight(), $results);
78+
rsort($statusWeights, SORT_NUMERIC);
79+
80+
$finalStatus = ResultStatus::fromWeight($statusWeights[0]);
7881

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

tests/Subscriber/Application/ApplicationFinishedSubscriberTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function testNotifyWhenCoverageIsOk(): void
123123
$this->assertMatchesTextSnapshot($spyOutput);
124124
}
125125

126-
public function testNotifyWhitOnlyTotal(): void
126+
public function testNotifyWithOnlyTotal(): void
127127
{
128128
$spyOutput = new SpyOutput();
129129
$subscriber = new ApplicationFinishedSubscriber(
@@ -154,7 +154,7 @@ public function testNotifyWhitOnlyTotal(): void
154154
$this->assertMatchesTextSnapshot($spyOutput);
155155
}
156156

157-
public function testNotifyWhitInvalidRules(): void
157+
public function testNotifyWithInvalidRules(): void
158158
{
159159
$spyOutput = new SpyOutput();
160160

tests/Subscriber/Application/__snapshots__/ApplicationFinishedSubscriberTest__testNotifyWhitOnlyTotal__1.txt renamed to tests/Subscriber/Application/__snapshots__/ApplicationFinishedSubscriberTest__testNotifyWithOnlyTotal__1.txt

File renamed without changes.

0 commit comments

Comments
 (0)