PHPUnit 测试插件失败
我的 phpunit 测试因以下错误而失败:
C:\workspace\internal_jets3\tests>phpunit --verbose
PHPUnit 3.5.7 by Sebastian Bergmann.
Fatal error: Call to a member function getOptions() on a non-object in C:\worksp
ace\internal_jets3\library\My\Controller\Plugin\ModuleLayoutLoader.php on line 7
从插件中提取:
class My_Controller_Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
任何有关如何在测试中包含插件的帮助都会有所帮助。谢谢!
编辑@戈登 这对我来说并不是那么明显。 执行 var_dump of:
var_dump(Zend_Controller_Front::getInstance()->getParam('bootstrap'));
die();
给我:
object(Bootstrap)[3]
protected '_appNamespace' => boolean false
protected '_resourceLoader' => null
protected '_application' =>
对我说“object”;转储的一半是:
protected '_options' =>
所以这让我感到困惑 - 我不熟悉如何正确地 phpunit 测试这个对象。
my phpunit test fails with this error:
C:\workspace\internal_jets3\tests>phpunit --verbose
PHPUnit 3.5.7 by Sebastian Bergmann.
Fatal error: Call to a member function getOptions() on a non-object in C:\worksp
ace\internal_jets3\library\My\Controller\Plugin\ModuleLayoutLoader.php on line 7
Extract from plugin:
class My_Controller_Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
Any help on how to include plugins in testing will be helpful. Thanks!
Edit @Gordon
It's not really that obvious to me.
Doing a var_dump of:
var_dump(Zend_Controller_Front::getInstance()->getParam('bootstrap'));
die();
gives me:
object(Bootstrap)[3]
protected '_appNamespace' => boolean false
protected '_resourceLoader' => null
protected '_application' =>
which says 'object' to me; and halfway down the dump is:
protected '_options' =>
So this confuses me - I'm not familiar how to correctly phpunit test this object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 Zend 环境中设置 PHPUnit,您必须在 phpunit 引导程序内触发 Zend 引导程序。之后,您的应用程序中仍然有一个引导对象。
你的错误消息说
Zend_Controller_Front::getInstance()->getParam('bootstrap')
为 NULL。您确定您已在正确的位置进行了调试吗?
to set up PHPUnit in Zend environment, you have to fire your Zend bootstrap inside your phpunit bootstrap. After this, you still have a bootstrap object in your application.
And your errormessage said that
Zend_Controller_Front::getInstance()->getParam('bootstrap')
is NULL. Are you sure, that you've debugged at the right place?