I had a simple controller action
class CatalogController extends AbstractActionController {
public function indexAction() {
return new ViewModel();
}
// ...
}
and a unit test for it:
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);
}
It worked fine.
Now I'm forwarding the request
public function indexAction() {
return $this->forward()->dispatch('Catalog/Controller/Catalog', array('action' => 'list-cities'));
}
and getting an error by unit testing after $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
How do you / how should one test action methods with forwards?
Thx