11
6

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 で PHPUnit 実行時に .env.testing を見てくれない?

Posted at

環境

  • PHP 7.1
  • Laravel 5.7
  • PHPUnit 7.5.15

起きた事

  • .envAPP_ENV=local.env.testingAPP_ENV=testing を記述してある状態。
  • phpunit.xml では特に APP_ENV の指定なし。
  • PHPUnit の処理中で config('app.env') を実行したら local が返ってしまった。

原因と対処

.env の値がキャッシュされてました。

せっかくなので、 TestCase.phpsetUp() で全てのキャッシュを消すようにしました。

~/tests/TestCase.php
    public function setUp()
    {
      parent::setUp();

      Artisan::call('cache:clear');
      Artisan::call('config:clear');
      Artisan::call('optimize:clear');
      Artisan::call('route:clear');

      // ...
    }

11
6
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
11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?