我試圖讓我的AuthController
可測試。我開始通過注入驗證類,所以我可以在我的測試嘲笑它:我如何模擬Laravel 4中的Auth類?
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
然後我用的是注射類後,當我檢查,如果登錄成功:
public function postLogin()
{
// instead of Auth::attempt(Input::all())
if ($this->auth->attempt(Input::all()) {
return 'you are logged in!';
} else {
return 'login failed!';
}
}
當我提交我的登錄表單,我得到了Auth::attempt
方法沒有定義的錯誤:
FatalErrorException: Error: Call to undefined method Illuminate\Support\Facades\Auth::attempt() ...
我在做什麼錯?我在模型中看到了這個exact technique,但顯然它不適用於Auth類。
謝謝!我認爲這是比這低的水平。我試着在UserProviderInterface的測試中嘗試創建一個App:instance(...),現在我再次觀看了這個視頻,但這樣做更有意義。 – 2013-04-07 04:14:57