Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ jobs:
php-version: ${{ matrix.php-version }}
-
name: Update dependencies
run: composer update --no-progress --${{ matrix.dependency-version }} --prefer-dist --no-interaction
run: |
composer remove --dev shipmonk/coverage-guard --no-update
composer update --no-progress --${{ matrix.dependency-version }} --prefer-dist --no-interaction
-
name: Run tests
run: composer check:tests
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"phpunit/phpunit": "^9.6.22",
"shipmonk/coding-standard": "^0.2.0",
"shipmonk/composer-dependency-analyser": "^1.8.1",
"shipmonk/coverage-guard": "dev-master",
"shipmonk/dead-code-detector": "^0.9.0",
"shipmonk/name-collision-detector": "^2.1.1",
"shipmonk/phpstan-dev": "^0.1.2"
Expand Down Expand Up @@ -59,7 +60,7 @@
"@check:ec",
"@check:cs",
"@check:types",
"@check:tests",
"@check:coverage",
"@check:dependencies",
"@check:collisions",
"@check:ignores"
Expand All @@ -69,11 +70,15 @@
"composer normalize --dry-run --no-check-lock --no-update-lock",
"composer validate --strict"
],
"check:coverage": [
"XDEBUG_MODE=coverage phpunit tests --coverage-clover cache/clover.xml",
"coverage-guard check cache/clover.xml"
],
"check:cs": "phpcs",
"check:dependencies": "composer-dependency-analyser",
"check:ec": "ec src tests",
"check:ignores": "php bin/verify-inline-ignore.php",
"check:tests": "phpunit -vvv tests",
"check:tests": "phpunit tests",
"check:types": "phpstan analyse -vv --ansi",
"fix:cs": "phpcbf"
}
Expand Down
67 changes: 65 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coverage-guard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use ShipMonk\CoverageGuard\Config;
use ShipMonk\CoverageGuard\Rule\EnforceCoverageForMethodsRule;

$config = new Config();
$config->addRule(new EnforceCoverageForMethodsRule(
requiredCoveragePercentage: 70,
minExecutableLines: 5,
));

return $config;
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
<php>
<ini name="error_reporting" value="-1"/>
</php>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
3 changes: 2 additions & 1 deletion tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ protected function getRule(): Rule
'ForbidCheckedExceptionInCallableRule\FirstClassCallableTest::allowThrow' => [1],
'ForbidCheckedExceptionInCallableRule\ArrowFunctionTest::allowThrow' => [0],
'ForbidCheckedExceptionInCallableRule\ArrowFunctionTest::__construct' => [0],
'allowed_function' => [0],
'ForbidCheckedExceptionInCallableRule\allowed_function' => [0], // not really needed as functions are always considered immediately invoked (https://phpstan.org/writing-php-code/phpdocs-basics#callables)
'ForbidCheckedExceptionInCallableRule\allowed_function_not_immediate' => [0],
],
);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Rule/data/ForbidCheckedExceptionInCallableRule/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function throwing_function() {}

function allowed_function(callable $callable) {}

/**
* @param-later-invoked-callable $callable
*/
function allowed_function_not_immediate(callable $callable) {}

interface CallableTest {

public function allowThrowInInterface(callable $callable): void;
Expand Down Expand Up @@ -96,6 +101,12 @@ public function testPassedCallbacksA5(): void
$this->allowThrow(42, throwing_function(...));
}

public function testPassedCallbacksA6(): void
{
allowed_function(throwing_function(...));
allowed_function_not_immediate(throwing_function(...));
}

public function testPassedCallbacksA6(): void
{
$this->immediateThrow(
Expand Down Expand Up @@ -510,3 +521,5 @@ private function throws(): void
throw new CheckedException();
}
}