Skip to content

Commit 5607fa4

Browse files
andrewnicolssebastianbergmann
authored andcommitted
Specify test name when initing TestCase
1 parent 1426ca6 commit 5607fa4

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* @coversNothing
14+
*/
15+
class CoverageClassNothingTest extends TestCase
16+
{
17+
public function testSomething(): void
18+
{
19+
$o = new CoveredClass;
20+
$o->publicMethod();
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
use PHPUnit\Framework\TestCase;
11+
12+
class CoverageClassWithoutAnnotationsTest extends TestCase
13+
{
14+
public function testSomething(): void
15+
{
16+
$o = new CoveredClass;
17+
$o->publicMethod();
18+
}
19+
}

tests/_files/CoverageNothingTest.php renamed to tests/_files/CoverageMethodNothingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use PHPUnit\Framework\TestCase;
1111

12-
class CoverageNothingTest extends TestCase
12+
class CoverageMethodNothingTest extends TestCase
1313
{
1414
/**
1515
* @covers CoveredClass::publicMethod

tests/unit/Framework/TestResultTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ public function testAddErrorOfTypeIncompleteTest(): void
6666
public function canSkipCoverageProvider(): array
6767
{
6868
return [
69-
['CoverageClassTest', true],
70-
['CoverageNothingTest', true],
69+
['CoverageClassTest', false],
70+
['CoverageClassNothingTest', true],
71+
['CoverageMethodNothingTest', false],
72+
['CoverageClassWithoutAnnotationsTest', false],
7173
['CoverageCoversOverridesCoversNothingTest', false],
7274
];
7375
}
@@ -79,8 +81,10 @@ public function testCanSkipCoverage($testCase, $expectedCanSkip): void
7981
{
8082
require_once TEST_FILES_PATH . $testCase . '.php';
8183

82-
$test = new $testCase;
83-
$canSkipCoverage = TestResult::isAnyCoverageRequired($test);
84+
$test = new $testCase('testSomething');
85+
$coverageRequired = TestResult::isAnyCoverageRequired($test);
86+
$canSkipCoverage = !$coverageRequired;
87+
8488
$this->assertEquals($expectedCanSkip, $canSkipCoverage);
8589
}
8690
}

tests/unit/Util/TestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ public function testGetLinesToBeCovered($test, $lines): void
786786
$expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines];
787787
} elseif ($test === 'CoverageNoneTest') {
788788
$expected = [];
789-
} elseif ($test === 'CoverageNothingTest') {
789+
} elseif ($test === 'CoverageMethodNothingTest') {
790790
$expected = false;
791791
} elseif ($test === 'CoverageFunctionTest') {
792792
$expected = [
@@ -1009,7 +1009,7 @@ public function getLinesToBeCoveredProvider(): array
10091009
\range(31, 35),
10101010
],
10111011
[
1012-
'CoverageNothingTest',
1012+
'CoverageMethodNothingTest',
10131013
false,
10141014
],
10151015
[

0 commit comments

Comments
 (0)