PHPUnit和Symfony2无法访问全局变量
这是我的phpunit.xml文件PHPUnit和Symfony2无法访问全局变量,php,symfony,phpunit,dbunit,Php,Symfony,Phpunit,Dbunit,这是我的phpunit.xml文件 <?xml version="1.0" encoding="UTF-8"?> <!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html --> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="htt
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
processIsolation="false"
colors="true"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="bootstrap.php.cache"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="./" />
<var name="DB_DSN" value="mysql:dbname=test_xxx;host=localhost" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="test_xxx" />
</php>
<logging>
<log type="coverage-html" target="build/coverage" title="App Code Coverage" charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*Bundle/Resources</directory>
<directory>../src/*Bundle/Tests</directory>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
从注释中可以看出,考虑到我遵循了文档,我的类似乎没有看到phpunit.xml文件中定义的globals
你有什么想法吗?我错过什么了吗
谢谢大家! 在symfony2中,默认的phpunit.xml不是app/phpunit.xml中的phpunit.xml,而是应用程序根目录中的phpunit.xml。将所有值都放在那里,一切正常。在symfony2中,默认的phpunit.xml不是app/phpunit.xml中的值,而是在应用程序的根目录中。将所有值都放在那里,一切正常。您检查了$\u服务器了吗?@RenatoMendesFigueiredo它对所有变量都做了相同的操作,现在它让我找到了下面的答案,谢谢!你检查了$\u服务器了吗?@RenatoMendesFigueiredo它对所有变量都做了相同的检查,现在它让我得到了下面的答案,谢谢!
abstract class AbstractDatabaseTestCase extends \PHPUnit_Extensions_Database_TestCase{
/**
*
*@var PDO
*
*/
static $pdo;
/**
*
*@var \Doctrine\DBAL\Connection description
*
*/
static $dbal;
private $conn;
final public function getConnection()
{
var_dump($GLOBALS);
// here my GLOBALS['DB_DSN'], GLOBALS['DB_USER'], GLOBALS['DB_PASSWD'] are not seen.
if ($this->conn === null) {
if (self::$pdo == null) {
self::$pdo = new \PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
}
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
}
return $this->conn;
}