在PHPUnit测试期间自动加载自定义资源类型时找不到类
在我的Zend Framework项目中,我正在使用一些自定义资源类型,这些类型是我添加到应用程序Bootstrap.php文件中的资源加载程序中的在PHPUnit测试期间自动加载自定义资源类型时找不到类,php,zend-framework,phpunit,zend-loader,Php,Zend Framework,Phpunit,Zend Loader,在我的Zend Framework项目中,我正在使用一些自定义资源类型,这些类型是我添加到应用程序Bootstrap.php文件中的资源加载程序中的 <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initAutoloader() { $resourceLoader = $t
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoloader()
{
$resourceLoader = $this->getResourceLoader();
$resourceLoader->addResourceTypes(array(
'infrastructure' => array(
'namespace' => 'Infrastructure',
'path' => 'infrastructure/',
),
'interfaces' => array(
'namespace' => 'Interface',
'path' => 'interfaces/',
),
'default' => array(
'namespace' => '',
'path' => '/',
),
));
}
...
}
tests/bootstrap.php文件如下所示
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Mbe_');
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
您需要使用与tests/bootstrap.php文件中类似的方法注册Wbp_uuuu名称空间:
$autoloader->registerNamespace('Wbp_');
你好,大卫,谢谢你的回复。我已经添加了建议的代码,但看起来自动加载程序正在库路径中查找该类,但未成功。所讨论的类位于应用程序路径/infrastructure/Persistence/InMemory
,即应用程序/infrastructure/Persistence/InMemory
中,而不是库路径。我现在得到以下错误。我收到以下错误警告:include_once():无法打开“Wbp/Infrastructure/Persistence/Db/TagRepository.php”进行包含(include_path='/var/www/Wbp/application/。/library:/var/www/Wbp/library:。:/usr/share/php:/usr/share/pear:/home/luke/.netbeans/6.9/zend:/usr/share/php/libzend framework php'))在第146行的/usr/share/php/libzend framework php/Zend/Loader.php中
由于您在linux上运行(假设),文件系统将区分大小写。如果您可以将文件放在APPLICATION\u PATH/Wbp/Infrastructure/Persistence/Db/TagRepository.php中,那么它将正确加载。如果您不想在路径中包含Wbp,我仍然建议将Infrastructure目录资本化。此外,您还需要添加一个名称空间映射,该映射表示对于Wbp_*内容,请查看应用程序_PATH/Infrastructure/。。。。如果您仍然希望它位于小写的基础设施中,则需要将Wbp_基础设施添加到应用程序路径/基础设施中。
$autoloader->registerNamespace('Wbp_');