How can I specify Partial Mockup for Laravel Facade?

I tried this first

$mock = m::mock('Cartalyst\Sentry\Facades\Laravel\Sentry');
$mock->shouldReceive('getUser')->once()->andReturn($userInst);

But it gave me

Fatal error: Cannot redeclare Mockery_1964315998_Cartalyst_Sentry_Facades_Laravel_Sentry::shouldReceive()

So, I found out that Laravel Facades already implements Mockery, so I tried right on the facade.

Sentry::shouldReceive('getUser')->once()->andReturn($userInst);

But now the problem is that it does not find other functions for these objects, in fact, I need the behavior of the partial layout here, but I do not see how to say it.

BadMethodCallException: Method Mockery_2115409749_Cartalyst_Sentry_Sentry::check() does not exist on this mock object

This is what I need

A traditional partial mock defined ahead of time which methods of a class are to be mocked and which are to left unmocked (i.e. callable as normal). The syntax for creating traditional mocks is:

$mock = \Mockery::mock('MyClass[foo,bar]');
In the above example, the foo() and bar() methods of MyClass will be mocked but no other MyClass methods are touched. You will need to define expectations for the foo() and bar() methods to dictate their mocked behaviour.
+3
source share
1 answer

you can try adding

Sentry::getFacadeRoot()->makePartial();

after

Sentry::shouldReceive('getUser')
      ->once()
      ->andReturn($userInst);
+4
source

All Articles