私はPHP5.2.9を使用したPHPUnitのアプリケーションを学習および調査しており、グローバル問題に遭遇しました。$ backupGlobalsをFALSEに設定し、ドキュメント「@backupGlobalsdisabled」を含めました。これはPHPUnitのグローバルのバックアップの動作に影響を与えないようです。足りないものはありますか?PHPUnitのxmlファイルを変更する必要がありますか?ブートストラップを作成しますか?
config.php:
$testString = 'Hello world!';
basicApp.php:
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->test = $testString;
}
public function getTest() {
return $this->test;
}
public function setTest($test){
$this->test = $test;
}
BasicAppTest.php:
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->testClass = new BasicApp;
$this->testClass->bootstrap();
}
public function testGlobal(){
echo $this->testClass->getTest();
$this->assertNotNull($this->backupGlobals);
$this->assertFalse($this->backupGlobals);
$this->assertNotEmpty($this->testClass->test);
}
public function testMethods(){
$this->testClass->setTest('Goodbye World!');
echo $this->testClass->getTest();
$this->assertNotNull($this->backupGlobals);
$this->assertNotNull($this->testClass->test);
if (empty($this->testClass->test)) echo 'Method set failed!';
}
}
testGlobal()は$ this-> assertNotEmpty($ this-> testClass-> test)で失敗し、$ this-> backupGlobalsがFALSEに設定されており、グローバルがまだPHPUnitによってバックアップされていることを示します。
編集:私は次の変更を加えることでこれを機能させました-
BasicAppTest.php:
protected $backupGlobals = FALSE; <- REMOVED
protected $backupGlobalsBlacklist = array('testString'); <- REMOVED
config.php:
global $testString; <- ADDED
$testString = 'Hello world!';
これがどこかでカバーされていなかったことに私は唖然としました!