Skip to content

Commit

Permalink
Specify test name when initing TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and sebastianbergmann committed May 26, 2019
1 parent d58761f commit 1a1ae79
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
22 changes: 22 additions & 0 deletions tests/_files/CoverageClassNothingTest.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 CoverageClassNothingTest extends TestCase
{
public function testSomething(): void
{
$o = new CoveredClass;
$o->publicMethod();
}
}
19 changes: 19 additions & 0 deletions tests/_files/CoverageClassWithoutAnnotationsTest.php
@@ -0,0 +1,19 @@
<?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 CoverageClassWithoutAnnotationsTest extends TestCase
{
public function testSomething(): void
{
$o = new CoveredClass;
$o->publicMethod();
}
}
Expand Up @@ -9,7 +9,7 @@
*/
use PHPUnit\Framework\TestCase;

class CoverageNothingTest extends TestCase
class CoverageMethodNothingTest extends TestCase
{
/**
* @covers CoveredClass::publicMethod
Expand Down
15 changes: 9 additions & 6 deletions tests/unit/Util/TestTest.php
Expand Up @@ -1069,7 +1069,7 @@ public function testGetLinesToBeCovered($test, $lines): void
$expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines];
} elseif ($test === 'CoverageNoneTest') {
$expected = [];
} elseif ($test === 'CoverageNothingTest') {
} elseif ($test === 'CoverageMethodNothingTest') {
$expected = false;
} elseif ($test === 'CoverageFunctionTest') {
$expected = [
Expand Down Expand Up @@ -1292,7 +1292,7 @@ public function getLinesToBeCoveredProvider(): array
\range(31, 35),
],
[
'CoverageNothingTest',
'CoverageMethodNothingTest',
false,
],
[
Expand Down Expand Up @@ -1332,17 +1332,20 @@ public function testCanSkipCoverage($testCase, $expectedCanSkip): void
{
require_once TEST_FILES_PATH . $testCase . '.php';

$test = new $testCase;
$canSkipCoverage = Test::requiresCodeCoverageDataCollection($test);
$test = new $testCase('testSomething');
$coverageRequired = Test::requiresCodeCoverageDataCollection($test);
$canSkipCoverage = !$coverageRequired;

$this->assertEquals($expectedCanSkip, $canSkipCoverage);
}

public function canSkipCoverageProvider(): array
{
return [
['CoverageClassTest', true],
['CoverageNothingTest', true],
['CoverageClassTest', false],
['CoverageClassNothingTest', true],
['CoverageMethodNothingTest', false],
['CoverageClassWithoutAnnotationsTest', false],
['CoverageCoversOverridesCoversNothingTest', false],
];
}
Expand Down

0 comments on commit 1a1ae79

Please sign in to comment.