나는 조커로 laravel에서 내 컨트롤러 동작을 테스트하려고합니다. 나는이처럼 내 생성자에서 DI를 사용Laravel 컨트롤러를 모의로 테스트합니다.
http://culttt.com/2013/07/15/how-to-structure-testable-controllers-in-laravel-4/
: 난 이미 여기에이 튜토리얼을 읽어
public function __construct(User $user, Cartalyst\Sentry\Sentry $sentry)
{
$this->user = $user;
$this->sentry = $sentry;
...
}
내 문제는 내 컨트롤러에 다음 코드입니다 :
public function getShow($id)
{
try
{
// this is a problem, because I dont know how to tell mockery, to mock the
// Userprovider
$user = $this->sentry->getUserProvider()->findById($id);
// this is not a problem for me
$this->user->all();
...
나는 Mockery와 모의 틀로 작업하려고합니다. 내 질문은 $ this-> sentry-> getUserProvider()와 같은 호출을 조롱하는 방법이다 (Cartalyst Sentry는 고급 인증 번들이다).
$this->user = Mockery::mock('Eloquent', 'User');
어떤 생각이 어떻게 Userprovider 조롱 아니면 다른 방법으로이 문제를 처리해야 : 사용자 모델을 조롱하기 위해 내가 쓰기? ID에 따라 사용자 세부 정보를 얻으면 UserController를 테스트하고 싶다.
보초를 조롱하고 조롱 한 userProvider를 반환하게하십시오. '$ sentryMock-> shouldReceive ('getUserProvider') -> times (1) -> andReturn ($ userProviderMock); ' – Mike