私はそれを実行しているときしかし、私は、次のランタイムエラーを取得しています、このようになりますAPI呼び出しをテストするためのLaravelのユニットテストを持っている:PHPUnitのLaravelハッシュが利用できない
RuntimeException: A facade root has not been set.
私は、ユーザーを作成していますsetupメソッドで、tearDown()メソッドで再度削除する予定で、次にmy auth testを実行します。
まず、私がしたいことをするためのよりよい方法がありますか?たとえば、データベースに触れることなくユーザーを嘲笑しますか?第二に、どのように私は 'ファサードルート'を設定するか、そのエラーはどういう意味ですか?私はダミーユーザーを作成する目的でその特定のフィールドをハッシュしないようにしてみましたが、エラーはモデルに移動しているように見えます。ここで(再び)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' => '[email protected]',
'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' => '[email protected]',
'password' => 'password',
'hashed_email' => Hash:make('[email protected]'),
]);
}
LaravelのTestCaseクラスを拡張し、あなたのテストですか? –
@RossWilson yep、TestCaseを延長 – Paul