From bf27a84be7acc67db44089c432c59dc3e51382b2 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 May 2021 00:39:47 +0900 Subject: [PATCH] Remove CodeCoverageAnnotationIgnorer (#1517) Since we have a very explicit annotation `@infection-ignore-all` (added in #1468) that, again, very explicit on the purpose, and works not only for methods, but for most kinds of statements, let's remove `@codeCoverageIgnore` ignorer, that not only implicit (you may only want to ignore a piece of code temporarily, and only ignore) but also messes up the metrics (hides otherwise-uncovered mutations). --- .../PhpUnitCodeCoverageAnnotationIgnorer.php | 59 ------- .../PhpUnit/Adapter/PhpUnitAdapter.php | 9 +- .../src/DoNotMutateClass.php | 12 ++ .../tests/DoNotMutateClassTest.php | 16 ++ ...pUnitCodeCoverageAnnotationIgnorerTest.php | 161 ------------------ .../PhpUnit/Adapter/PhpUnitAdapterTest.php | 12 -- 6 files changed, 29 insertions(+), 240 deletions(-) delete mode 100644 src/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorer.php create mode 100644 tests/e2e/Ignore_All_Mutations/src/DoNotMutateClass.php create mode 100644 tests/e2e/Ignore_All_Mutations/tests/DoNotMutateClassTest.php delete mode 100644 tests/phpunit/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorerTest.php diff --git a/src/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorer.php b/src/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorer.php deleted file mode 100644 index 85d0978cc..000000000 --- a/src/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorer.php +++ /dev/null @@ -1,59 +0,0 @@ -getDocComment(); - - return $docComment !== null - && strpos($docComment->getText(), '@codeCoverageIgnore') !== false - ; - } -} diff --git a/src/TestFramework/PhpUnit/Adapter/PhpUnitAdapter.php b/src/TestFramework/PhpUnit/Adapter/PhpUnitAdapter.php index 13b6cc69f..03326c597 100644 --- a/src/TestFramework/PhpUnit/Adapter/PhpUnitAdapter.php +++ b/src/TestFramework/PhpUnit/Adapter/PhpUnitAdapter.php @@ -38,13 +38,11 @@ use function escapeshellarg; use Infection\AbstractTestFramework\MemoryUsageAware; use Infection\Config\ValueProvider\PCOVDirectoryProvider; -use Infection\PhpParser\Visitor\IgnoreNode\PhpUnitCodeCoverageAnnotationIgnorer; use Infection\TestFramework\AbstractTestFrameworkAdapter; use Infection\TestFramework\CommandLineArgumentsAndOptionsBuilder; use Infection\TestFramework\CommandLineBuilder; use Infection\TestFramework\Config\InitialConfigBuilder; use Infection\TestFramework\Config\MutationConfigBuilder; -use Infection\TestFramework\IgnoresAdditionalNodes; use Infection\TestFramework\ProvidesInitialRunOnlyOptions; use Infection\TestFramework\VersionParser; use function Safe\preg_match; @@ -56,7 +54,7 @@ * @internal * @final */ -class PhpUnitAdapter extends AbstractTestFrameworkAdapter implements IgnoresAdditionalNodes, MemoryUsageAware, ProvidesInitialRunOnlyOptions +class PhpUnitAdapter extends AbstractTestFrameworkAdapter implements MemoryUsageAware, ProvidesInitialRunOnlyOptions { public const COVERAGE_DIR = 'coverage-xml'; @@ -172,11 +170,6 @@ public function getInitialTestsFailRecommendations(string $commandLine): string return $recommendations; } - public function getNodeIgnorers(): array - { - return [new PhpUnitCodeCoverageAnnotationIgnorer()]; - } - /** * @return string[] */ diff --git a/tests/e2e/Ignore_All_Mutations/src/DoNotMutateClass.php b/tests/e2e/Ignore_All_Mutations/src/DoNotMutateClass.php new file mode 100644 index 000000000..917716edb --- /dev/null +++ b/tests/e2e/Ignore_All_Mutations/src/DoNotMutateClass.php @@ -0,0 +1,12 @@ +assertGreaterThan(0.0, $sourceClass->divide(2, 2)); + } + +} diff --git a/tests/phpunit/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorerTest.php b/tests/phpunit/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorerTest.php deleted file mode 100644 index cb7c66c2d..000000000 --- a/tests/phpunit/PhpParser/Visitor/IgnoreNode/PhpUnitCodeCoverageAnnotationIgnorerTest.php +++ /dev/null @@ -1,161 +0,0 @@ -createSpy(); - - $this->parseAndTraverse($code, $spy); - - $this->assertSame($count, $spy->nodeCounter); - } - - public function provideIgnoreCases(): iterable - { - yield 'classes with annotation are ignored' => [ - <<<'PHP' - [ - <<<'PHP' - [ - <<<'PHP' - [ - <<<'PHP' - [ - <<<'PHP' -adapter->getNodeIgnorers()); - - $this->assertSame( - [PhpUnitCodeCoverageAnnotationIgnorer::class], - $nodeIgnorers - ); - } - /** * @group integration */