Skip to content

Commit

Permalink
Merge pull request #9 from LeoVie/fix-edge-case
Browse files Browse the repository at this point in the history
Fix edge case: Baseline is not empty, but actual result is empty
  • Loading branch information
LeoVie authored Apr 4, 2023
2 parents b6d6eee + 0a72348 commit 55aaf4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Command/CloverCrapCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;

#[AsCommand(name: 'clover-crap-check')]
Expand Down Expand Up @@ -114,6 +113,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return $this->generateBaseline($io, $generateBaselinePath, $crapCheckResult);
}

if ($baselinePath !== null) {
return $this->compareWithBaseline($io, $baselinePath, $crapCheckResult, $reportLessCrappyMethods, $reportVanishedMethods);
}

if ($crapCheckResult instanceof EmptyCrapCheckResult) {
if ($io->isVerbose()) {
$io->info('No crappy methods detected.');
Expand All @@ -124,10 +127,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var NonEmptyCrapCheckResult $crapCheckResult */

if ($baselinePath !== null) {
return $this->compareWithBaseline($io, $baselinePath, $crapCheckResult, $reportLessCrappyMethods, $reportVanishedMethods);
}

$io->error('The following methods are crappier than allowed');
$this->outputMethodsTable($io, $crapCheckResult->tooCrappyMethods);

Expand Down Expand Up @@ -223,11 +222,11 @@ private function generateBaseline(SymfonyStyle $io, string $generateBaselinePath
}

private function compareWithBaseline(
SymfonyStyle $io,
string $baselinePath,
NonEmptyCrapCheckResult $crapCheckResult,
bool $reportLessCrappyMethods,
bool $reportVanishedMethods,
SymfonyStyle $io,
string $baselinePath,
CrapCheckResult $crapCheckResult,
bool $reportLessCrappyMethods,
bool $reportVanishedMethods,
): int
{
if ($io->isVerbose()) {
Expand Down
18 changes: 18 additions & 0 deletions tests/Functional/CloverCrapCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ public static function checkProvider(): array
'crap-threshold' => 10,
],
],
'no too crappy methods, but baseline is not empty' => [
'expectedStatus' => 1,
'expectedOutput' =>
'[ERROR] The baseline is not up to date
[INFO] The following methods vanished
------------ -------- ------
Class method CRAP
------------ -------- ------
ClassA m1 10
Foo\ClassB m2 2
------------ -------- ------',
'inputs' => [
'clover-report-path' => __DIR__ . '/../_testdata/clover.xml',
'crap-threshold' => 10,
'--baseline' => __DIR__ . '/../_testdata/baseline.json',
'--report-vanished-methods' => true
],
],
'all crappy methods covered by baseline' => [
'expectedStatus' => 0,
'expectedOutput' => '',
Expand Down

0 comments on commit 55aaf4b

Please sign in to comment.