Skip to content
Latchkey

PHPUnit Coverage Threshold Not Met - Fix Failing Coverage Gates in CI

A CI step enforces a minimum coverage percentage (via a wrapper like coverage-check, a --coverage-text parse, or a tool gate). New untested code drops coverage below that floor, so the gate fails even though every test passes.

What this error means

All tests are green, but the pipeline fails on a coverage check reporting that coverage is below the required percentage. The drop usually traces to recently added code with no accompanying tests.

CI log
Generating code coverage report ... done
Lines:   78.40% (below required minimum 80.00%)

Coverage check failed: 78.40% is less than the minimum 80%.

Common causes

New code added without tests

Untested branches or methods dilute the overall percentage, pushing it under the configured floor.

A file newly included in the coverage scope

Widening the coverage include paths (or removing an exclude) brings previously-ignored, untested code into the denominator.

How to fix it

Find the uncovered lines and test them

Generate a readable report and target the gaps.

Terminal
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-html build/cov
# open build/cov/index.html to see uncovered lines

Scope coverage to the right source

Make sure the coverage include/exclude reflects code you intend to measure.

phpunit.xml
<!-- phpunit.xml -->
<source>
  <include><directory>src</directory></include>
  <exclude><directory>src/Generated</directory></exclude>
</source>

Change the threshold only deliberately

  1. Prefer adding tests over lowering the floor.
  2. If the floor is genuinely wrong, change it with team agreement, not silently.
  3. Track any temporary lowering with an issue to restore it.

How to prevent it

  • Add tests alongside new code so coverage does not regress.
  • Keep coverage include/exclude scoped to meaningful source.
  • Review threshold changes the same way you review code.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →