Skip to content

test: raise the mutation score to 95.56 % - #27

Merged
ogorzalka merged 4 commits into
mainfrom
mut/query
Nov 16, 2026
Merged

ogorzalka merged 4 commits into
mainfrom
mut/query

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Raises the mutation score of the package from 85.47 % to 95.56 % (Pest --mutate --everything --covered-only, 516 mutants, 23 left), with tests only: nothing outside tests/ changes and no existing test is weakened.

Why this repository first. Its mutation run did not even start: tests/helpers/wp.php was loaded twice. Pest loads tests/Helpers/*.php by itself, the folder was spelled helpers, and Pest.php also included the files. On macOS (a case-insensitive file system) both paths are the same folder, so the file was declared twice (Cannot redeclare function wp_parse_str()), on Linux the folder Helpers does not exist and nothing showed. The folder is now tests/Helpers, as Pest expects, and the include lines are gone.

What the survivors said.

  • ->not->toHaveKeys([...]) passes as soon as one of the keys is missing, so ten assertions never proved that offset, paged and the like were absent. A toLackKeys expectation (in tests/Pest.php) fails if any of the keys is present, and replaces them. They all passed: there was no hidden defect, only weak assertions.
  • Allow-lists were never pinned value by value (term fields, user fields and their case-insensitive matching, user and site search columns, tax fields), nor the exact text of the errors they raise.
  • Date clauses (before only, after only, the parts of a date, the h alias for the hour), value types (0 and 1 are booleans before they are numbers, signed below zero, the widest numeric type of a list), exists() ignoring paging and sticky posts, pluck() and exists() not asking for a total, lists whatever keys WordPress gives them, a type written in capitals.

What stays. 23 mutants, mostly equivalent: a cast on a value the test doubles already type (found_posts, get_total()), ucfirst() on a PHP class name (case-insensitive), array_values() on a list already built from array_unique() (key 0 always survives), NullableType (the fallback type is CHAR too), searchById() re-setting the default field.

New files: tests/Feature/AllowedValuesTest.php (56 tests) and tests/Feature/EdgeCasesTest.php (53). 429 tests pass, in random order (3 seeds) and in a Linux container (php:8.4-cli). Pint is clean. The .harness.json ratchet is not touched: the workflow does not run --mutation yet.

@ogorzalka
ogorzalka merged commit f4ea2c6 into main Nov 16, 2026
17 checks passed
@ogorzalka
ogorzalka deleted the mut/query branch November 16, 2026 17:21
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.

1 participant