Phpunit从未知位置抓取Doctrine2配置
我使用的是ZF2+Doctrine2+PHPUNIT,在设置PHPUNIT时,它可以很好地用于基本测试,但是只要我尝试运行调用Doctrine2的测试,我就会得到:Phpunit从未知位置抓取Doctrine2配置,php,doctrine-orm,zend-framework2,phpunit,Php,Doctrine Orm,Zend Framework2,Phpunit,我使用的是ZF2+Doctrine2+PHPUNIT,在设置PHPUNIT时,它可以很好地用于基本测试,但是只要我尝试运行调用Doctrine2的测试,我就会得到: PDOException: SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES) 但是,我从未指定“用户名”或“本地主机”或任何类型的密码。事实上,我的应用程序运行得非常好,我的配置指定了完全不同的设置
PDOException: SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
但是,我从未指定“用户名”或“本地主机”或任何类型的密码。事实上,我的应用程序运行得非常好,我的配置指定了完全不同的设置
那么PHPUnit从哪里获得这些设置以及如何修复它呢
My global.php:
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => '127.0.0.1',
'port' => '3306',
'user' => 'sbapp',
'password' => 'myp@ss',
'dbname' => 'root'
)
)
),
测试:
class ApplicationControllerTest extends AbstractHttpControllerTestCase
{
protected $traceError = true;
public function setUp()
{
$this->setApplicationConfig(
include '../../../config/application.config.php'
);
parent::setUp();
}
public function testAuthActionCanBeAccessed()
{
$postData = new \stdClass();
$postData->username = "someAppUser";
$postData->password = "12345";
$postData = json_decode(json_encode($postData),true);
$this->dispatch('/auth', 'POST', $postData);
$response = $this->getResponse();
$this->assertResponseStatusCode(200);
$this->assertActionName('auth');
}
}
如果设置时配置中使用的相对路径不正确,可能会严重影响实体的加载等。所以我一直在沿着正确的道路追。。从根目录..或供应商..或从测试文件夹内等调用phpunit时 解决方案: 从项目根调用它,并保持路由与主项目完全相同