public function testConstructor() { $name = 'Foo'; $context = 'Bar'; $params = ['baz' => 'bat']; $event = new SystemEvent($name, $context, $params); $this->assertSame($name, $event->getName()); $this->assertSame($context, $event->getContext()); $this->assertSame($params, $event->getParams()); }
/** * Processes the response. * * @param \Psr\Http\Message\ResponseInterface $response The response * @param \Es\System\SystemEvent $event The system event */ public function processResponse(ResponseInterface $response, SystemEvent $event) { if ($event->getName() === SystemEvent::FINISH) { $event->stopPropagation(true); $server = $this->getServer(); $emitter = $server->getEmitter(); $emitter->emit($response); return; } $events = $this->getEvents(); $event->setResult(SystemEvent::FINISH, $response); $events->trigger($event(SystemEvent::FINISH)); }
/** * Handles an error in development mode. * * @param \Es\System\SystemEvent $systemEvent The system event * @param \Exception|\Error $exception The exception or the error */ public function handleDevelopmentError(SystemEvent $systemEvent, $exception) { $options = ['exception' => $exception, 'eventName' => $systemEvent->getName()]; $renderer = $this->getRenderer(); $result = $renderer->render('error/development', $options); $body = Stream::make($result); $status = 503; if ($exception instanceof ExceptionInterface && $exception->getCode()) { $status = $exception->getCode(); } $response = new Response($status, $body, ['Content-Type' => 'text/html']); $this->processResponse($response, $systemEvent); }
public function testHandleDevelopmentErrorWithSpecifiedStatus() { $renderer = $this->getMock(ErrorRenderer::CLASS); $events = $this->getMock(Events::CLASS); $strategy = new HtmlErrorStrategy(); $strategy->setRenderer($renderer); $strategy->setEvents($events); $event = new SystemEvent('Foo'); $exception = new FakeException('Foo', 405); $content = 'Lorem ipsum dolor sit amet'; $renderer->expects($this->once())->method('render')->with($this->identicalTo('error/development'), $this->identicalTo(['exception' => $exception, 'eventName' => $event->getName()]))->will($this->returnValue($content)); $events->expects($this->once())->method('trigger')->with($this->identicalTo($event)); $strategy->handleDevelopmentError($event, $exception); $response = $event->getResult(SystemEvent::FINISH); $this->assertInstanceOf(ResponseInterface::CLASS, $response); $this->assertSame($content, (string) $response->getBody()); $this->assertSame('text/html', $response->getHeaderLine('Content-Type')); $this->assertSame(405, $response->getStatusCode()); }