1 | initial version |
In PHPUnit, you can set the value of an environment variable while running a test by utilizing the putenv()
function.
Here's an example code snippet:
public function testSomething()
{
putenv('MY_ENV_VAR=some_value');
// your test code here
}
In this example, we set the value of the MY_ENV_VAR
environment variable to 'some_value'
using the putenv()
function just before the test code is executed.
Note that changes made to environment variables with putenv()
during a test will only persist for the duration of the test. Once the test is complete, any changes made to the environment variables will be discarded.