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

expects() cannot be chained #1137

Open
Bilge opened this issue Aug 7, 2021 · 1 comment
Open

expects() cannot be chained #1137

Bilge opened this issue Aug 7, 2021 · 1 comment

Comments

@Bilge
Copy link
Contributor

Bilge commented Aug 7, 2021

Although we can chain shouldReceive(), the same cannot be said for the new expects() API.

\Mockery::mock(Foo::class)
  ->shouldReceive('foo')
  ->shouldReceive('bar')
  ->getMock() // OK
\Mockery::mock(Foo::class)
  ->expects('foo')
  ->expects('bar') // TypeError 
  ->getMock() 

TypeError : call_user_func_array(): Argument #1 ($callback) must be a valid callback, class Mockery\Expectation does not have a method "expects"

@freiondrej-lmc
Copy link

@Bilge I believe this is intentional, because the "more correct" way in your first example would be

\Mockery::mock(Foo::class)
  ->shouldReceive('foo')
  ->getMock()
  ->shouldReceive('bar')
  ->getMock()

but for whatever reasons it was not necessary, whereas with expects() it is now indeed necessary to use getMock(). But maybe I'm wrong.

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

2 participants