Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to an undefined method Mockery\Expectation::shouldReceive() after chaining onto andReturn #8

Open
mr-feek opened this issue Aug 13, 2019 · 5 comments

Comments

@mr-feek
Copy link

mr-feek commented Aug 13, 2019

similar to #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().

mr-feek added a commit to mr-feek/phpstan-mockery that referenced this issue Aug 13, 2019
@khalyomede
Copy link

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());

@StuartCowley
Copy link

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);

@lchhieu
Copy link

lchhieu commented Jun 27, 2023

This issue still exist

@davisenra
Copy link

I'm having this problem :(

@PatrickLubbers
Copy link

@StuartCowley your approach worked for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants