简体   繁体   中英

How to access env variables from phpunit.xml rather than app config file

Note: It is important to understand that the way the constants in my problem are defined are significantly different to those in the question flagged to be a duplicate of my question, because mine are config file oriented as opposed to env file oriented.

I am writing integration test cases where I don't want to provide my app key from the config file but want it to get accessed from a phpunit.xml file.

But it still accesses the keys from a config file and not from a phpunit.xml file. I have tried the force element as well. What needs to be done in this regard?

Config file:

 <?php

 return [
    'KEY' => env('Test', ''),
    'DATA' => env('Test1', '')
 ];

phpunit.xml file:

 <php>
     <env name="Test" value="foo" />
     <env name="Test1" value="secret"/>
 </php>

Try this:

<php>
    <env name="APP_ENV" value="Test"/>
</php>

Source: How to specify a different .env file for phpunit in Laravel 5?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM