2009-04-17 29 views
1

當我運行PHPUnit來有測試我的控制器總是消息:Class Zend_Test_PHPUnit_Controller_TestCase could not be found ...類Zend_Test_PHPUnit_ControllerTestCase找不到

所有require_once被執行,並沒有錯誤運行。

我的文件:

test.php的:

<?php 

require_once 'bootstrap.php'; 

class indexTest extends Zend_Test_PHPUnit_ControllerTestCase 
{ 
    protected function setUp() 
    { 
     $this->bootstrap = array($this, 'appBootstrap'); 
     parent::setUp(); 
    } 

    public function appBootstrap() 
    { 
     $this->frontController->registerPlugin(new DemoApp_Controller_Plugin_Initialize('test', PROJECT_ROOT)); 
    } 

    public function testIndex() 
    { 
     $this->dispatch('/'); 
     $this->assertController('login'); 
    } 
} 

bootstrap.php中:

<?php 
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../src/application/')); 

set_include_path(APPLICATION_PATH . '/../library' . PATH_SEPARATOR . 
     APPLICATION_PATH . '/modules' . PATH_SEPARATOR . 
     APPLICATION_PATH . '/layouts' . PATH_SEPARATOR . 
     get_include_path()); 

require_once 'PHPUnit/Framework.php';  
require_once 'PHPUnit/Framework/TestSuite.php';  
require_once 'PHPUnit/TextUI/TestRunner.php'; 

error_reporting(E_ALL); 

require_once APPLICATION_PATH . "/../library/Zend/Loader.php"; 
Zend_Loader::registerAutoload(); 

// Set up the config in the registry path relative to public/index.php 
$config = new Zend_Config_Ini(APPLICATION_PATH . '/config.ini'); //, 'test' 
Zend_Registry::set('config', $config); 

/*// Set up the database in the Registry 
$db = Zend_Db::factory($config->db); 
Zend_Db_Table_Abstract::setDefaultAdapter($db); 
*/ 

// Set timezone 
date_default_timezone_set("Europe/Berlin"); 

回答

0

最明顯的第一個問題是,什麼版本的Zend Framework源有嗎?它在Zend/Version.php.

+0

VERSION = '1.7.8' 目錄調用PHPUnit的; – user63371 2009-04-18 18:33:10

1

該類不在你的包含路徑,或者,你根本沒有這個類。
採取的步驟:

  1. 找到類文件
  2. 確保類在 包括路徑,包括 auto_loader名稱解析: Z_Y_YourClass將在 的include_path/Z/Y來看待/YourClass.php

好運

+0

該類在「APPLICATION_PATH」文件中定義爲「ControllerTestCase.php」 。 「/../library/Zend/Test/PHPUnit/' 它被添加到bootstrap.php中的包含路徑 – user63371 2009-04-18 18:32:35

+0

嘗試實驗使用絕對路徑並查看會發生什麼 – 2009-04-18 21:58:29

1

你可以把這個在你的引導,以激活T他自動加載器。

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

如果您創建一個應用程序對象,它這樣做會自動爲您 但以其它方式使用上述自己做。

0

兩個解決方案,爲我工作:

  1. 創建測試目錄中的符號鏈接爲:ln -s ../library/Zend允許自動加載器找文件
  2. 添加/庫到PHP包括路徑 - 這也有助於自動加載磁帶機來定位文件
0

將此放在您的bootstrap.php文件:

require_once 'Zend/Test/PHPUnit/ControllerTestCase.php'; 

爲我工作。祝你好運!

0

我有以下設置

  • 下載Zend的1.12類似的問題,
  • 創建一個項目,通過ZF工具:sh bin/zf.sh create project my-project
  • 然後從項目的根文件夾中運行phpunit

溶液cd tests然後運行PHPUnit的。

原因爲什麼發生這種情況是phpunit首先需要引導。 引導程序腳本在tests/phpunit.xml配置文件中定義,如果該文件位於命令運行的相同目錄中,該文件將默認加載。

phpunit.xml:

<?xml version="1.0" encoding="utf-8" ?> 
<phpunit bootstrap="./bootstrap.php"> 
    <testsuite name="Application Test Suite"> 
    .... 

或者,也可以從任何指定phpunit.xml的位置與-c參數

phpunit -c tests/phpunit.xml