2013-04-23 28 views
0

我想在一个ZF项目中使用单元测试,所以我创建了测试类,但这里是错误:误差分贝使用PHPUnit和Zend框架选择

有关线路有:

$this->db = Zend_Db_Table_Abstract::getDefaultAdapter(); 

$select = $this->db->select()->from(array('c' => 'cards')); 

而且当我使用浏览器时没有问题。

这里是我的phpunit.xml(从其他项目ZF无数据库):

<phpunit bootstrap="./bootstrap.php"> 
    <testsuite name="Application Test Suite"> 
     <directory>./application</directory> 
    </testsuite> 
    <testsuite name="Library Test Suite"> 
     <directory>./library</directory> 
    </testsuite> 

    <filter> 
     <whitelist> 
      <directory suffix=".php">../../library/Zend</directory> 
     </whitelist> 
    </filter> 
</phpunit> 

的bootstrap.php中:

<?php 

// Define path to application directory 
defined('APPLICATION_PATH') 
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); 

// Define application environment 
defined('APPLICATION_ENV') 
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); 

// Ensure library/ is on include_path 
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'), 
    get_include_path(), 
))); 

require_once 'Zend/Loader/Autoloader.php'; 
Zend_Loader_Autoloader::getInstance(); 

,并且测试类:

<?php 

class CardControllerTest extends Zend_Test_PHPUnit_ControllerTestCase 
{ 

    public function setUp() 
    { 
     $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); 
     parent::setUp(); 
    } 

    public function testList() 
    { 
     $this->dispatch('/card'); 
    } 
} 

我尝试了很多东西,但没有真正起作用。某些代码更改了“找不到默认模块”的错误。

谢谢您的帮助:)

回答

1

好吧,我发现了问题:

中的application.ini

,我只把数据库配置的开发环境,同时单元测试仍在使用的测试环境组态。

所以问题解决了!