相关疑难解决方法(0)

如何在Laravel 4中模拟Auth类?

我正试图让我的AuthController可测试.我从注入Auth类开始,所以我可以在我的测试中模拟它:

public function __construct(Auth $auth)
{
    $this->auth = $auth;
}
Run Code Online (Sandbox Code Playgroud)

然后我在检查登录是否成功时使用注入的类:

public function postLogin()
{
    // instead of Auth::attempt(Input::all())
    if ($this->auth->attempt(Input::all()) {
        return 'you are logged in!';
    } else {
        return 'login failed!';
    }
}
Run Code Online (Sandbox Code Playgroud)

当我提交登录表单时,我收到一个错误,即该Auth::attempt方法未定义:

FatalErrorException: Error: Call to undefined method Illuminate\Support\Facades\Auth::attempt() ...
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我在模型中看到了这种精确的技术,但显然它不适用于Auth类.

laravel laravel-4

3
推荐指数
1
解决办法
4094
查看次数

标签 统计

laravel ×1

laravel-4 ×1