Zend\Mvc\Controller\AbstractController::setEvent PHP Method

setEvent() public method

By default, will re-cast to MvcEvent if another event type is provided.
public setEvent ( Zend\EventManager\EventInterface $e ) : void
$e Zend\EventManager\EventInterface
return void
    public function setEvent(Event $e)
    {
        if (!$e instanceof MvcEvent) {
            $eventParams = $e->getParams();
            $e = new MvcEvent();
            $e->setParams($eventParams);
            unset($eventParams);
        }
        $this->event = $e;
    }

Usage Example

 public function setUp()
 {
     Console::overrideIsConsole(false);
     parent::setUp();
     $this->request = new Request();
     $this->request->setHeaders(new Headers());
     $this->routeMatch = new RouteMatch(array('controller' => $this->controllerName));
     $this->event = $this->getApplication()->getMvcEvent();
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->getRouter()->setRequestUri(new HttpUri('http://localhost'));
     if (null === $this->controller) {
         if (null === $this->controllerName) {
             throw new PHPUnit_Framework_Exception('No controller name was specified in the test');
         }
         $this->controller = $this->getServiceManager()->get('ControllerLoader')->get($this->controllerName);
     }
     $this->controller->setEvent($this->event);
 }