5 months ago

Access 2 values from .env in phpunit.xml (without a new .env.testing file)

Posted 5 months ago by connecteev

I am trying to ** read ** values from my .env file and access them in phpunit.xml Is there a way to do this? I do not want to define a new .env.testing file and have to maintain it separately, I just want to override 2 variables in my .env file.

I have tried:

        <server name="DB_CONNECTION" value="config('DB_CONNECTION_PHPUNIT')"/>
        <server name="DB_CONNECTION" value="env('DB_CONNECTION_PHPUNIT')"/>

phpunit errors out with:

4) Tests\Feature\Api\PostsApiTest::non_authenticated_users_cannot_access_the_following_endpoints_for_the_posts_api
InvalidArgumentException: Database connection [env('DB_CONNECTION_PHPUNIT')] not configured.

Any way to do this?

Please sign in or create an account to participate in this conversation.