protected function getApplication() { if (null === $this->application) { $this->application = $this->getServiceManager()->get('Application'); $this->application->bootstrap(); } return $this->application; }
public function setupPathController() { $request = $this->serviceManager->get('Request'); $uri = UriFactory::factory('http://example.local/path'); $request->setUri($uri); $router = $this->serviceManager->get('HttpRouter'); $route = Router\Http\Literal::factory(array('route' => '/path', 'defaults' => array('controller' => 'path'))); $router->addRoute('path', $route); $this->application->bootstrap(); }
public function testCanRecoverFromApplicationError() { $this->application->bootstrap(); $response = $this->getMock('Zend\\Stdlib\\ResponseInterface'); $errorMock = $this->getMock('stdClass', array('__invoke')); $finishMock = $this->getMock('stdClass', array('__invoke')); $routeMock = $this->getMock('stdClass', array('__invoke')); $dispatchMock = $this->getMock('stdClass', array('__invoke')); $errorMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { $event->stopPropagation(true); $event->setRouteMatch(new Router\RouteMatch(array())); $event->setError(''); })); $routeMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { $event->stopPropagation(true); $event->setError(Application::ERROR_ROUTER_NO_MATCH); return $event->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event)->last(); })); $dispatchMock->expects($this->once())->method('__invoke')->will($this->returnValue($response)); $finishMock->expects($this->once())->method('__invoke')->will($this->returnCallback(function (MvcEvent $event) { $event->stopPropagation(true); })); $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, $errorMock, 100); $this->application->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $routeMock, 100); $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, $dispatchMock, 100); $this->application->getEventManager()->attach(MvcEvent::EVENT_FINISH, $finishMock, 100); $this->application->run(); $this->assertSame($response, $this->application->getMvcEvent()->getResponse()); }
public function setUp() { $config = ['modules' => ['Zff\\Html2Pdf'], 'module_listener_options' => []]; $serviceManager = new ServiceManager((new ServiceManagerConfig())->toArray()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); $application = new Application($config, $serviceManager); $application->bootstrap(); $this->serviceManager = $serviceManager; }
public function testCompleteRequestShouldReturnApplicationInstance() { $r = new ReflectionObject($this->application); $method = $r->getMethod('completeRequest'); $method->setAccessible(true); $this->application->bootstrap(); $event = $this->application->getMvcEvent(); $result = $method->invoke($this->application, $event); $this->assertSame($this->application, $result); }
public function testCustomListener() { $this->application->bootstrap(array('BootstrapListener')); // must contains custom bootstrap listeners $bootstrapListener = $this->serviceManager->get('BootstrapListener'); $listeners = $this->application->getEventManager()->getListeners(MvcEvent::EVENT_BOOTSTRAP); $bootstrapListeners = $bootstrapListener->getListeners(); $this->assertTrue($listeners->contains($bootstrapListeners[0])); // must contains default listeners $listeners = $this->application->getEventManager()->getListeners(MvcEvent::EVENT_DISPATCH); $this->assertEquals(1, count($listeners)); $listeners = $this->application->getEventManager()->getListeners(MvcEvent::EVENT_ROUTE); $this->assertEquals(1, count($listeners)); $listeners = $this->application->getEventManager()->getListeners(MvcEvent::EVENT_FINISH); $this->assertEquals(1, count($listeners)); }