'How can I specify Partial Mockup for a Laravel Facade?

First I tried this

$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 then I found out the Laravel Facades already implement Mockery so I tried directly on the facade.

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

But now the problem is it's not finding the other functions for that objects essentially I need the behavior of a partial mockup here but I don't see how do tell 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.


Solution 1:[1]

You can try this:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Viet Nguyen