Code Coverage

Code Coverage and What It Does Not Prove

Code coverage records which lines of src/ ran during the tests. The driver is PCOV 794 (github.com/krakjoe/pcov (https://github.com/krakjoe/pcov 794 ), sudo apt install php8.5-pcov, 1.0.12 on Ubuntu 26.04 225 ), or Xdebug 16,266 enabled per command with php -d zend_extension=xdebug -d xdebug.mode=coverage (Subsection 4.21.2); keep both off production servers. With PCOV loaded, vendor/bin/phpunit --testsuite unit --coverage-text adds a report:

Output of 217
...
 Summary:
  Classes: 66.66% (8/12)
  Methods: 74.07% (20/27)
  Lines:   73.43% (47/64)
Shop\Money
  Methods:  66.66% ( 4/ 6)   Lines:  81.81% (  9/ 11)
Shop\Order
  Methods:  66.66% ( 2/ 3)   Lines:  90.00% (  9/ 10)
Shop\ShippingRule
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
...

A method counts only when all its lines ran: Order falls short because no test adds a quantity of 0, Money because none mixes currencies or parses a malformed price. Coverage cannot show whether a test would notice a bug. ShippingRule::cost() is one line, return $subtotal->cents >= 5000 ? new Money(0) : new Money(499);, and test rows for 1999 and 6000 cents cover it 100%, yet nothing checks exactly $50.00, so > in place of >= would pass. Use coverage to find untested code, never as a target.