[英]Class not found when autoloading custom resource types during PHPUnit testing
In my Zend Framework project, I am using some custom resource types that I add to the resource loader in my application's Bootstrap.php file. 在我的Zend Framework项目中,我使用了一些自定义资源类型,这些类型已添加到应用程序的Bootstrap.php文件中的资源加载器中。
<?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' => '/',
),
));
}
...
}
I can autoload these resources okay when running the application, but when running PHPUnit and trying to load these classes during tests, they cannot be found. 我可以在运行应用程序时自动加载这些资源,但是在运行PHPUnit并尝试在测试期间加载这些类时,找不到它们。
PHP Fatal error: Class 'Wbp_Infrastructure_Persistence_InMemory_TagRepository' not found in /var/www/worldsbestprizes/tests/library/Mbe/Validate/TaggedUriTest.php on line 37
The tests/bootstrap.php file looks like this. 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'
);
Is there something I should add to it to allow those custom resource types to be loaded? 我应该添加一些内容以允许加载那些自定义资源类型吗?
您需要使用与在tests / bootstrap.php文件中类似的方法注册Wbp_名称空间:
$autoloader->registerNamespace('Wbp_');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.