4

首先我试过这个

$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.
4

1 回答 1

5

你可以尝试添加

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

Sentry::shouldReceive('getUser')
      ->once()
      ->andReturn($userInst);
于 2014-01-17T08:47:51.283 回答