我有一个简单的控制器动作
class CatalogController extends AbstractActionController {
public function indexAction() {
return new ViewModel();
}
// ...
}
并对其进行单元测试:
class CatalogControllerTest extends AbstractHttpControllerTestCase
{
public function testIndexActionCanBeAccessed()
{
$this->routeMatch->setParam('action', 'index');
$result = $this->controller->dispatch($this->request);
$response = $this->controller->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertInstanceOf('Zend\View\Model\ViewModel', $result);
}
它工作得很好。
现在我正在转发请求
public function indexAction() {
return $this->forward()->dispatch('Catalog/Controller/Catalog', array('action' => 'list-cities'));
}
并在之后通过单元测试得到错误$this->controller->dispatch($this->request);
:
PHP Fatal error: Call to a member function getEventManager() on a non-object in /var/www/path/to/project/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/Forward.php on line 147
你如何/应该如何用前锋测试动作方法?
谢谢