[Bug]: PHPStan does not pick up type information for Pest architecture tests
What Happened
PHPStan is unable to find methods for arch() in Pest architecture tests.
This results in errors found by phpstan when writing architecture tests.
How to Reproduce
-
Install a fresh Laravel app, add Pest, add
phpstan/phpstan -
Add a test that uses
arch()->preset()orarch()->expect(), e.g.:<?php // tests/Arch.php arch() ->expect('App') ->toUseStrictTypes(); arch() ->preset() ->php(); -
Run phpstan on this file with level 2 or higher:
vendor/bin/phpstan analyse tests/Arch.php --level=2Outputs:
------ ------------------------------------------------------------------- Line Arch.php ------ ------------------------------------------------------------------- 4 Call to an undefined method Pest\PendingCalls\TestCall::expect(). 🪪 method.notFound 8 Call to an undefined method Pest\PendingCalls\TestCall::preset(). 🪪 method.notFound ------ -------------------------------------------------------------------
Sample Repository
No response
Pest Version
4.1.2
PHP Version
8.3.26
Operation System
Linux
Notes
It seems that PHPStan does not recognise multiple classes together in a @mixin doc tag separated by pipes |. Multiple @mixin tags seem to work fine though:
src/PendingCalls/TestCall.php:
/**
* @mixin HigherOrderCallables
* @mixin TestCase
* @mixin Testable
*/
This change would make phpstan pass the arch test file at max level.
I note psalm behaves similarly (though it adds a further complaint of using methods on classes marked as internal Pest\Support\HigherOrderCallables::expect and Pest\Preset::php after the suggested change to mixins).
I don't use PHPStorm so I can't easily check whether this would affect the similar issue for PHPStorm reported in #1242.