Zend_Test_PHPUnit_ControllerTestCase 和 Zend_Layout,运行测试时无法找到布局插件
我开始使用 Zend Framework 1.10.6 和 Zend_Test_PHPUnit_ControllerTestCase 为控制器类编写一些测试用例。我遇到了一项问题,即在测试用例运行时,Zend_Controller_Action_HelperBroker 找不到布局操作助手。
以下是我的测试用例的基本内容:
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'controllers/IndexController.php';
class Application_Controllers_IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
public $_application;
protected function setUp() {
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp ();
}
public function appBootstrap() {
// Create application, bootstrap, but don't run
$this->_application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$this->_application->bootstrap();
$this->getFrontController()->setParams($this->_application->getOptions())
->addControllerDirectory(APPLICATION_PATH . '/controllers');
}
public function testIndexAction() {
$this->dispatch('/index/index');
$this->assertController('index');
$this->assertAction('index');
}
}
运行测试用例时出现异常:
Zend_Controller_Action_Exception: Action Helper by name Layout not found
当我注释掉类 Zend_Controller_Action_HelperBroker 中的两行以尝试找到该行周围的源时368,我得到:
Zend_Loader_PluginLoader_Exception:在注册表中找不到名为“Layout”的插件;使用的路径: Zend_Controller_Action_Helper_: Zend/Controller/Action/Helper/
布局脚本的加载在我的应用程序中运行时工作正常,在 PHPUnit 下运行测试时似乎无法找到 Zend_Controller_Action_Helper 的正确路径或注册表,因此布局插件可以不被加载。
我已经验证 Zend 安装正确并且 Layout.php 位于正确的位置。
有什么想法吗?
德尔
I am starting to write some test cases for controller classes using Zend Framework 1.10.6 and Zend_Test_PHPUnit_ControllerTestCase. I am having problems with one item, which is that while the test cases are running, Zend_Controller_Action_HelperBroker can't find the Layout action helper.
Here are the bare bones of my test case:
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
require_once 'controllers/IndexController.php';
class Application_Controllers_IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
public $_application;
protected function setUp() {
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp ();
}
public function appBootstrap() {
// Create application, bootstrap, but don't run
$this->_application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$this->_application->bootstrap();
$this->getFrontController()->setParams($this->_application->getOptions())
->addControllerDirectory(APPLICATION_PATH . '/controllers');
}
public function testIndexAction() {
$this->dispatch('/index/index');
$this->assertController('index');
$this->assertAction('index');
}
}
I get an exception when I run the test case:
Zend_Controller_Action_Exception: Action Helper by name Layout not found
When I comment out the two lines in class Zend_Controller_Action_HelperBroker to try to find the source of this around line 368, I get:
Zend_Loader_PluginLoader_Exception: Plugin by name 'Layout' was not found in the registry; used paths:
Zend_Controller_Action_Helper_: Zend/Controller/Action/Helper/
The loading of layout scripts works fine in my application when running, it appears that the correct path or registry for the Zend_Controller_Action_Helper can't be found while running tests under PHPUnit and therefore the Layout plugin can't be loaded.
I have verified that Zend is installed correctly and that Layout.php is in the correct place.
Any ideas?
Del
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 appBootstrap() 的末尾放置以下行:
In you appBootstrap() at the end place this line:
您在什么时候添加布局代码?
请记住,运行 PHPUnit 测试时,“引导”是不同的,并且在主应用程序中引导的内容在作为 PHPUnit 测试运行时可能不会。
At which point do you add your Layout code?
Remember that the 'boostraping' is different when running a PHPUnit test, and that things that are bootstrapped in your main app might not be when running as a PHPUnit test.
我的解决方法:
My workaround: