运行PHPUnit测试会产生“;“未找到类”;错误
这是一个关于PHP单元测试的问题,给出了一个类NotFound错误 背景 我正在使用Zend Studio 10.5开发Zend Framework 2应用程序。我加载了一些模块,包括运行PHPUnit测试会产生“;“未找到类”;错误,php,zend-framework,tdd,phpunit,autoloader,Php,Zend Framework,Tdd,Phpunit,Autoloader,这是一个关于PHP单元测试的问题,给出了一个类NotFound错误 背景 我正在使用Zend Studio 10.5开发Zend Framework 2应用程序。我加载了一些模块,包括ZfcUser和BjyAuthorize FedcoUser是具有使用BJYAAuthorize的保护规则的控制器保护的模块: <?php namespace FedcoUser\Controller; use Zend\View\Model\ViewModel; use ZfcUser\Controlle
ZfcUser
和BjyAuthorize
FedcoUser是具有使用BJYAAuthorize的保护规则的控制器保护的模块:
<?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();
}
}
我的假设是,PHPUnit的autoloader不知何故无法确定类的位置,因为它找不到的类位于何处
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'),
);
您能帮忙吗?我最后在TestConfiguration.php文件的配置中加载了其他名称空间:
$additionalNamespaces=数组(
“ZfcUser\Controller'=>\uuuuu DIR\uuuuuu.'/../../../../../../../vendor/zf commons/zfc user/src/ZfcUser/Controller/”
);
这非常适合我的bootstrap.php
,它有以下代码:
最后,我在TestConfiguration.php文件的配置中加载了其他名称空间:
$additionalNamespaces=数组(
“ZfcUser\Controller'=>\uuuuu DIR\uuuuuu.'/../../../../../../../vendor/zf commons/zfc user/src/ZfcUser/Controller/”
);
这非常适合我的bootstrap.php
,它有以下代码:
你在项目中使用自动加载的是谁?我不确定我是否理解这个问题。我给出的答案可能与此无关。我正在使用ZendskeletonApp+几个Zfc模块+BjyAuthorize模块。我添加了一个FedcoUser模块,该模块具有module.php和getAutoloaderConfig()函数。还有autoload_classmap.php、autoload_function.php和autoload_register.php文件。如果相关的话,我可以在它们里面发布代码。你在项目中使用自动加载的是谁?我不确定我是否理解这个问题。我给出的答案可能与此无关。我正在使用ZendskeletonApp+几个Zfc模块+BjyAuthorize模块。我添加了一个FedcoUser模块,该模块具有module.php和getAutoloaderConfig()函数。还有autoload_classmap.php、autoload_function.php和autoload_register.php文件。如果相关的话,我可以把代码贴在里面。
$additionalModulePaths = array(
'ZfcUser' => realpath('vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php'),
);
// setup autoloader
AutoloaderFactory::factory(
array(
'Zend\Loader\StandardAutoloader' => array(
StandardAutoloader::AUTOREGISTER_ZF => true,
StandardAutoloader::ACT_AS_FALLBACK => false,
StandardAutoloader::LOAD_NS => $additionalNamespaces,
)
)
);