`assertArrayHasKey()` does not accept `ArrayAccess` implementations with a specific value type when test code is analysed with PHPStan at level 9 · Issue #6833 · sebastianbergmann/phpunit · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
assertArrayHasKey() does not accept ArrayAccess implementations with a specific value type when test code is analysed with PHPStan at level 9 #6833
Methods like assertArrayHasKey accept array<mixed>|ArrayAccess<array-key, mixed> as subject array. The TValue template in ArrayAccess however is invariant, which makes phpstan unhappy at level 9 when analyzing code that passes an ArrayAccess implementation containing anything but mixed.
Using call-site variance (ArrayAccess<array-key, covariant mixed>) these methods can accept ArrayAccess objects with any value type (as it should, since it only checks the keys).
changed the title [-]Use call-site variance in assertion methods like assertArrayHasKey[/-][+]`assertArrayHasKey()` does not accept `ArrayAccess` implementations with a specific value type when test code is analysed with PHPStan at level 9[/+]on Jul 16, 2026
Activity
[-]Use call-site variance in assertion methods like assertArrayHasKey[/-][+]`assertArrayHasKey()` does not accept `ArrayAccess` implementations with a specific value type when test code is analysed with PHPStan at level 9[/+]Merge branch '13.2'
Closes sebastianbergmann#6833
Merge branch '12.5' into 13.2