PHPUNIT如何为这种情况制作UT?

时间:2020-10-06 16:34:21

标签: php zend-framework phpunit

我正在尝试使用PHPUNIT来实现以下功能:

/**
 * Get the _getValueHelperhelps to return a magic value from the matrix
 * @return string
 */
protected function _getValueHelper()
{
    return Zend_Controller_Action_HelperBroker::getStaticHelper('valueHelper');
}

这是要测试的函数,它调用上面的帮助器:

 protected function _protectedFunctionMagic( $view ) {
        if($this->_shopName->values->showLog){
            $view->showLog = array(
                "value1" => Zend_Registry::get('conversationId'),
                "value2" => $this->_getValueHelper()->getValue()
            );
        }
    }

我已经尝试了几件事,阅读了文档,但是无法掌握它,我该如何模拟这行

 "value2" => $this->_getValueHelper()->getValue()

我尝试了很多事情,但似乎没有任何效果,甚至无法进入断言阶段……当调用仅是一个函数时,我确实工作了

 "value2" => $this->_getValueHelper()

但是现在代码已更新,如何模拟这种特殊情况?

    $testMock->expects($this->any())
        ->method('_getValueHelper')
        ->with('getValue')
        ->will($this->returnValue('1234'));

结果:

Expectation failed for method name is equal to <string:_getValueHelper> when invoked zero or more times
Parameter count for invocation PEP_Controller_Plugin_ConfigurableStore::_getValueHelper() is too low

0 个答案:

没有答案