Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
compose=docker compose

dc:
@${compose} -f docker-compose.yml $(cmd)

dcr:
@make dc cmd="run --rm php-cli $(cmd)"

stop:
@make dc cmd="stop"

up:
@make dc cmd="up -d"

build-containers:
@make dc cmd="up -d --build"

down:
@make dc cmd="down"

composer:
@make dcr cmd="composer $(arg)"

# Code quality tools.
phpunit:
@make dcr cmd="vendor/bin/phpunit -d --enable-pretty-print -d --compact $(arg)"

phpunit-with-coverage-report:
@make phpunit arg="--coverage-clover=clover.xml -d --min-coverage=min-coverage-rules.php"

phpstan:
@make dcr cmd="vendor/bin/phpstan --memory-limit=1G $(arg)"

csfix:
@make dcr cmd="vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php"

delete-snapshots:
find . -name __snapshots__ -type d -prune -exec rm -rf {} \;
13 changes: 9 additions & 4 deletions src/Subscriber/Application/ApplicationFinishedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class ApplicationFinishedSubscriber extends FormatterHelper implements FinishedSubscriber
{
public function __construct(
private readonly string $relativePathToCloverXml,
private readonly string $pathToCloverXml,
private readonly MinCoverageRules $minCoverageRules,
private readonly bool $cleanUpCloverXml,
private readonly Exitter $exitter,
Expand All @@ -35,10 +35,15 @@ public function notify(Finished $event): void
$this->timer->start();
/** @var string $reflectionFileName */
$reflectionFileName = (new \ReflectionClass(ClassLoader::class))->getFileName();
$absolutePathToCloverXml = dirname($reflectionFileName, 3).'/'.$this->relativePathToCloverXml;

$absolutePathToCloverXml = $this->pathToCloverXml;
if (!str_starts_with($this->pathToCloverXml, '/')) {
// User is probably using relative path to clover.xml
$absolutePathToCloverXml = dirname($reflectionFileName, 3).'/'.$this->pathToCloverXml;
}

if (!file_exists($absolutePathToCloverXml)) {
return;
throw new \RuntimeException('Clover XML file not found at: '.$absolutePathToCloverXml);
}

/** @var CoverageMetric[] $metrics */
Expand Down Expand Up @@ -146,7 +151,7 @@ public static function fromConfigurationAndParameters(
}

return new self(
relativePathToCloverXml: $configuration->coverageClover(),
pathToCloverXml: $configuration->coverageClover(),
minCoverageRules: $rules,
cleanUpCloverXml: $cleanUpCloverXml,
exitter: new Exitter(),
Expand Down
37 changes: 18 additions & 19 deletions tests/Subscriber/Application/ApplicationFinishedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testNotifyWithAtLeastOneFailedRule(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-failed-rule.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testNotifyWithAWarning(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-warning.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testNotifyWhenCoverageIsOk(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-success.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testNotifyWithOnlyTotal(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-total-only.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -187,7 +187,7 @@ public function testNotifyWithoutTotal(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-without-total.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -221,7 +221,7 @@ public function testNotifyWithRulesThatDoNotExit(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-no-exit.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -255,7 +255,7 @@ public function testDivideByZero(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover-test-divide-by-zero.xml',
pathToCloverXml: 'tests/clover-test-divide-by-zero.xml',
minCoverageRules: MinCoverageRules::fromInt(100, true),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -289,7 +289,7 @@ public function testNotifyWhenNoTrackedLines(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover-with-no-tracked-lines.xml',
pathToCloverXml: 'tests/clover-with-no-tracked-lines.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-no-tracked-lines.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -323,14 +323,15 @@ public function testNotifyWithNonExistingCloverFile(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover-wrong.xml',
pathToCloverXml: 'tests/clover-wrong.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-success.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
consoleOutput: new ConsoleOutput($this->output, $this->resourceUsageFormatter),
timer: $this->timer,
);

$this->expectExceptionMessage('Clover XML file not found at:');
$subscriber->notify(event: new Finished(
new Info(
current: new Snapshot(
Expand All @@ -346,8 +347,6 @@ public function testNotifyWithNonExistingCloverFile(): void
),
0
));

$this->assertEmpty((string) $this->output);
}

public function testNotifyWithInvalidCloverFile(): void
Expand All @@ -357,7 +356,7 @@ public function testNotifyWithInvalidCloverFile(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover-invalid.xml',
pathToCloverXml: 'tests/clover-invalid.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-success.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand Down Expand Up @@ -394,7 +393,7 @@ public function testNotifyWithCleanUpCloverFile(): void
->method('exit');

$subscriber = new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover-to-delete.xml',
pathToCloverXml: 'tests/clover-to-delete.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-failed-rule.php'),
cleanUpCloverXml: true,
exitter: $this->exitter,
Expand Down Expand Up @@ -431,7 +430,7 @@ public function testNotifyWithDuplicatePatterns(): void
$this->expectExceptionMessage('Make sure all coverage rule patterns are unique');

new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-with-duplicates.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand All @@ -450,7 +449,7 @@ public function testNotifyWithInvalidRules(): void
$this->expectExceptionMessage('MinCoverage has to be value between 0 and 100. 203 given');

new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-invalid.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand All @@ -469,7 +468,7 @@ public function testNotifyWithInvalidRuleInstances(): void
$this->expectExceptionMessage('Make sure all coverage rules are of instance RobinIngelbrecht\PHPUnitCoverageTools\MinCoverage\MinCoverageRule');

new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-invalid-rule-instances.php'),
cleanUpCloverXml: false,
exitter: $this->exitter,
Expand All @@ -482,7 +481,7 @@ public function testFromConfigurationAndParameters(): void
{
$this->assertEquals(
new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromInt(90, false),
cleanUpCloverXml: true,
exitter: new Exitter(),
Expand All @@ -503,7 +502,7 @@ public function testFromConfigurationAndParameters2(): void
{
$this->assertEquals(
new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromInt(90, true),
cleanUpCloverXml: true,
exitter: new Exitter(),
Expand All @@ -526,7 +525,7 @@ public function testFromConfigurationAndParametersFromFile(): void
{
$this->assertEquals(
expected: new ApplicationFinishedSubscriber(
relativePathToCloverXml: 'tests/clover.xml',
pathToCloverXml: 'tests/clover.xml',
minCoverageRules: MinCoverageRules::fromConfigFile('tests/Subscriber/Application/min-coverage-rules-success.php'),
cleanUpCloverXml: false,
exitter: new Exitter(),
Expand Down