← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Test Coverage Types

testing PHP 7.0+ Intermediate

Also Known As

code coverage mutation testing branch coverage Infection PHP

TL;DR

Line coverage (lines executed), branch coverage (if/else paths), mutation testing (do tests detect actual bugs) — each measures a different aspect of test quality.

Explanation

Line coverage: percentage of source lines executed by tests — easiest to achieve, easiest to game (execute a line without asserting its output). Branch coverage: percentage of if/else/switch branches taken — more meaningful than line coverage. Mutation testing (Infection PHP): automatically modifies code (change + to -, flip conditions) and checks if tests fail — the mutation score reveals whether tests actually detect changes. 100% line coverage with no assertions = 100% line coverage, 0% mutation score.

Common Misconception

100% code coverage means the code is fully tested — 100% line coverage can be achieved with tests that execute every line but assert nothing; mutation testing reveals whether tests actually catch bugs.

Why It Matters

A team targeting 100% line coverage without mutation testing has false confidence — tests that execute but don't assert provide zero protection against regressions or logic errors.

Common Mistakes

  • 100% line coverage as the only quality metric
  • Tests that cover code without asserting outcomes
  • Testing implementation details instead of observable behaviour
  • Not running mutation testing on critical business logic paths

Code Examples

✗ Vulnerable
// 100% line coverage, 0% useful assertions:
public function testCalculateTotal(): void {
    $cart = new Cart();
    $cart->add(new Item('Widget', 9.99));
    $total = $cart->calculateTotal();
    // No assertion — executes the code but checks nothing!
    $this->assertTrue(true); // 100% line coverage, 0% mutation score
}
✓ Fixed
// Meaningful coverage with real assertions:
public function testCalculateTotalAppliesVat(): void {
    $cart = new Cart(new VatCalculator(0.20));
    $cart->add(new Item('Widget', 10.00));
    $this->assertSame(12.00, $cart->calculateTotal(), '20% VAT not applied');
}
// Run mutation testing:
// vendor/bin/infection --min-msi=80 --min-covered-msi=90

Added 16 Mar 2026
Edited 5 Apr 2026
Views 26
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 8 Perplexity 7 Ahrefs 2 Unknown AI 2 Google 1 SEMrush 1
crawler 21
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Use branch coverage (not line coverage) as your primary metric — line coverage misses untested if/else branches; mutation testing reveals if your assertions actually verify behaviour
📦 Applies To
PHP 7.0+ any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
100% line coverage but critical branches untested; coverage met by running code not asserting results; no mutation testing to verify coverage quality
Auto-detectable: ✓ Yes phpunit xdebug pcov infection
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File Tests: Update

✓ schema.org compliant