コード例 #1
0
ファイル: ServerTest.php プロジェクト: easy-system/es-server
 public function testGetRequestGetsNewRequest()
 {
     $server = new Server();
     $first = $server->getRequest(false);
     $second = $server->getRequest(false);
     $this->assertNotSame($first, $second);
     $this->assertInstanceof(ServerRequest::CLASS, $first);
     $this->assertInstanceof(ServerRequest::CLASS, $second);
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 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());
 }
コード例 #4
0
 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);
 }