title: PHPUnit and Globals
body: <p>I am learning and exploring applications of PHPUnit with PHP 5.2.9 and have run into the globals issue. I have set $backupGlobals to FALSE, included the doc '@backupGlobals disabled' and this doesn't seem to affect the behaviour of PHPUnit's backing up of the globals. Is there something I'm missing? Do I need to alter PHPUnit's xml file? Create a bootstrap?</p>
  
  <p>config.php:</p>
  
  <pre><code>$testString = 'Hello world!';
  </code></pre>
  
  <p>basicApp.php:</p>
  
  <pre><code>require ('D:\data\clients\security.ca\web_sites\QRASystems.com\wwwroot\__tests\BasicApp\config.php');
  
  class BasicApp {
  
  public $test;
  
  public function __construct() {
      global $testString;
      $this-&gt;test = $testString;
  }
  
  public function getTest() {
      return $this-&gt;test;
  }
  
  public function setTest($test){
      $this-&gt;test = $test;
  }
  </code></pre>
  
  <p>BasicAppTest.php:</p>
  
  <pre><code>require ('D:\data\clients\security.ca\web_sites\QRASystems.com\wwwroot\__tests\BasicApp\BasicApp.php');
  
  class BasicAppTest extends PHPUnit_Framework_TestCase{
      protected $testClass;
      protected $backupGlobals = FALSE;
      protected $backupGlobalsBlacklist = array('testString');
  
      public function SetUp(){
          $this-&gt;testClass = new BasicApp;
          $this-&gt;testClass-&gt;bootstrap();
      }
  
      public function testGlobal(){
          echo $this-&gt;testClass-&gt;getTest();
          $this-&gt;assertNotNull($this-&gt;backupGlobals);
          $this-&gt;assertFalse($this-&gt;backupGlobals);
          $this-&gt;assertNotEmpty($this-&gt;testClass-&gt;test);
      }
  
      public function testMethods(){
          $this-&gt;testClass-&gt;setTest('Goodbye World!');
          echo $this-&gt;testClass-&gt;getTest();
          $this-&gt;assertNotNull($this-&gt;backupGlobals);
          $this-&gt;assertNotNull($this-&gt;testClass-&gt;test);
          if (empty($this-&gt;testClass-&gt;test)) echo 'Method set failed!';
      }
  }
  </code></pre>
  
  <p>testGlobal() fails on $this->assertNotEmpty($this->testClass->test), indicating that $this->backupGlobals is set to FALSE and that globals are still being back up by PHPUnit.</p>
  
  <p>EDIT: I got this working by making the following changes-</p>
  
  <p>BasicAppTest.php:</p>
  
  <pre><code>    protected $backupGlobals = FALSE; &lt;- REMOVED
      protected $backupGlobalsBlacklist = array('testString');  &lt;- REMOVED
  </code></pre>
  
  <p>config.php:</p>
  
  <pre><code>global $testString; &lt;- ADDED
  $testString = 'Hello world!';
  </code></pre>
  
  <p>I am dumbfounded that this hasn't been covered before somewhere!</p>