2

laravel 4で引数を使用してファサードをモックするにはどうすればよいですか? たとえば、ユーザーコントローラーと「ログイン」メソッドをテストしようとしています。

私のコントローラーメソッド

public function login(){

    $this->beforeFilter('guest');

    $creds = array(
        'email'    => Input::get('email'),
        'password' => Input::get('password'),
    );

    if(Auth::attempt($creds, true)){
        return "successful";
    } else {
        return Redirect::to('user/login')->with('error', true);
    }
}

動作しないリダイレクト テスト

    public function testPostLogin(){

        Redirect::shouldReceive('to')->once()->with('error', true);

        $response = $this->action('POST', 'UserController@login');

        $this->assertRedirectedTo('user/login');

    }

次の例外が発生しています。「user/login」パラメーターを Redirect モックに挿入する方法がわかりません

Mockery\Exception\NoMatchingExpectationException : Illuminate\Routing\Redirector::to("user/login") に一致するハンドラが見つかりません

4

1 に答える 1

10

Auth理論的には、クラスをモックするだけです。

これを試して:

Auth::shouldReceive('attempt')->once()->andReturn(true);
于 2013-05-21T20:04:51.747 に答える