Skip to content

Commit 0b7f3df

Browse files
committed
feat(tests): add CoverageSummaryTest for coverage validation
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 7aa3f73 commit 0b7f3df

6 files changed

Lines changed: 60 additions & 13 deletions

File tree

src/Command/SkillsCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
namespace FastForward\DevTools\Command;
2020

2121
use FastForward\DevTools\Agent\Skills\SkillsSynchronizer;
22-
use FastForward\DevTools\Agent\Skills\SynchronizeResult;
2322
use Symfony\Component\Console\Input\InputInterface;
2423
use Symfony\Component\Console\Output\OutputInterface;
2524
use Symfony\Component\Filesystem\Filesystem;
@@ -123,7 +122,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123122

124123
$this->synchronizer->setLogger($this->getIO());
125124

126-
/** @var SynchronizeResult $result */
127125
$result = $this->synchronizer->synchronize($skillsDir, $packageSkillsPath);
128126

129127
if ($result->failed()) {

src/Command/TestsCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
127127

128128
try {
129129
$minimumCoverage = $this->resolveMinimumCoverage($input);
130-
} catch (InvalidArgumentException $exception) {
131-
$output->writeln('<error>' . $exception->getMessage() . '</error>');
130+
} catch (InvalidArgumentException $invalidArgumentException) {
131+
$output->writeln('<error>' . $invalidArgumentException->getMessage() . '</error>');
132132

133133
return self::FAILURE;
134134
}
@@ -259,8 +259,8 @@ private function validateMinimumCoverage(
259259
): int {
260260
try {
261261
$coverageSummary = $this->coverageSummaryLoader->load($coverageReportPath);
262-
} catch (RuntimeException $exception) {
263-
$output->writeln('<error>' . $exception->getMessage() . '</error>');
262+
} catch (RuntimeException $runtimeException) {
263+
$output->writeln('<error>' . $runtimeException->getMessage() . '</error>');
264264

265265
return self::FAILURE;
266266
}

src/GitAttributes/Merger.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function merge(string $existingContent, array $exportIgnoreEntries, array
7979
if (isset($keptExportLookup[$pathKey])) {
8080
continue;
8181
}
82+
8283
if (isset($exportIgnoreLines[$pathKey])) {
8384
continue;
8485
}
@@ -149,8 +150,8 @@ private function parseExistingLines(string $content): array
149150

150151
$lines = [];
151152

152-
foreach (preg_split('/\R/', $content) ?: [] as $line) {
153-
$trimmedLine = trim($line);
153+
foreach (preg_split('/\R/', $content) as $line) {
154+
$trimmedLine = trim((string) $line);
154155

155156
if ('' === $trimmedLine) {
156157
continue;

src/GitAttributes/Writer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private function format(string $content): string
6363
$rows = [];
6464
$maxPathSpecLength = 0;
6565

66-
foreach (preg_split('/\R/', $content) ?: [] as $line) {
66+
foreach (preg_split('/\R/', $content) as $line) {
6767
$trimmedLine = trim((string) $line);
6868

6969
if ('' === $trimmedLine) {

tests/Command/TestsCommandTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ final class TestsCommandTest extends AbstractCommandTestCase
4747
*/
4848
protected function getCommandClass(): TestsCommand
4949
{
50-
return new TestsCommand(
51-
$this->filesystem->reveal(),
52-
$this->coverageSummaryLoader->reveal(),
53-
);
50+
return new TestsCommand($this->filesystem->reveal(), $this->coverageSummaryLoader->reveal());
5451
}
5552

5653
/**
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of fast-forward/dev-tools.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
12+
* @license https://opensource.org/licenses/MIT MIT License
13+
*
14+
* @see https://github.com/php-fast-forward/dev-tools
15+
* @see https://github.com/php-fast-forward
16+
* @see https://datatracker.ietf.org/doc/html/rfc2119
17+
*/
18+
19+
namespace FastForward\DevTools\PhpUnit\Coverage;
20+
21+
use PHPUnit\Framework\TestCase;
22+
use PHPUnit\Framework\Attributes\CoversClass;
23+
use PHPUnit\Framework\Attributes\DataProvider;
24+
use PHPUnit\Framework\Attributes\Test;
25+
26+
#[CoversClass(CoverageSummary::class)]
27+
class CoverageSummaryTest extends TestCase
28+
{
29+
/**
30+
* @return array
31+
*/
32+
public static function provideCoverageData(): array
33+
{
34+
return [[0, 0, 100.0], [50, 200, 25.0], [1, 3, 33.33333333333333]];
35+
}
36+
37+
/**
38+
* @param int $executed
39+
* @param int $executable
40+
* @param float $expectedPercentage
41+
*
42+
* @return void
43+
*/
44+
#[Test]
45+
#[DataProvider('provideCoverageData')]
46+
public function executedLinesReturnsValue(int $executed, int $executable, float $expectedPercentage): void
47+
{
48+
$summary = new CoverageSummary($executed, $executable);
49+
self::assertSame($executed, $summary->executedLines());
50+
}
51+
}

0 commit comments

Comments
 (0)