pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: PHPStan throws error when calling `expect` on higher order test

Open calebdw opened this issue 2 years ago • 3 comments

What Happened

When I write a test in the form of:

it('...')
    ->expect(fn () => ...))
    ->toBeTrue();

PHPStan fails with the following message:

Call to an undefined method Pest\PendingCalls\TestCall::expect().

How to Reproduce

see above

Sample Repository

No response

Pest Version

2.24.1

PHP Version

8.2.10

Operation System

Linux

Notes

No response

calebdw avatar Oct 30 '23 17:10 calebdw

Still a problem in PestPHP 3 unfortunately :(

rvoortman avatar Sep 17 '24 20:09 rvoortman

As a bandaid, I would suggest putting a // @phpstan-ignore-next-line above the offending code.

Read more: https://phpstan.org/user-guide/ignoring-errors#ignoring-in-configuration-file

If it's a lot of code, you can ignore a regex of the issue in the configuration file (see: https://phpstan.org/user-guide/ignoring-errors#ignoring-in-configuration-file).

danielh-official avatar Jan 26 '25 02:01 danielh-official

Thanks, but I'm aware that I can ignore the errors. Actually, I've just stopped analyzing test code with PHPStan, it's not really needed given that it's tested anyway

calebdw avatar Jan 26 '25 02:01 calebdw

@calebdw would love if you could come up with better phpstan experience for pest.

nunomaduro avatar Jul 30 '25 21:07 nunomaduro