【发布时间】:2013-12-23 02:56:02
【问题描述】:
这是一个关于 PHP 单元测试的问题,给我一个 Class Not Found 错误。
背景
我正在使用 Zend Studio 10.5 开发 Zend Framework 2 应用程序。我加载了一些模块,包括ZfcUser 和BjyAuthorize
FedcoUser 是具有使用 BjyAuthorize 保护规则的 Controller Guard 的模块:
<?php
namespace FedcoUser\Controller;
use Zend\View\Model\ViewModel;
use ZfcUser\Controller\UserController as ZfcUserController;
class MachinistController extends ZfcUserController
{
public function indexAction()
{
if (!$this->zfcUserAuthentication()->hasIdentity()) {
return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}
return new ViewModel();
}
}
使用 Zend Studio 10.5 原生菜单,我为上面的控制器创建了一个测试用例。当我运行它时,我收到以下错误:
Debug Error: FedcoUser/Controller/MachinistController.php line 8 - Class 'ZfcUser\Controller\UserController' not found
我的假设是,不知何故,PHPUnit 的自动加载器无法确定类的放置位置,因为它找不到的类位于
vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php
我还不熟悉 PHPUnit 是如何解决这个错误的。 PHPUnit 甚至有自动加载器吗?如果有帮助,我模块的 /test/ 文件夹中有名为 bootstrap.php、phpunit.xml 和 TestConfiguration.php 的文件。我尝试将各种模块和路径随机添加到TestConfiguration.php 文件,如下所示,但没有帮助:
$additionalModulePaths = array(
'ZfcUser' => realpath('vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php'),
);
你能帮忙吗?
【问题讨论】:
-
你在你的项目中使用了谁的自动加载功能?
-
我不确定我是否理解这个问题。我给出的答案可能不相关。我正在使用 ZendSkeletonApplication + 几个 Zfc 模块 + BjyAuthorize 模块。我添加了一个 FedcoUser 模块,该模块具有 Module.php 和 getAutoloaderConfig() 函数。还有 autoload_classmap.php、autoload_function.php 和 autoload_register.php 文件。如果相关,我可以在其中发布代码。
标签: php zend-framework tdd phpunit autoloader