Skip to content

Commit

Permalink
Extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robiningelbrecht committed Sep 18, 2023
1 parent 7972b60 commit 7757d1e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MinCoverage/MinCoverageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function fromInt(int $minCoverage, bool $exitOnLowCoverage): self
{
return new self(
[new MinCoverageRule(
pattern: self::TOTAL,
pattern: MinCoverageRule::TOTAL,
minCoverage: $minCoverage,
exitOnLowCoverage: $exitOnLowCoverage
)],
Expand All @@ -72,6 +72,10 @@ public static function fromConfigFile(string $filePathToConfigFile): self
throw new \RuntimeException('Make sure all coverage rules are of instance '.MinCoverageRule::class);
}
}
$patterns = array_map(fn (MinCoverageRule $minCoverageRule) => $minCoverageRule->getPattern(), $rules);
if (count(array_unique($patterns)) !== count($patterns)) {
throw new \RuntimeException('Make sure all coverage rule patterns are unique');
}

return new self($rules);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Subscriber/Application/ApplicationFinishedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ public function testNotifyWithoutTotal(): void
$this->assertMatchesTextSnapshot($spyOutput);
}

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

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Make sure all coverage rule patterns are unique');

new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-duplicates.php'),
cleanUpCloverXml: false,
exitter: new Exitter(),
consoleOutput: new ConsoleOutput($spyOutput),
);
}

public function testNotifyWithInvalidRules(): void
{
$spyOutput = new SpyOutput();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use RobinIngelbrecht\PHPUnitCoverageTools\MinCoverage\MinCoverageRule;

return [
new MinCoverageRule(
pattern: 'RobinIngelbrecht\PHPUnitCoverageTools\PhpUnitExtension',
minCoverage: 100,
exitOnLowCoverage: true
),
new MinCoverageRule(
pattern: 'RobinIngelbrecht\PHPUnitCoverageTools\PhpUnitExtension',
minCoverage: 100,
exitOnLowCoverage: true
),
];

0 comments on commit 7757d1e

Please sign in to comment.