11
8

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.

phpunit.xmlの設定が反映されない

Posted at

問題:phpunit.xmlが反映されない

        <env name="APP_ENV" value="testing" />

Laravelの開発で phpunit.xml の環境名の上書きを下記のテストで確認したところ、反映されませんでした。

tests\Unit\DemoTest.php

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class DemoTest extends TestCase
{
    /**
     * @test
     */
    public function 環境確認()
    {
        $this->assertEquals('testing', $this->app->environment());
    }
}
   │ Failed asserting that two strings are equal.
   │ --- Expected
   │ +++ Actual
   │ @@ @@
   │ -'testing'
   │ +'local'
   │
   │ /home/vagrant/code/demo-vue-practice/tests/Unit/DemoTest.php
   │

Time: 2.09 seconds, Memory: 16.00 MB

解決策: force=trueを設定

        <env name="APP_ENV" value="testing"  force="true"/>

またphp artisan config:clearも行う必要がありそうでした。
https://stackoverflow.com/questions/48227569/failure-to-set-app-env-to-testing-for-unit-testing-in-laravel-5-5

これで先のテストが通りました。

Unit\DemoTest
 ✔ 環境確認

Time: 2.07 seconds, Memory: 16.00 MB

以上です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?