phpstan-mockery
phpstan-mockery copied to clipboard
Call to an undefined method Mockery\Expectation::shouldReceive() after chaining onto `andReturn`
similar to https://github.com/phpstan/phpstan-mockery/issues/3
I am still experiencing the following code as failing on 0.11.2
$mock = Mockery::mock(Something::class);
$mock
->shouldReceive('foo')
->andReturn(null)
->shouldReceive('bar');
Currently, the second shouldReceive call will trigger this error: Call to an undefined method Mockery\Expectation::shouldReceive().
I confirm the bug is still present as of phpstan 1.0.*
A temporary solution is to use an ignore comment to silence the error:
/** @phpstan-ignore-next-line */
$this->partialMock(User::class)
->shouldReceive('plan')
->andReturn(Plan::where('id', Plan::FREE)->firstOrFail());
It seems this is failing because shouldReceive() has more than one possible return type, so this can be fixed by decoupling the chain and using an annotation:
$mock = Mockery::mock(Something::class);
/** @var \Mockery\Expectation $mock */
$mock->shouldReceive('foo');
$mock->andReturn(null);
This issue still exist
I'm having this problem :(