Skip to content

Commit

Permalink
Fix sebastianbergmann#3697 Respect @coversNothing at coverage driver …
Browse files Browse the repository at this point in the history
…start
  • Loading branch information
andrewnicols committed May 21, 2019
1 parent 856f213 commit 5975270
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/Framework/TestResult.php
Expand Up @@ -203,6 +203,12 @@ public static function isAnyCoverageRequired(TestCase $test): bool
return true;
}

// If there are no explicit covers, and the test method is
// marked as covers nothing, all coverage can be skipped
if (isset($annotations['method']['coversNothing'])) {
return false;
}

// If there are no explicit covers, and the test class is
// marked as covers nothing, all coverage can be skipped
if (isset($annotations['class']['coversNothing'])) {
Expand Down
@@ -0,0 +1,24 @@
<?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 CoverageCoversOverridesCoversNothingSameDocblockTest extends TestCase
{
/**
* @covers CoveredClass::publicMethod
* @coversNothing
*/
public function testSomething(): void
{
error_log("CoerageNothingTest");
$o = new CoveredClass;
$o->publicMethod();
}
}
22 changes: 22 additions & 0 deletions tests/_files/CoverageNothingClassTest.php
@@ -0,0 +1,22 @@
<?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;

/**
* @coversNothing
*/
class CoverageNothingClassTest extends TestCase
{
public function testSomething(): void
{
$o = new CoveredClass;
$o->publicMethod();
}
}
Expand Up @@ -9,10 +9,9 @@
*/
use PHPUnit\Framework\TestCase;

class CoverageNothingTest extends TestCase
class CoverageNothingMethodTest extends TestCase
{
/**
* @covers CoveredClass::publicMethod
* @coversNothing
*/
public function testSomething(): void
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/Framework/TestResultTest.php
Expand Up @@ -18,17 +18,19 @@ public function testCanSkipCoverage($testCase, $expectedCanSkip): void
{
require_once TEST_FILES_PATH . $testCase . '.php';

$test = new $testCase;
$canSkipCoverage = TestResult::isAnyCoverageRequired($test);
$this->assertEquals($expectedCanSkip, $canSkipCoverage);
$test = new $testCase('testSomething');
$coverageRequired = TestResult::isAnyCoverageRequired($test);
$this->assertEquals($expectedCanSkip, !$coverageRequired);
}

public function canSkipCoverageProvider(): array
{
return [
['CoverageClassTest', true],
['CoverageNothingTest', true],
['CoverageClassTest', false],
['CoverageCoversOverridesCoversNothingSameDocblockTest', false],
['CoverageCoversOverridesCoversNothingTest', false],
['CoverageNothingClassTest', true],
['CoverageNothingMethodTest', true],
];
}
}
10 changes: 8 additions & 2 deletions tests/unit/Util/TestTest.php
Expand Up @@ -1067,7 +1067,9 @@ public function testGetLinesToBeCovered($test, $lines): void
$expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines];
} elseif ($test === 'CoverageNoneTest') {
$expected = [];
} elseif ($test === 'CoverageNothingTest') {
} elseif ($test === 'CoverageNothingMethodTest') {
$expected = false;
} elseif ($test === 'CoverageNothingClassTest') {
$expected = false;
} elseif ($test === 'CoverageFunctionTest') {
$expected = [
Expand Down Expand Up @@ -1290,7 +1292,11 @@ public function getLinesToBeCoveredProvider(): array
\range(31, 35),
],
[
'CoverageNothingTest',
'CoverageNothingClassTest',
false,
],
[
'CoverageNothingMethodTest',
false,
],
[
Expand Down

0 comments on commit 5975270

Please sign in to comment.