我正在尝试使用Doctrine ORM使用phpunit为Zend创建单元测试。当我尝试创建一个扩展Zend_Test_PHPUnit_DatabaseTestCase的测试类时,我在执行PHPUnit时收到一条消息:“没有打开的连接”
以下是完整资料来源:
<?php
class AclTest extends Zend_Test_PHPUnit_DatabaseTestCase
{
private $_userAdmin;
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->_userAdmin = Model_UserTable::getInstance()->findOneByUsername('admin');
parent::setUp();
}
protected function getConnection()
{
$pdo = new PDO('mysql:host=localhost;dbname=mydbname', 'root', 'pwd');
return $this->createDefaultDBConnection($pdo, 'testdb');
}
protected function getDataSet()
{
return null;
}
public function testHasProfilPermission()
{
//execute some tests
}
}
您怎么看?
由于
答案 0 :(得分:0)
请试试这个:
class AclTest extends Zend_Test_PHPUnit_DatabaseTestCase
{
private $_userAdmin;
/** @var PDO **/
protected $pdo;
public function __construct()
{
$this->pdo = new PDO('mysql:host=localhost;dbname=mydbname', 'root', 'pwd');
}
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->_userAdmin = Model_UserTable::getInstance()->findOneByUsername('admin');
parent::setUp();
}
protected function getConnection()
{
return $this->createDefaultDBConnection($this->pdo, 'testdb');
}
}