Skip to content

Commit 268da1a

Browse files
F#78299 US#190650 T#207172 add the support of multi coverage file for the baseline command + raises an error when the custom coverage can be increased
1 parent c6a515d commit 268da1a

File tree

5 files changed

+10
-17
lines changed

5 files changed

+10
-17
lines changed

src/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public function inspect(?PathInspectionConfig $fileConfig, FileMetric $metric):
2121
}
2222

2323
$globalCoverage = $this->config->getMinimumCoverage();
24-
$customCoverage = $fileConfig->getMinimumCoverage();
2524

26-
if ($customCoverage >= $globalCoverage || $metric->getCoverage() >= $globalCoverage) {
25+
if ($metric->getCoverage() >= $globalCoverage) {
2726
return new Failure($metric, $fileConfig->getMinimumCoverage(), Failure::UNNECESSARY_CUSTOM_COVERAGE);
2827
}
2928

src/Lib/Metrics/MetricsAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public function __construct(array $metrics, InspectionConfig $config)
3131
$this->config = $config;
3232

3333
$this->inspections = [
34+
new CustomCoverageAboveGlobalInspection($config),
3435
new DifferentCustomCoverageInspection($config),
3536
new BelowGlobalCoverageInspection($config),
36-
new UncoveredMethodsInspection($config),
37-
new CustomCoverageAboveGlobalInspection($config)
37+
new UncoveredMethodsInspection($config)
3838
];
3939
}
4040

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<error line="1" column="0" severity="error" message="Project per file coverage is configured at 80%. Current coverage is at 70%. Improve coverage for this class." source="phpunit-file-coverage-inspection"/>
55
</file>
66
<file name="/home/workspace/test/directory/standard-below-threshold.php">
7-
<error line="1" column="0" severity="error" message="Custom file coverage is configured at 90%. Current coverage is at 80%. Improve coverage for this class." source="phpunit-file-coverage-inspection"/>
7+
<error line="1" column="0" severity="error" message="Custom file coverage is configured at 90%. Current coverage is at 60%. Improve coverage for this class." source="phpunit-file-coverage-inspection"/>
8+
</file>
9+
<file name="/home/workspace/test/directory/standard-above-threshold.php">
10+
<error line="1" column="0" severity="error" message="A custom file coverage is configured at 90%, but the current file coverage 90% exceeds the project coverage 80%. Remove `/home/workspace/test/directory/standard-above-threshold.php` from phpfci.xml custom-coverage rules." source="phpunit-file-coverage-inspection"/>
811
</file>
912
<file name="/home/workspace/test/case/below-threshold.php">
1013
<error line="1" column="0" severity="error" message="Custom file coverage is configured at 55%. Current coverage is at 50%. Improve coverage for this class." source="phpunit-file-coverage-inspection"/>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
conditionals="0"
6363
coveredconditionals="0"
6464
statements="10"
65-
coveredstatements="8"
65+
coveredstatements="6"
6666
elements="0"
6767
coveredelements="0"/>
6868
<line num="1" type="method" name="methodName" count="1"/>
69-
<line num="2" type="stmt" count="1"/>
69+
<line num="2" type="stmt" count="0"/>
7070
<line num="3" type="stmt" count="1"/>
71-
<line num="4" type="stmt" count="1"/>
71+
<line num="4" type="stmt" count="0"/>
7272
<line num="5" type="stmt" count="1"/>
7373
<line num="6" type="stmt" count="1"/>
7474
<line num="7" type="stmt" count="1"/>

tests/Unit/Lib/Metrics/Inspection/CustomCoverageAboveGlobalInspectionTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,4 @@ public function testInspectCoverageAboveGlobalCoverageShouldFail(): void
4747
static::assertSame(Failure::UNNECESSARY_CUSTOM_COVERAGE, $failure->getReason());
4848
static::assertSame(40, $failure->getMinimumCoverage());
4949
}
50-
51-
public function testInspectCoverageCustomCoverageAboveGlobalCoverageShouldPass(): void
52-
{
53-
// global is 80
54-
$fileConfig = new PathInspectionConfig(PathInspectionConfig::TYPE_FILE, '/tmp/b', 85);
55-
$metric = new FileMetric('/tmp/b/', 0, 83, [], []);
56-
57-
static::assertNull($this->inspection->inspect($fileConfig, $metric));
58-
}
5950
}

0 commit comments

Comments
 (0)