我想調用我的zend框架模型並使用AuthenticationControllerTest.php
中的函數,但是當我從終端運行它時出現錯誤。在Phpunit類中加載Zend-Framework模型
- -MyZendproject
- -application
-model
-testmodel
- +public
- -tests
- aplication
- controller
- .AuthenticationControllerTest.php
這裏是我的AuthenticationControllerTest.php
文件
<?php
require_once `PHPUnit/Framework/TestCase.php`;
defined(`APPLICATION_PATH`)
|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../application`));
// Define application environment
defined(`APPLICATION_ENV`) || define(`APPLICATION_ENV`, `tests`);
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR,
array(realpath(APPLICATION_PATH . `../../../library`), get_include_path())));
// Zend_Application
require_once `Zend/Application.php`;
$application = new Zend_Application(
APPLICATION_ENV,
realpath(APPLICATION_PATH .`configs/application.ini`)
);
class AuthenticationControllerTest extends PHPUnit_Framework_TestCase
{
public function testLoginRetriespLogin() {
$testmodel = new Model_testmodel_Object();//my model
}
}
但是當來自終端 「的PHPUnit AuthenticationControllerTest」 運行它,它給我的錯誤:
$ phpunit AuthenticationControllerTest
..FPHP Fatal error: Class 'Model_testmodel_Object' not found in /var/www/versioned/pm160form/tests/application/controllers/AuthenticationControllerTest.php on line 146
由於您使用了許多[反引號(執行運算符)](http://php.net/language.operators.execution),您的代碼實際上應該會產生更多的錯誤。除此之外,你在你的問題中描述的只是一個缺少的類定義。只需要包含它的文件。 – hakre
另外,我認爲你可以從phpunit bootstrap文件和xml配置中獲益:http://phpunit.de/manual/current/en/appendixes.configuration.html – hakre