【发布时间】:2013-10-03 09:25:37
【问题描述】:
我想调用我的 zend-framework 模型并在 AuthenticationControllerTest.php 中使用那里的函数,但是当我从终端运行它时出现错误。
- -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 致命错误:在第 146 行的 /var/www/versioned/pm160form/tests/application/controllers/AuthenticationControllerTest.php 中找不到类“Model_testmodel_Object”
【问题讨论】:
-
您的代码实际上应该产生更多错误,因为您使用了许多backticks (execution operators)。除此之外,您在问题中描述的只是一个缺失的类定义。只需要包含它的文件。
-
另外,我认为您可能会受益于阅读 phpunit 引导文件和 xml 配置:phpunit.de/manual/current/en/appendixes.configuration.html
标签: php zend-framework phpunit