pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: PHPStan does not pick up type information for Pest architecture tests

Open biinari opened this issue 4 months ago • 0 comments

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

  1. Install a fresh Laravel app, add Pest, add phpstan/phpstan

  2. Add a test that uses arch()->preset() or arch()->expect(), e.g.:

    <?php
    // tests/Arch.php
    
    arch()
        ->expect('App')
        ->toUseStrictTypes();
    
    arch()
        ->preset()
        ->php();
    
  3. Run phpstan on this file with level 2 or higher:

    vendor/bin/phpstan analyse tests/Arch.php --level=2
    

    Outputs:

    ------ ------------------------------------------------------------------- 
      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.

biinari avatar Oct 15 '25 04:10 biinari