このような API 呼び出しをテストするために Laravel で単体テストを行っていますが、実行時に次のランタイム エラーが発生します。
RuntimeException: A facade root has not been set.
setup メソッドでユーザーを作成し、tearDown() メソッドで再度削除してから、認証テストを実行します。
まず、私がやりたいことを行うためのより良い方法はありますか? たとえば、データベースに触れずにユーザーを嘲笑しますか? 次に、「ファサードルート」を設定するにはどうすればよいですか、またはそのエラーは正確には何を意味しますか? ダミーユーザーを作成する目的でその特定のフィールドをハッシュすることを気にしないようにしましたが、エラーはモデルに移動するようで、(再び) Hash ファサードクラスが使用されます。
これらのファサードをテストで使用できるように、環境をセットアップするための追加の手順はありますか?
前もって感謝します。
use Illuminate\Support\Facades\Hash;
/*
* Make sure the structure of the API call is sound.
*/
public function testAuthenticateFailed()
{
$this->json('POST', $this->endpoint,
[ 'email' => 'test@test.com',
'password' => 'password',
])
->seeJsonStructure([
'token'
]);
}
//create a user if they don't already exist.
public function setup()
{
$user = User::create([
'company_id' => 9999,
'name'=>'testUser',
'email' => 'test@test.com',
'password' => 'password',
'hashed_email' => Hash:make('test@test.com'),
]);
}