我想写一些测试用例,我正在写一个ZF应用程序,但我似乎无法通过这一点。Zend自动加载模型在PHPUnit
我已经扩展了Zend_Test_PHPUnit_ControllerTestCase
,增加以下内容:
public function setUp() {
$this->bootstrap = new Zend_Application('testing',
APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
}
它的工作原理,以及它初始化了Zend自动加载磁带机,让我加载我的图书馆以及Zend类内的其他类。所以我设置了一个测试:
public function testUserUnauthorized() {
$this->dispatch('/api/user');
//Assertions...
}
不幸的是,测试永远不会通过调度。相反,它给我一个错误:
Fatal error: Class 'App_Model_User' not found in ....Action.php
action.php的是扩展Zend_Controller_Action
类。其中有一项功能使用App_Model_User
来验证登录的用户。自从自动装载机工作以来,我从不必添加require_once
。这是奇怪的部分:它通过我的浏览器工作。只是不在PHPUnit中。
所以我甩使用Zend自动加载机注册的自动加载磁带机:
public function testUserUnauthorized() {
print_r(Zend_Loader_Autoloader::getInstance()->getAutoloaders());
exit;
$this->dispatch('/api/user');
}
它显示我的所有模块,以及其命名空间视图,控制器,模型等我做了同样的通过我的浏览器垃圾箱匹配。
缺少自动加载磁带机的配置?一些自定义spl自动加载器?找出哪个自动加载器加载了App_Model_User类。 – MonkeyMonkey