我一直在谷歌和其他各种网站上寻找这个问题的答案几个小时没有运气.我使用PHPUnit为Zend Framework项目创建了一些单元测试.一切顺利,直到PHPUnit代码覆盖率报告的测试为止.此时我收到以下错误:
生成代码覆盖率报告,这可能需要一些时间.致命错误:在第32行的C:\ htdocs\ZendFWTutorials\ZendStorefront\library\SF\Plugin\Action.php中的非对象上调用成员函数pushStack()
此错误引用以下代码块:
public function
dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$stack = $this->getStack();
// category menu
$categoryRequest = new Zend_Controller_Request_Simple();
$categoryRequest->setControllerName('category')
->setActionName('index')
->setParam('responseSegment', 'categoryMain');
// push requests into the stack
$stack->pushStack($categoryRequest);
}
public function getStack()
{
if (null === $this->_stack) {
$front = Zend_Controller_Front::getInstance();
if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack'))
{
$stack = new Zend_Controller_Plugin_ActionStack();
$front->registerPlugin($stack);
} else {
$stack = $front->getPlugin('ActionStack');
}
$this->_stack = $stack;
}
return $this->_stack;
}
Run Code Online (Sandbox Code Playgroud)
这段代码来自我没有编写的库,因此可能会增加我的问题的复杂性,因为我不太可能理解发生了什么.我还不知道PHPUnit逻辑在创建代码覆盖率报告时正在做什么,所以我不知道如何解决问题.这个问题只发生在我运行PHPUnit并运行xdebug以在正常操作条件下跟踪此函数中的代码时.我有一种感觉,PHPUnit进入一个变量为null但在正常操作中$ stack和$ categoryRequest不为空的情况.
我的目录结构如下:
application
-----> bootstrap
-----> config
-----> layouts
-----> modules
--------> …