4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelでAPP_URLをちゃんと設定しないとHTTPテストが失敗する

Posted at

発生した事象

Laravelのバージョンを5.1から5.4にアップデートしたら、HTTPテストが通らなくなってしまった。

テストコード

public function testAPI()
{
    $this->json('get', '/api/xxxx', [], [])
        ->assertStatus(200);
}

テスト結果

1) Tests\APITest::testAPI
Expected status code 200 but received 404.
Failed asserting that false is true.

原因

.env で APP_URL を以下のように設定していたのが原因だったようだ。

APP_URL=localhost

対応

.env の APP_URL は http scheme も含めないといけない

APP_URL=http://localhost
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?