Skip to content

Commit

Permalink
Merge branch '7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 21, 2018
2 parents b2f113c + 49a4028 commit 1ad62f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog-7.2.md
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 7.2 release series are documented in this fil
### Fixed

* Fixed [#3218](https://github.com/sebastianbergmann/phpunit/issues/3218): `prefix` attribute for `directory` node missing from `phpunit.xml` XSD
* Fixed [#3222](https://github.com/sebastianbergmann/phpunit/pull/3222): Priority of `@covers` and `@coversNothing` is wrong

## [7.2.7] - 2018-07-15

Expand Down
27 changes: 21 additions & 6 deletions src/Framework/TestResult.php
Expand Up @@ -189,6 +189,25 @@ class TestResult implements Countable
*/
private $registerMockObjectsFromTestArgumentsRecursively = false;

public static function isAnyCoverageRequired(TestCase $test)
{
$annotations = $test->getAnnotations();

// If any methods have covers, coverage must me generated
if (isset($annotations['method']['covers'])) {
return true;
}

// 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'])) {
return false;
}

// Otherwise each test method can generate coverage
return true;
}

/**
* Registers a TestListener.
*/
Expand Down Expand Up @@ -571,11 +590,7 @@ public function run(Test $test): void
$this->registerMockObjectsFromTestArgumentsRecursively
);

$annotations = $test->getAnnotations();

if (isset($annotations['class']['coversNothing']) || isset($annotations['method']['coversNothing'])) {
$coversNothing = true;
}
$isAnyCoverageRequired = self::isAnyCoverageRequired($test);
}

$error = false;
Expand Down Expand Up @@ -604,7 +619,7 @@ public function run(Test $test): void

$collectCodeCoverage = $this->codeCoverage !== null &&
!$test instanceof WarningTestCase &&
!$coversNothing;
$isAnyCoverageRequired;

if ($collectCodeCoverage) {
$this->codeCoverage->start($test);
Expand Down
21 changes: 21 additions & 0 deletions tests/Framework/TestResultTest.php
Expand Up @@ -62,4 +62,25 @@ public function testAddErrorOfTypeIncompleteTest()
$this->assertAttributeEquals(true, 'lastTestFailed', $result);
$this->assertAttributeContainsOnly(TestFailure::class, 'notImplemented', $result);
}

public function canSkipCoverageProvider()
{
return [
['CoverageClassTest', true],
['CoverageNothingTest', true],
['CoverageCoversOverridesCoversNothingTest', false],
];
}

/**
* @dataProvider canSkipCoverageProvider
*/
public function testCanSkipCoverage($testCase, $expectedCanSkip)
{
require_once __DIR__ . '/../_files/' . $testCase . '.php';

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

0 comments on commit 1ad62f2

Please sign in to comment.