예제 #1
0
 /**
  * @param Request $request
  * @return Response
  */
 public function handleRequest(Request $request)
 {
     $directRequest = $this->requestFactory->createRequest($request);
     $directResponse = $this->router->handle($directRequest, $request);
     if ($directRequest->isFormUpload()) {
         $response = new UploadResponse($directResponse->getFirst());
     } else {
         $response = JsonResponse::create($directResponse);
     }
     if ($this->debug) {
         $response->setEncodingOptions(JSON_PRETTY_PRINT);
     }
     return $response;
 }
예제 #2
0
 public function testEventDispatcherIsCalledCorrectlyForFailedCall()
 {
     /** @var \TQ\ExtDirect\Router\ServiceResolverInterface|\PHPUnit_Framework_MockObject_MockObject $serviceResolver */
     $serviceResolver = $this->getMock('TQ\\ExtDirect\\Router\\ServiceResolverInterface', array('getService', 'getArguments'));
     /** @var \TQ\ExtDirect\Router\ServiceReference|\PHPUnit_Framework_MockObject_MockObject $service */
     $service = $this->getMock('TQ\\ExtDirect\\Router\\ServiceReference', array('__invoke', 'hasSession'), array(), '', false);
     $httpRequest = new HttpRequest();
     $directRequest = new DirectRequest(1, 'My.Action', 'myMethod', array('a', 'b'), false, false);
     $serviceResolver->expects($this->once())->method('getService')->with($this->equalTo($directRequest))->willReturn($service);
     $serviceResolver->expects($this->once())->method('getArguments')->with($this->equalTo($directRequest), $this->equalTo($httpRequest))->willReturn(array('__internal__directRequest' => $directRequest, '__internal__httpRequest' => $httpRequest, 'a' => 'a', 'b' => 'b'));
     $service->expects($this->any())->method('hasSession')->willReturn(true);
     $exception = new \RuntimeException('Something has happened');
     $service->expects($this->once())->method('__invoke')->with($this->equalTo(array($directRequest, $httpRequest, 'a', 'b')))->willThrowException($exception);
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array('dispatch', 'addListener', 'addSubscriber', 'removeListener', 'removeSubscriber', 'getListeners', 'getListenerPriority', 'hasListeners'));
     $eventDispatcher->expects($this->exactly(6))->method('dispatch')->withConsecutive(array($this->equalTo('tq_extdirect.router.begin_request'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\BeginRequestEvent')), array($this->equalTo('tq_extdirect.router.before_resolve'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\ServiceResolveEvent')), array($this->equalTo('tq_extdirect.router.after_resolve'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\ServiceResolveEvent')), array($this->equalTo('tq_extdirect.router.before_invoke'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\InvokeEvent')), array($this->equalTo('tq_extdirect.router.exception'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\ExceptionEvent')), array($this->equalTo('tq_extdirect.router.end_request'), $this->isInstanceOf('TQ\\ExtDirect\\Router\\Event\\EndRequestEvent')))->will($this->returnArgument(1));
     $router = new Router($serviceResolver, $eventDispatcher);
     $router->handle(new RequestCollection(array($directRequest)), $httpRequest);
 }