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 を実装していることがわかったので、直接 Facade を試してみました。

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 に答える