title: How to set $_SERVER[' '] variables when running phpunit tests through Jenkins
body: <p>I am trying to write unit tests for an application where a lot of code changes is not possible. Almost all the .php files in the code base uses some $_SERVER[''] variables like</p>
  
  <pre><code>require_once $_SERVER['DOCUMENT_ROOT'] . '/mainApi.php';
  </code></pre>
  
  <p>So now when I have to write and run PHPUnit test cases I have to somehow set these variables. 
  At present I am setting these variables in the user environment and then doing</p>
  
  <pre><code>$_SERVER['DOCUMENT_ROOT'] = getenv('DOCUMENT_ROOT');
  require_once $_SERVER['DOCUMENT_ROOT'] . '/mainApi.php';
  </code></pre>
  
  <p>Getting the server variables like this is working fine. I run my tests through commandline as <code>$ phpunit test.php</code>. </p>
  
  <p><strong>Ques1:</strong> Is it possible to set the $_SERVER variables while running the phpunit tests through commandline?</p>
  
  <p>I also have to run these unit tests through Jenkins and I am not able to set these server variable through ANT/build file. </p>
  
  <p><strong>Ques2:</strong> Is it possible to set these variable through ant build file in Jenkins or by running any shell script before executing the phpunit tests through Jenkins?</p>
  
  <p>I tried exporting the server variable through a shell script </p>
  
  <pre><code>    export DOCUMENT_ROOT=/server/path-to-root-dir
  </code></pre>
  
  <p>and calling that script in the build.xml in Jenkins</p>
  
  <pre><code>&lt;export name="setEnv" description="set server var"&gt;
      &lt;exec executable="sh"&gt;
         &lt;arg value = "sumit.sh" /&gt;
      &lt;/exec&gt; 
  &lt;/target&gt;
  </code></pre>
  
  <p>but its not working. Is there any setting that I can do for this?
  Thanks!</p>