Skip to content

Commit a75dbc0

Browse files
committed
CoverageGuard: enforce 70% coverage for all methods; add missing tests
1 parent d8ef02e commit a75dbc0

File tree

6 files changed

+105
-5
lines changed

6 files changed

+105
-5
lines changed

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"phpunit/phpunit": "^9.6.22",
2323
"shipmonk/coding-standard": "^0.2.0",
2424
"shipmonk/composer-dependency-analyser": "^1.8.1",
25+
"shipmonk/coverage-guard": "dev-master",
2526
"shipmonk/dead-code-detector": "^0.9.0",
2627
"shipmonk/name-collision-detector": "^2.1.1",
2728
"shipmonk/phpstan-dev": "^0.1.2"
@@ -59,7 +60,7 @@
5960
"@check:ec",
6061
"@check:cs",
6162
"@check:types",
62-
"@check:tests",
63+
"@check:coverage",
6364
"@check:dependencies",
6465
"@check:collisions",
6566
"@check:ignores"
@@ -69,11 +70,15 @@
6970
"composer normalize --dry-run --no-check-lock --no-update-lock",
7071
"composer validate --strict"
7172
],
73+
"check:coverage": [
74+
"XDEBUG_MODE=coverage phpunit tests --coverage-clover cache/clover.xml",
75+
"coverage-guard check cache/clover.xml"
76+
],
7277
"check:cs": "phpcs",
7378
"check:dependencies": "composer-dependency-analyser",
7479
"check:ec": "ec src tests",
7580
"check:ignores": "php bin/verify-inline-ignore.php",
76-
"check:tests": "phpunit -vvv tests",
81+
"check:tests": "phpunit tests",
7782
"check:types": "phpstan analyse -vv --ansi",
7883
"fix:cs": "phpcbf"
7984
}

composer.lock

Lines changed: 65 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coverage-guard.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use ShipMonk\CoverageGuard\Config;
4+
use ShipMonk\CoverageGuard\Rule\EnforceCoverageForMethodsRule;
5+
6+
$config = new Config();
7+
$config->addRule(new EnforceCoverageForMethodsRule(
8+
requiredCoveragePercentage: 70,
9+
minExecutableLines: 5,
10+
));
11+
12+
return $config;

phpunit.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
<php>
1515
<ini name="error_reporting" value="-1"/>
1616
</php>
17+
18+
<coverage processUncoveredFiles="true">
19+
<include>
20+
<directory suffix=".php">src</directory>
21+
</include>
22+
</coverage>
1723
</phpunit>

tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ protected function getRule(): Rule
4949
'ForbidCheckedExceptionInCallableRule\FirstClassCallableTest::allowThrow' => [1],
5050
'ForbidCheckedExceptionInCallableRule\ArrowFunctionTest::allowThrow' => [0],
5151
'ForbidCheckedExceptionInCallableRule\ArrowFunctionTest::__construct' => [0],
52-
'allowed_function' => [0],
52+
'ForbidCheckedExceptionInCallableRule\allowed_function' => [0], // not really needed as functions are always considered immediately invoked (https://phpstan.org/writing-php-code/phpdocs-basics#callables)
53+
'ForbidCheckedExceptionInCallableRule\allowed_function_not_immediate' => [0],
5354
],
5455
);
5556
}

tests/Rule/data/ForbidCheckedExceptionInCallableRule/code.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function throwing_function() {}
1111

1212
function allowed_function(callable $callable) {}
1313

14+
/**
15+
* @param-later-invoked-callable $callable
16+
*/
17+
function allowed_function_not_immediate(callable $callable) {}
18+
1419
interface CallableTest {
1520

1621
public function allowThrowInInterface(callable $callable): void;
@@ -96,6 +101,12 @@ public function testPassedCallbacksA5(): void
96101
$this->allowThrow(42, throwing_function(...));
97102
}
98103

104+
public function testPassedCallbacksA6(): void
105+
{
106+
allowed_function(throwing_function(...));
107+
allowed_function_not_immediate(throwing_function(...));
108+
}
109+
99110
public function testPassedCallbacksA6(): void
100111
{
101112
$this->immediateThrow(
@@ -510,3 +521,5 @@ private function throws(): void
510521
throw new CheckedException();
511522
}
512523
}
524+
525+

0 commit comments

Comments
 (0)