首先我尝试了这个
$mock = m::mock('Cartalyst\Sentry\Facades\Laravel\Sentry');
$mock->shouldReceive('getUser')->once()->andReturn($userInst);
但它给了我
Fatal error: Cannot redeclare Mockery_1964315998_Cartalyst_Sentry_Facades_Laravel_Sentry::shouldReceive()
然后我发现Laravel Facades已经实施了Mockery所以我直接尝试了立面。
Sentry::shouldReceive('getUser')->once()->andReturn($userInst);
但现在的问题是它没有找到该对象的其他函数本质上我需要部分模型的行为,但我不知道如何告诉它。
BadMethodCallException: Method Mockery_2115409749_Cartalyst_Sentry_Sentry::check() does not exist on this mock object
这就是我需要的
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.
答案 0 :(得分:4)
您可以尝试添加
Sentry::getFacadeRoot()->makePartial();
之后
Sentry::shouldReceive('getUser')
->once()
->andReturn($userInst);