Skip to content

Commit 7757d1e

Browse files
Extra tests
1 parent 7972b60 commit 7757d1e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/MinCoverage/MinCoverageRules.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function fromInt(int $minCoverage, bool $exitOnLowCoverage): self
4949
{
5050
return new self(
5151
[new MinCoverageRule(
52-
pattern: self::TOTAL,
52+
pattern: MinCoverageRule::TOTAL,
5353
minCoverage: $minCoverage,
5454
exitOnLowCoverage: $exitOnLowCoverage
5555
)],
@@ -72,6 +72,10 @@ public static function fromConfigFile(string $filePathToConfigFile): self
7272
throw new \RuntimeException('Make sure all coverage rules are of instance '.MinCoverageRule::class);
7373
}
7474
}
75+
$patterns = array_map(fn (MinCoverageRule $minCoverageRule) => $minCoverageRule->getPattern(), $rules);
76+
if (count(array_unique($patterns)) !== count($patterns)) {
77+
throw new \RuntimeException('Make sure all coverage rule patterns are unique');
78+
}
7579

7680
return new self($rules);
7781
}

tests/Subscriber/Application/ApplicationFinishedSubscriberTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ public function testNotifyWithoutTotal(): void
179179
$this->assertMatchesTextSnapshot($spyOutput);
180180
}
181181

182+
public function testNotifyWithDuplicatePatterns(): void
183+
{
184+
$spyOutput = new SpyOutput();
185+
186+
$this->expectException(\RuntimeException::class);
187+
$this->expectExceptionMessage('Make sure all coverage rule patterns are unique');
188+
189+
new ApplicationFinishedSubscriber(
190+
relativePathToCloverXml: 'tests/clover.xml',
191+
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-duplicates.php'),
192+
cleanUpCloverXml: false,
193+
exitter: new Exitter(),
194+
consoleOutput: new ConsoleOutput($spyOutput),
195+
);
196+
}
197+
182198
public function testNotifyWithInvalidRules(): void
183199
{
184200
$spyOutput = new SpyOutput();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use RobinIngelbrecht\PHPUnitCoverageTools\MinCoverage\MinCoverageRule;
4+
5+
return [
6+
new MinCoverageRule(
7+
pattern: 'RobinIngelbrecht\PHPUnitCoverageTools\PhpUnitExtension',
8+
minCoverage: 100,
9+
exitOnLowCoverage: true
10+
),
11+
new MinCoverageRule(
12+
pattern: 'RobinIngelbrecht\PHPUnitCoverageTools\PhpUnitExtension',
13+
minCoverage: 100,
14+
exitOnLowCoverage: true
15+
),
16+
];

0 commit comments

Comments
 (0)