public function testOnBootstrapListenersWithHttpRequest() { $module = new Module(); $application = $this->createApplication(); $sm = $application->getServiceManager(); foreach ($module->getServiceConfig()['invokables'] as $key => $value) { $sm->setInvokableClass($key, $value); } foreach ($module->getServiceConfig()['factories'] as $key => $value) { $sm->setFactory($key, $value); } $event = new \Zend\Mvc\MvcEvent(); $event->setApplication($application); $em = $application->getEventManager(); $em->getSharedManager()->clearListeners('ConLayout\\Updater\\LayoutUpdater'); $this->assertCount(0, $em->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH)); $this->assertCount(0, $em->getListeners(\Zend\Mvc\MvcEvent::EVENT_RENDER)); $module->onBootstrap($event); $this->assertCount(2, $em->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH)); $layoutUpdater = $sm->get('ConLayout\\Updater\\LayoutUpdaterInterface'); $this->assertEquals(['default'], $layoutUpdater->getHandles()); $mvcEvent = new \Zend\Mvc\MvcEvent(); $mvcEvent->setApplication($application); $mvcEvent->setName(\Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR); $mvcEvent->setError('test-error'); $em->trigger($mvcEvent); $this->assertEquals(['default', 'test-error'], $layoutUpdater->getHandles()); }
public function testOnBootstrapListenersWithHttpRequest() { $module = new Module(); $application = $this->createApplication(); $sm = $application->getServiceManager(); $sm->setService('FilterManager', new FilterPluginManager()); foreach ($module->getServiceConfig()['invokables'] as $key => $value) { $sm->setInvokableClass($key, $value); } foreach ($module->getServiceConfig()['factories'] as $key => $value) { $sm->setFactory($key, $value); } $sm->get('ViewHelperManager')->setService('bodyClass', $this->getMock(BodyClass::class)); $event = new MvcEvent(); $event->setApplication($application); $em = $application->getEventManager(); $em->getSharedManager()->clearListeners(LayoutUpdater::class); $module->onBootstrap($event); $layoutUpdater = $sm->get(LayoutUpdaterInterface::class); $this->assertEquals(['default'], $layoutUpdater->getHandles()); $mvcEvent = new MvcEvent(); $mvcEvent->setApplication($application); $mvcEvent->setName(MvcEvent::EVENT_DISPATCH_ERROR); $mvcEvent->setError('test-error'); $em->triggerEvent($mvcEvent); $this->assertEquals(['default', 'test-error'], $layoutUpdater->getHandles()); }