我想调用我的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