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

[Proposal] Allow multiple mock expectations on a Facade #364

Closed
karptonite opened this issue Feb 18, 2013 · 2 comments
Closed

[Proposal] Allow multiple mock expectations on a Facade #364

karptonite opened this issue Feb 18, 2013 · 2 comments

Comments

@karptonite
Copy link
Contributor

Not sure if this is a bug or a proposal.
It seems like it should be possible to add multiple expectations to a Facade.
You can do it now like this:

$mock = View::shouldReceive('make')->andReturn(\Mockery::self())->getMock();
$mock->shouldReceive('with')->andReturn(self::RESPONSE);

But it would be cleaner, I think, if you could do it like this:

View::shouldReceive('make')->andReturn(\Mockery::self());
View::shouldReceive('with')->andReturn(self::RESPONSE);

Currently, that will throw an error "Cannot redeclare Mockery_...".

This could be solved if shouldReceive first checked to see if there is already a mock of this facade, and used that mock if there is one.

public static function shouldReceive()
{
  $name = static::getFacadeAccessor();

  if (isset(static::$resolvedInstance[$name]) && strpos(get_class(static::$resolvedInstance[$name]), 'Mockery') !== false)
  {
    $mock = static::$resolvedInstance[$name];
  }
  else
  {
    static::$resolvedInstance[$name] = $mock = \Mockery::mock(get_class(static::getFacadeRoot()));

    static::$app->instance($name, $mock);           
  }

  return call_user_func_array(array($mock, 'shouldReceive'), func_get_args());
}

There is probably a cleaner way of checking if there is a mock, but something like this should allow multiple expectations with a cleaner syntax.

@niallobrien
Copy link

I like this implementation.

@karptonite
Copy link
Contributor Author

I've replaced this with this pull request:
#539
it seemed more like a bug that a proposal for a new feature anyway.

joelharkes added a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
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