phpstan-prophecy
phpstan-prophecy copied to clipboard
phpstan returning Cannot call method willReturn() on array<>.
Steps required to reproduce the problem :
Not sure this is an "issue' however, phpstan considers a call such as $this->packageRepositoryProphecy->findModules()->willReturn([]); problematic since findModules most often that not return something which is not an object.
Expected Result
Installing phpstan-phrophecy should tell phpstan to ingore such as it is a prophecy.
Actual Result
Not ignored.
More context : https://github.com/phpstan/phpstan/discussions/4599
The issue is your type PackageRepository|ObjectProphecy on your packageRepositoryProphecy. That object does not contain a PackageRepository (and calling findModules on a PackageRepository will indeed return an array so phpstan is right about the reported issue).
Your phpdoc should use @var ObjectProphecy<PackageRepository> instead.
@jseparovic1 this should be closed as the solution is provided in my comment from 2021
As I'm not maintainer of this library I'm forwarding friendly ping to @alexander-schranz to take a look.
oh sorry. I messed up who was the new maintainer