Appearance
date: 2026-06-13 tags: [mutation, pest, casts, eloquent, testing-technique] status: active graduated_to: CLAUDE.md (Mutation Testing Policy)
A casts() method mutant is killable — it's executed code, not a declaration line
Symptom — an AlwaysReturnEmptyArray mutant on Person::casts()'s return (and RemoveArrayItem on each cast entry) survived as UNTESTED. The graduated declaration-line learning (2026-06-04-pcov-uncovers-declaration-lines.md) lists "casts() returns" as un-killable, so the first instinct was a reasoned @pest-mutate-ignore.
Root cause — that earlier learning conflated two different things. The $casts property is resolved at class-load and pcov never marks it executed → genuinely un-killable. But this project uses the casts() method (per .claude/rules/php-laravel.md), and a method body runs every time a model hydrates an attribute — pcov marks it covered, so pest can attribute a killing test. The cast's effect is observable: if casts() returns [], birthday_day comes back as the raw string '15' instead of an int.
Fix — replaced the ignore with a behavioural test that hydrates from string input and asserts a strict-typed result: Person::factory()->create(['birthday_day' => '15', ...]) then ->birthday_day->toBe(15) (strict int, not '15'). Killed the casts() return mutant and all three per-entry mutants in one test — sprint/455 commit 2948790, tests/Feature/PersonBirthdayTest.php ("casts birthday parts submitted as strings to integers"). Verified: the warm composer mutate run reports 0 Person survivors with no @pest-mutate-ignore on casts(); under the old "un-killable" prediction it would show as an UNCOVERED survivor.
Guard — CLAUDE.md Mutation Testing Policy updated: casts() returns removed from the un-killable list, with the killable-method exception spelled out (strict-type assertion from string input). This is the same technique as 2026-06-04-kill-dto-casts-by-hydrating-raw-types.md, now extended from app/Data DTO hydrators to Eloquent model casts(). Reach for the ignore only on the true declaration forms (const, the $casts/$fillable/$hidden/$attributes properties, PHP attributes).