Skip to content

Commit

Permalink
Add php minimum coverage check to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjustein committed May 5, 2024
1 parent 63a78f6 commit dd6e4ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ jobs:

- name: Run tests suite
run: |
php ./vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-xml=logs/coverage --log-junit=logs/coverage.junit.xml -d --min-coverage=100
php ./vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-xml=logs/coverage --log-junit=logs/coverage.junit.xml
- name: Ensure every line is covered by tests
run: |
php tests/phpunit-coverage.php 100
- name: Run infection mutation testing
run:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"vimeo/psalm": "^5.23",
"infection/infection": "^0.27.11"
"infection/infection": "^0.27.11",
"ext-simplexml": "*"
},
"autoload-dev": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit-coverage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$threshold = (double) $argv[1];

$coverage = simplexml_load_file(__DIR__.'/../coverage.xml');
$ratio = (double)(($coverage->project->metrics["coveredelements"]/$coverage->project->metrics["elements"])*100);

echo "Coverage: $ratio% of $threshold%\n";

if ($ratio < $threshold) {
echo "Coverage under $threshold%!\n";
exit(-1);
}

echo "Coverage above $threshold%!\n";

0 comments on commit dd6e4ed

Please sign in to comment.