Skip to content

Fix: read the php-code-coverage 14 --coverage-php array format - #38

Open
joshdaugherty wants to merge 1 commit into
pestphp:5.xfrom
joshdaugherty:fix/coverage-php-14-array-format
Open

Fix: read the php-code-coverage 14 --coverage-php array format#38
joshdaugherty wants to merge 1 commit into
pestphp:5.xfrom
joshdaugherty:fix/coverage-php-14-array-format

Conversation

@joshdaugherty

Copy link
Copy Markdown

MutationTestRunner::run() reads the --coverage-php report with require and calls ->getData() on it. Since phpunit/php-code-coverage 14 that file returns an array, so every --mutate run on Pest 5 aborts with Call to a member function getData() on array.

Its codeCoverage entry is keyed relative to basePath, so those keys need rebasing too, or --covered-only reports 0 Mutations for 0 Files created and exits 0. Same handling core already has in Pest\Plugins\Tia\CoverageMerger; the object form keeps the old path.

Fixes pestphp/pest#1790

@yeapea

yeapea commented Jul 30, 2026

Copy link
Copy Markdown

Independently reproduced and verified this against pest-plugin-mutate v5.0.0 (ref fc4a0b3d) on PHP 8.5 / PHPUnit 13.2.4 / php-code-coverage 14.2.3, both arms:

Without the patch — dies exactly where you describe:

➜ 116▕ ... $codeCoverage->getData()->lineCoverage());
Call to a member function getData() on array

With the patch applied, same command, same tree:

Mutating application files...
3 Mutations for 1 Files created

 RUN  app/Support/BatchSize.php
✓ Line 16: MaxToMin
✓ Line 16: DecrementInteger
✓ Line 16: IncrementInteger
Mutations: 3 tested
Score:     100.00%

The basePath rebasing is the half that matters most, and it is easy to miss. I had a two-line change ready that only swapped the read (Unserializer + ['codeCoverage']->lineCoverage()), and it would have produced 0 Mutations for 0 Files created and exit 0 — a run that reports success having tested nothing. That failure mode is worse than the crash it replaces, because a crash is loud and a green run over zero mutants is not. Thank you for handling it.

The instanceof CodeCoverage branch also keeps this working on the object form, so it is safe for anyone still on php-code-coverage 13.

For whatever it is worth to prioritisation: this blocks --mutate for every Pest 5 user with php-code-coverage 14, which is the default resolution today. In our case it left 30+ repositories unable to produce a mutation score at all.

@devfake

devfake commented Aug 1, 2026

Copy link
Copy Markdown

hope we can merge this fix asap 👍

@OmeBlues

OmeBlues commented Aug 3, 2026

Copy link
Copy Markdown

Confirming this fixes it, on pest 5.0.3 / pest-plugin-mutate 5.0.0 / php-code-coverage 14.2.4.

Please merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --mutate fails with "Call to a member function getData() on array" on Pest 5

4 participants