Skip to content

Commit

Permalink
We no longer need to look for code coverage target metadata on test m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
sebastianbergmann committed Feb 27, 2024
1 parent f2347f1 commit e817f3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/Framework/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public function run(TestCase $test): void

$linesToBeUsed = (new CodeCoverageMetadataApi)->linesToBeUsed(
$test::class,
$test->name(),
);
} catch (InvalidCoversTargetException $cce) {
Event\Facade::emitter()->testTriggeredPhpunitWarning(
Expand Down
7 changes: 3 additions & 4 deletions src/Metadata/Api/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function linesToBeCovered(string $className, string $methodName): array|f
$codeUnits = CodeUnitCollection::fromList();
$mapper = new Mapper;

foreach (Registry::parser()->forClassAndMethod($className, $methodName) as $metadata) {
foreach (Registry::parser()->forClass($className) as $metadata) {
if (!$metadata->isCoversClass() && !$metadata->isCoversMethod() && !$metadata->isCoversFunction()) {
continue;
}
Expand All @@ -64,18 +64,17 @@ public function linesToBeCovered(string $className, string $methodName): array|f

/**
* @psalm-param class-string $className
* @psalm-param non-empty-string $methodName
*
* @psalm-return array<string,list<int>>
*
* @throws CodeCoverageException
*/
public function linesToBeUsed(string $className, string $methodName): array
public function linesToBeUsed(string $className): array
{
$codeUnits = CodeUnitCollection::fromList();
$mapper = new Mapper;

foreach (Registry::parser()->forClassAndMethod($className, $methodName) as $metadata) {
foreach (Registry::parser()->forClass($className) as $metadata) {
if (!$metadata->isUsesClass() && !$metadata->isUsesMethod() && !$metadata->isUsesFunction()) {
continue;
}
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/Metadata/Api/CodeCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ public function testLinesToBeCoveredCanBeDetermined(array|false $expected, strin
* @psalm-param class-string $className
*/
#[DataProvider('linesToBeUsedProvider')]
public function testLinesToBeUsedCanBeDetermined(array|false $expected, string $className, string $methodName): void
public function testLinesToBeUsedCanBeDetermined(array|false $expected, string $className): void
{
$this->assertEqualsCanonicalizing(
$expected,
(new CodeCoverage)->linesToBeUsed(
$className,
$methodName,
),
);
}
Expand Down Expand Up @@ -225,7 +224,7 @@ public function testRejectsInterfaceAsUsesClassTargetWithAttribute(): void
$this->expectException(CodeCoverageException::class);
$this->expectExceptionMessage('Interface "Throwable" is not a valid target for code coverage');

(new CodeCoverage)->linesToBeUsed(InterfaceAsTargetWithAttributeTest::class, 'testOne');
(new CodeCoverage)->linesToBeUsed(InterfaceAsTargetWithAttributeTest::class);
}

public function testRejectsInvalidCoversClassTargetWithAttribute(): void
Expand All @@ -241,7 +240,7 @@ public function testRejectsInvalidUsesClassTargetWithAttribute(): void
$this->expectException(CodeCoverageException::class);
$this->expectExceptionMessage('Class "InvalidClass" is not a valid target for code coverage');

(new CodeCoverage)->linesToBeUsed(InvalidClassTargetWithAttributeTest::class, 'testOne');
(new CodeCoverage)->linesToBeUsed(InvalidClassTargetWithAttributeTest::class);
}

public function testRejectsInvalidCoversClassTargetWithAnnotation(): void
Expand All @@ -257,7 +256,7 @@ public function testRejectsInvalidUsesClassTargetWithAnnotation(): void
$this->expectException(CodeCoverageException::class);
$this->expectExceptionMessage('Class "InvalidClass" is not a valid target for code coverage');

(new CodeCoverage)->linesToBeUsed(InvalidClassTargetWithAnnotationTest::class, 'testOne');
(new CodeCoverage)->linesToBeUsed(InvalidClassTargetWithAnnotationTest::class);
}

public function testRejectsInvalidCoversFunctionTarget(): void
Expand All @@ -273,6 +272,6 @@ public function testRejectsInvalidUsesFunctionTarget(): void
$this->expectException(CodeCoverageException::class);
$this->expectExceptionMessage('Function "::invalid_function" is not a valid target for code coverage');

(new CodeCoverage)->linesToBeUsed(InvalidFunctionTargetTest::class, 'testOne');
(new CodeCoverage)->linesToBeUsed(InvalidFunctionTargetTest::class);
}
}

0 comments on commit e817f3d

Please sign in to comment.