title: How to force an environment variable to a certain value inside phpunit test?
body: <p>In my phpunit I have this configuration:</p>
  
  <pre><code>&lt;php&gt;
      &lt;env name="ENVIRONMENT" value="test"/&gt;
  &lt;/php&gt;
  </code></pre>
  
  <p>I worked under the false assumption that it always would set the environment variable to the value <code>test</code>. Yet when the system already has the variable set, then it prefers the already existing value.</p>
  
  <pre><code>$ export ENVIRONMENT=GNARF
  $ phpunit -c test/phpunit.xml
  </code></pre>
  
  <p>So inside the tests the value of <code>env('ENVIRONMENT')</code> will be <code>"GNARF"</code> even though I expected <code>"test"</code>.</p>
  
  <p>Is there a way to make phpunit to treat the <code>env</code> setting not as a default but rather as the definite value it should be using?</p>
  
  <p>I also would like to avoid calling phpunit in a certain way just to get the right env variables. </p>
  
  <p>So while this works:</p>
  
  <pre><code>ENVIRONMENT="test";./vendor/bin/phpunit -c tests/phpunit.xml
  </code></pre>
  
  <p>I rather configure it inside the <code>phpunit.xml</code> file if possible.</p>