Skip to content

Commit a50a2c7

Browse files
Refactor
1 parent 1be1b30 commit a50a2c7

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/Framework/TestRunner/TestRunner.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public function run(TestCase $test): void
7070
$test->name(),
7171
);
7272

73-
$shouldCodeCoverageBeCollected = $codeCoverageMetadataApi->shouldCodeCoverageBeCollectedFor(
74-
$test::class,
75-
$test->name(),
76-
);
73+
$shouldCodeCoverageBeCollected = $codeCoverageMetadataApi->shouldCodeCoverageBeCollectedFor($test);
7774

7875
$this->performSanityChecks($test, $coversTargets, $usesTargets, $shouldCodeCoverageBeCollected);
7976

src/Metadata/Api/CodeCoverage.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\Metadata\Api;
1111

1212
use function assert;
13+
use PHPUnit\Framework\TestCase;
1314
use PHPUnit\Metadata\CoversClass;
1415
use PHPUnit\Metadata\CoversClassesThatExtendClass;
1516
use PHPUnit\Metadata\CoversClassesThatImplementInterface;
@@ -145,20 +146,17 @@ public function usesTargets(string $className, string $methodName): TargetCollec
145146
return TargetCollection::fromArray($targets);
146147
}
147148

148-
/**
149-
* @param class-string $className
150-
* @param non-empty-string $methodName
151-
*/
152-
public function shouldCodeCoverageBeCollectedFor(string $className, string $methodName): bool
149+
public function shouldCodeCoverageBeCollectedFor(TestCase $test): bool
153150
{
154-
$metadataForClass = Registry::parser()->forClass($className);
155-
$metadataForMethod = Registry::parser()->forMethod($className, $methodName);
151+
$className = $test::class;
152+
$methodName = $test->name();
153+
$parser = Registry::parser();
156154

157-
if ($metadataForMethod->isCoversNothing()->isNotEmpty()) {
155+
if ($parser->forMethod($className, $methodName)->isCoversNothing()->isNotEmpty()) {
158156
return false;
159157
}
160158

161-
if ($metadataForClass->isCoversNothing()->isNotEmpty()) {
159+
if ($parser->forClass($className)->isCoversNothing()->isNotEmpty()) {
162160
return false;
163161
}
164162

tests/unit/Metadata/Api/CodeCoverageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testMapsUsesMetadataToCodeCoverageTargetCollection(): void
135135
public function testWhetherCollectionOfCodeCoverageDataCanBeSkippedCanBeDetermined(bool $expected, string $testCase): void
136136
{
137137
$test = new $testCase('testSomething');
138-
$coverageRequired = (new CodeCoverage)->shouldCodeCoverageBeCollectedFor($test::class, $test->name());
138+
$coverageRequired = (new CodeCoverage)->shouldCodeCoverageBeCollectedFor($test);
139139
$canSkipCoverage = !$coverageRequired;
140140

141141
$this->assertSame($expected, $canSkipCoverage);

0 commit comments

Comments
 (0)