Skip to content

Commit

Permalink
apply abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror committed Dec 27, 2023
1 parent d3091f1 commit 27fd409
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public function diff(array $items): self
{
return new self(array_values(array_diff($this->items, $items)));
}

public function count(): int
{
return count($this->items);
}
}
10 changes: 5 additions & 5 deletions src/Symfony/Console/CheckCoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ public function execute(InputInterface $input, OutputInterface $output): int

$this->logger?->debug('CoverageCommand: Open Api Paths ', ['open_api_paths_count' => count($openApiPaths)]);

$missingPaths = array_diff($paths->items, $openApiPaths);
$missingPaths = $paths->diff($openApiPaths);

$coverageCalculator = new CoverageCalculator(count($paths->items), count($openApiPaths));
$coverageCalculator = new CoverageCalculator($paths->count(), count($openApiPaths));

$output->writeln('Open API coverage: ' . $coverageCalculator->calculate()->asPercentage() . '%');

if (empty($missingPaths)) {
if ($missingPaths->count() === 0) {
$output->writeln('OpenAPI schema covers all Symfony routes. Good job!');
} else {
$output->writeln('Missing paths in OpenAPI schema:');
foreach ($missingPaths as $path) {
$output->writeln("- $path");
foreach ($missingPaths->items as $path) {
$output->writeln($path->path);
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Integration/CheckCoverageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public function testExecuteClass(): void

$expectedDisplay = <<<TEXT
Open API coverage: 0%
OpenAPI schema covers all Symfony routes. Good job!
Missing paths in OpenAPI schema:
/products
/products
/products/:id
TEXT;

$this->assertEquals($expectedDisplay, $display);
Expand Down

0 comments on commit 27fd409

Please sign in to comment.