Skip to content

Commit 9dad8f0

Browse files
authored
Merge pull request #17 from 123inkt/Report-uncovered-methods-only
Only report actual uncovered methods.
2 parents baee460 + 9d50899 commit 9dad8f0

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/Renderer/RendererHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public static function renderReason(InspectionConfig $config, Failure $failure):
2222
return sprintf($message, (string)$failure->getMinimumCoverage(), (string)$failure->getMetric()->getCoverage());
2323
case Failure::MISSING_METHOD_COVERAGE:
2424
$message = "File coverage is above %s%%, but method(s) `%s` has/have no coverage at all.";
25-
$methodNames = array_map(static fn($method): string => $method->getMethodName(), $failure->getMetric()->getMethods());
25+
$methodNames = array_filter(
26+
array_map(
27+
static fn($method): ?string => $method->getCount() === 0 ? $method->getMethodName() : null,
28+
$failure->getMetric()->getMethods()
29+
)
30+
);
2631

2732
return sprintf($message, (string)$config->getMinimumCoverage(), implode(', ', $methodNames));
2833
case Failure::UNNECESSARY_CUSTOM_COVERAGE:

tests/Functional/Command/InspectCommand/Data/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<error line="1" column="0" severity="error" message="A custom file coverage is configured at 75%, but the current file coverage 90% exceeds the project coverage 80%. Remove `/home/workspace/test/case/unnecessary-custom-rule.php` from phpfci.xml custom-coverage rules." source="phpunit-file-coverage-inspection"/>
1414
</file>
1515
<file name="/home/workspace/test/case/uncovered-method.php">
16-
<error line="16" column="0" severity="error" message="File coverage is above 80%, but method(s) `__construct, myMethod` has/have no coverage at all." source="phpunit-file-coverage-inspection"/>
16+
<error line="16" column="0" severity="error" message="File coverage is above 80%, but method(s) `__construct` has/have no coverage at all." source="phpunit-file-coverage-inspection"/>
1717
</file>
1818
</checkstyle>

tests/Unit/Renderer/CheckStyleRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testRenderFileCoverageTooLow(): void
7070
public function testRenderMissingMethodCoverage(): void
7171
{
7272
$config = new InspectionConfig('', 80);
73-
$metric = new FileMetric('/foo/bar/file.php', 85.3, [new MethodMetric('method', 200, 80)]);
73+
$metric = new FileMetric('/foo/bar/file.php', 85.3, [new MethodMetric('method', 200, 0)]);
7474
$failure = new Failure($metric, 60, Failure::MISSING_METHOD_COVERAGE, 20);
7575

7676
$checkStyle = new CheckStyleRenderer();

tests/Unit/Renderer/RendererHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public function testRenderReasonCustomCoverageTooLow(): void
5252
*/
5353
public function testRenderReasonMissingMethodCoverage(): void
5454
{
55-
$metric = new FileMetric('foobar', 70, [new MethodMetric('myMethod', 100, 80)]);
55+
$metric = new FileMetric('foobar', 70, [new MethodMetric('coveredMethod', 100, 80), new MethodMetric('uncoveredMethod', 105, 0)]);
5656
$failure = new Failure($metric, 30, Failure::MISSING_METHOD_COVERAGE, 5);
5757

5858
$message = RendererHelper::renderReason($this->config, $failure);
59-
static::assertSame('File coverage is above 80%, but method(s) `myMethod` has/have no coverage at all.', $message);
59+
static::assertSame('File coverage is above 80%, but method(s) `uncoveredMethod` has/have no coverage at all.', $message);
6060
}
6161

6262
/**

0 commit comments

Comments
 (0)