public function testProcessResponseEmitResponseIfTheSystemEventIsAtTheFinish() { $emitter = $this->getMock(SapiEmitter::CLASS); $server = new Server(); $server->setEmitter($emitter); $strategy = new HtmlErrorStrategy(); $strategy->setServer($server); $event = new SystemEvent(SystemEvent::FINISH); $response = new Response(); $emitter->expects($this->once())->method('emit')->with($this->identicalTo($response)); $strategy->processResponse($response, $event); }
public function testInvokeOnSuccess() { $response = new Response(); $event = new SystemEvent(); $event->setResult(SystemEvent::FINISH, $response); $server = new Server(); $emitter = $this->getMock(SapiEmitter::CLASS); $server->setEmitter($emitter); $emitter->expects($this->once())->method('emit')->with($this->identicalTo($response)); $listener = new ResponseListener(); $listener->setServer($server); $listener($event); }
public function testInvokeOnSuccess() { $server = new Server(); $request = $server->getRequest(); $server->setRequest($request->withAttribute('action', 'foo')); $model = new ViewModel(); $model->setModule(__NAMESPACE__); $event = new SystemEvent(); $event->setResult(SystemEvent::DISPATCH, $model); $event->setContext(new FakeController()); $listener = new InjectTemplateListener(); $listener->setServer($server); $listener($event); $this->assertSame('fake/foo', $model->getTemplate()); }
public function testInvoke() { $params = ['foo' => 'bar', 'bat' => 'baz']; $route = new Route('/foo', $params); $router = new Router(); $router->add('foo', $route); $server = new Server(); $request = $server->getRequest(); $uri = new Uri('/foo'); $server->setRequest($request->withUri($uri)); $listener = new RouteMatchListener(); $listener->setRouter($router); $listener->setServer($server); $listener(new SystemEvent()); $request = $server->getRequest(); $expected = ['foo' => 'bar', 'bat' => 'baz', 'request_method' => 'GET', 'request_scheme' => '', 'route' => 'foo']; $this->assertSame($expected, $request->getAttributes()); }
public function testInvokeCallJsonErrorStrategyToProcessProductionError() { SystemTestHelper::resetSystem(); $system = System::init([], false); $exception = new Exception(); $systemEvent = $system->getEvent(); $errorEvent = new ErrorEvent(ErrorEvent::FATAL_ERROR, $exception, $system); $server = new Server(); $request = $server->getRequest()->withHeader('Accept', 'application/json'); $server->setRequest($request); $strategy = $this->getMock(JsonErrorStrategy::CLASS, ['handleProductionError']); $listener = new ErrorListener(); $listener->attachErrorStrategy($strategy); $listener->setServer($server); $strategy->expects($this->once())->method('handleProductionError')->with($this->identicalTo($systemEvent), $this->identicalTo($exception)); $listener($errorEvent); }
public function testDoDispatch() { $result = 'Lorem ipsum dolor sit amet'; $params = ['foo' => 'bar', 'bat' => 'baz']; $controller = $this->getMock('FakeController', ['fakeAction']); $event = new DispatchEvent($controller, 'FakeController', 'fake', $params); $request = $this->getMock(ServerRequest::CLASS); $response = new Response(); $server = new Server(); $server->setRequest($request); $server->setResponse($response); $dispatcher = new DispatchesControllerListener(); $dispatcher->setServer($server); $request->expects($this->once())->method('withAddedAttributes')->with($this->callback(function ($attributes) use($params) { return empty(array_diff($params, $attributes)); }))->will($this->returnSelf()); $controller->expects($this->once())->method('fakeAction')->with($this->identicalTo($request), $this->identicalTo($response))->will($this->returnValue($result)); $dispatcher->doDispatch($event); }
public function testGetEmitter() { $server = new Server(); $this->assertInstanceOf(EmitterInterface::CLASS, $server->getEmitter()); }