Skip to content

Commit

Permalink
Fix #3697 Respect @coversNothing at coverage driver start
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and sebastianbergmann committed May 26, 2019
1 parent 1a1ae79 commit fb7e21f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Util/Test.php
Expand Up @@ -156,6 +156,12 @@ public static function requiresCodeCoverageDataCollection(TestCase $test): bool
{
$annotations = $test->getAnnotations();

// If there is no @covers annotation but a @coversNothing annotation on
// the test method then code coverage data does not need to be collected
if (isset($annotations['method']['coversNothing'])) {
return false;
}

// If there is at least one @covers annotation then
// code coverage data needs to be collected
if (isset($annotations['method']['covers'])) {
Expand Down
23 changes: 23 additions & 0 deletions tests/_files/CoverageMethodNothingCoversMethod.php
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

class CoverageMethodNothingCoversMethod extends TestCase
{
/**
* @covers CoveredClass::publicMethod
* @coversNothing
*/
public function testSomething(): void
{
$o = new CoveredClass;
$o->publicMethod();
}
}
1 change: 0 additions & 1 deletion tests/_files/CoverageMethodNothingTest.php
Expand Up @@ -12,7 +12,6 @@
class CoverageMethodNothingTest extends TestCase
{
/**
* @covers CoveredClass::publicMethod
* @coversNothing
*/
public function testSomething(): void
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/Util/TestTest.php
Expand Up @@ -1065,10 +1065,14 @@ public function testGetLinesToBeCovered($test, $lines): void
$expected = [
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines,
];
} elseif ($test === 'CoverageMethodNothingCoversMethod') {
$expected = false;
} elseif ($test === 'CoverageCoversOverridesCoversNothingTest') {
$expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines];
} elseif ($test === 'CoverageNoneTest') {
$expected = [];
} elseif ($test === 'CoverageClassNothingTest') {
$expected = false;
} elseif ($test === 'CoverageMethodNothingTest') {
$expected = false;
} elseif ($test === 'CoverageFunctionTest') {
Expand Down Expand Up @@ -1291,6 +1295,10 @@ public function getLinesToBeCoveredProvider(): array
'NamespaceCoverageCoversClassPublicTest',
\range(31, 35),
],
[
'CoverageClassNothingTest',
false,
],
[
'CoverageMethodNothingTest',
false,
Expand All @@ -1299,6 +1307,10 @@ public function getLinesToBeCoveredProvider(): array
'CoverageCoversOverridesCoversNothingTest',
\range(29, 33),
],
[
'CoverageMethodNothingCoversMethod',
false,
],
];
}

Expand Down Expand Up @@ -1343,10 +1355,10 @@ public function canSkipCoverageProvider(): array
{
return [
['CoverageClassTest', false],
['CoverageClassNothingTest', true],
['CoverageMethodNothingTest', false],
['CoverageClassWithoutAnnotationsTest', false],
['CoverageCoversOverridesCoversNothingTest', false],
['CoverageClassNothingTest', true],
['CoverageMethodNothingTest', true],
];
}

Expand Down

0 comments on commit fb7e21f

Please sign in to comment.