【Laravel】テストで困ったこと
・これがうまくいかなくて悩んでた…
tests>Feature>AuthTest.php
▼修正前
/** @test index*/
public function 正しいパスワードの場合()
{
$response = $this->get('/');
$response->assertStatus(200);
// ログインする
$response = $this->post('/', ['email' => $this->user->email, 'password' => 'abcd1234']);
// このユーザーがログイン認証されているか
$this->assertAuthenticatedAs($this->user);
}
▼修正後
// ログインする
ログインページのURLは「/」だが、
ログインするためには「/api/login」へのPOSTが必要!!
Route::post('/login', [CookieAuthenticationController::class, 'login']);