{"id":20613215,"url":"https://github.com/robiningelbrecht/phpunit-coverage-tools","last_synced_at":"2025-08-21T17:32:08.967Z","repository":{"id":154062686,"uuid":"630864370","full_name":"robiningelbrecht/phpunit-coverage-tools","owner":"robiningelbrecht","description":"A PHPUnit extension to enforce minimum code coverage by using the clover XML report","archived":false,"fork":false,"pushed_at":"2024-08-27T11:30:14.000Z","size":246,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-11T17:22:32.653Z","etag":null,"topics":["codecoverage","phpunit","testing","website"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/robiningelbrecht/phpunit-coverage-tools","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robiningelbrecht.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-21T10:25:42.000Z","updated_at":"2024-08-27T11:29:48.000Z","dependencies_parsed_at":"2023-12-07T09:32:59.654Z","dependency_job_id":"35756b32-13b6-4cc1-b9e2-ab3928cbc69a","html_url":"https://github.com/robiningelbrecht/phpunit-coverage-tools","commit_stats":{"total_commits":50,"total_committers":2,"mean_commits":25.0,"dds":"0.020000000000000018","last_synced_commit":"8b83c59dd072b5e1c19729c468323f3f01e5cdae"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robiningelbrecht%2Fphpunit-coverage-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robiningelbrecht%2Fphpunit-coverage-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robiningelbrecht%2Fphpunit-coverage-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robiningelbrecht%2Fphpunit-coverage-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robiningelbrecht","download_url":"https://codeload.github.com/robiningelbrecht/phpunit-coverage-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230038685,"owners_count":18163305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codecoverage","phpunit","testing","website"],"created_at":"2024-11-16T11:09:09.754Z","updated_at":"2024-12-20T02:07:01.777Z","avatar_url":"https://github.com/robiningelbrecht.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ePHPUnit Coverage tools\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/robiningelbrecht/phpunit-coverage-tools/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/robiningelbrecht/phpunit-coverage-tools/actions/workflows/ci.yml/badge.svg\" alt=\"CI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/robiningelbrecht/phpunit-coverage-tools/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/robiningelbrecht/phpunit-coverage-tools?color=428f7e\u0026logo=open%20source%20initiative\u0026logoColor=white\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/robiningelbrecht/phpunit-coverage-tools\"\u003e\u003cimg src=\"https://codecov.io/gh/robiningelbrecht/phpunit-coverage-tools/branch/master/graph/badge.svg?token=O0qekKRyuc\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://phpstan.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/PHPStan-level%209-succes.svg?logo=php\u0026logoColor=white\u0026color=31C652\" alt=\"PHPStan Enabled\"\u003e\u003c/a\u003e\n\u003ca href=\"https://php.net/\"\u003e\u003cimg src=\"https://img.shields.io/packagist/php-v/robiningelbrecht/phpunit-coverage-tools?color=%23777bb3\u0026logo=php\u0026logoColor=white\" alt=\"PHP\"\u003e\u003c/a\u003e\n\u003ca href=\"https://phpunit.de/\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dependency-v/robiningelbrecht/phpunit-coverage-tools/phpunit/phpunit.svg?logo=php\u0026logoColor=white\" alt=\"PHPUnit\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/robiningelbrecht/phpunit-coverage-tools\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/robiningelbrecht/phpunit-coverage-tools?logo=packagist\u0026logoColor=white\" alt=\"PHPUnit\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\nThis extension allows you to enforce minimum code coverage by using the clover xml report from PHPUnit. \nBased on the given threshold the testsuite will exit ok if the coverage is higher than the threshold \nor exit with code 1 if the coverage is lower than the threshold. \nThis can be used in your continuous deployment environment or can be added to a pre-commit hook.\n\n## Installation\n\n```bash\n\u003e composer require robiningelbrecht/phpunit-coverage-tools --dev\n```\n\n## Configuration\n\nNavigate to your `phpunit.xml.dist` file and add following config to set default options:\n\n```xml\n\u003cextensions\u003e\n    \u003cbootstrap class=\"RobinIngelbrecht\\PHPUnitCoverageTools\\PhpUnitExtension\"\u003e\n        \u003cparameter name=\"exitOnLowCoverage\" value=\"0|1\"/\u003e\n        \u003cparameter name=\"cleanUpCloverXml\" value=\"0|1\"/\u003e\n    \u003c/bootstrap\u003e\n\u003c/extensions\u003e\n```\n## Usage\n\nJust run your testsuite like you normally would, but add following arguments:\n\n### --min-coverage=`[INTEGER]`\n\n```bash\n\u003e vendor/bin/phpunit --coverage-clover=path/to/clover.xml -d --min-coverage=100\n```\n\nWhen assigning an integer between 0 - 100, you enforce a minimum code coverage \nfor all your classes. In other words, the total coverage of your project has to be\nhigher than this threshold.\n\n### --min-coverage=`[path/to/min-coverage-rules.php]`\n\n```bash\n \u003e vendor/bin/phpunit --coverage-clover=path/to/clover.xml -d --min-coverage=\"path/to/min-coverage-rules.php\"\n```\n\nWhen referencing a PHP config file, you can configure more complex rules. \nThis allows you to be stricter for critical parts of your application and less strict\nfor parts of your app that are not that critical.\n\nFor example:\n\n```php\n\u003c?php \n\nuse RobinIngelbrecht\\PHPUnitCoverageTools\\MinCoverage\\MinCoverageRule;\n\nreturn [\n    new MinCoverageRule(\n        pattern: MinCoverageRule::TOTAL,\n        minCoverage: 20,\n        exitOnLowCoverage: true\n    ),\n    new MinCoverageRule(\n        pattern: 'RobinIngelbrecht\\PHPUnitCoverageTools\\*',\n        minCoverage: 80,\n        exitOnLowCoverage: false\n    ),\n    new MinCoverageRule(\n        pattern: 'RobinIngelbrecht\\PHPUnitCoverageTools\\Subscriber\\Application\\ApplicationFinishedSubscriber',\n        minCoverage: 100,\n        exitOnLowCoverage: true\n    ),   \n    new MinCoverageRule(\n        pattern: 'RobinIngelbrecht\\PHPUnitCoverageTools\\*CommandHandler',\n        minCoverage: 100,\n        exitOnLowCoverage: true\n    ),\n];\n```\n\nThis example will enforce:\n\n- A minimum total coverage of *20%*\n- A minimum coverage of *80%* for all classes in namespace `RobinIngelbrecht\\PHPUnitCoverageTools`, but will NOT `exit = 1` if it fails\n- *100%* code coverage for the class `ApplicationFinishedSubscriber`\n- *100%* code coverage for the classes ending with `CommandHandler`\n\n### --clean-up-clover-xml\n\nAdding this argument will clean up the generated clover file after the application has finished running.\n\n### Example when coverage is too low\n\n![Coverage FAIL](readme/fail-example.png)\n\n### Example when coverage generates warning\n\n![Coverage WARNING](readme/warning-example.png)\n\n### Example when coverage passes\n\n![Coverage WARNING](readme/success-example.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobiningelbrecht%2Fphpunit-coverage-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobiningelbrecht%2Fphpunit-coverage-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobiningelbrecht%2Fphpunit-coverage-tools/lists"}