Ejemplo n.º 1
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = ['foo' => 'bar'];
     $viewHandler = new ViewHandler($this->router, $this->serializer, $this->templating, $this->requestStack, $this->exceptionWrapperHandler, ['jsonp' => false]);
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', [$jsonpHandler, 'createResponse']);
     $this->serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = array('foo' => 'bar');
     $viewHandler = new ViewHandler(array('jsonp' => false));
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', array($jsonpHandler, 'createResponse'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get', 'getParameter'));
     $serializer = $this->getMock('stdClass', array('serialize', 'setVersion'));
     $serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $container->expects($this->once())->method('get')->with('fos_rest.serializer')->will($this->returnValue($serializer));
     $container->expects($this->any())->method('getParameter')->will($this->onConsecutiveCalls('version', '1.0'));
     $viewHandler->setContainer($container);
     $data = array('foo' => 'bar');
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = ['foo' => 'bar'];
     $viewHandler = new ViewHandler(['jsonp' => false]);
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', [$jsonpHandler, 'createResponse']);
     $viewHandler->setSerializationContextAdapter($this->getMock(SerializationContextAdapterInterface::class));
     $container = $this->getMock(ContainerInterface::class);
     $serializer = $this->getMock('stdClass', ['serialize', 'setVersion']);
     $serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $container->expects($this->any())->method('get')->with($this->equalTo('fos_rest.serializer'))->will($this->returnValue($serializer));
     $container->expects($this->any())->method('getParameter')->will($this->onConsecutiveCalls('version', '1.0'));
     $viewHandler->setContainer($container);
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
 public function testHandleCustom()
 {
     $viewHandler = new ViewHandler(array());
     $viewHandler->registerHandler('html', $callback = function () {
         return 'foo';
     });
     $container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container', array('get'));
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue(new Request()));
     $viewHandler->setContainer($container);
     $data = array('foo' => 'bar');
     $view = new View($data);
     $this->assertEquals('foo', $viewHandler->handle($view));
 }
Ejemplo n.º 5
0
 public function testHandleCustom()
 {
     $viewHandler = new ViewHandler([]);
     $viewHandler->registerHandler('html', $callback = function () {
         return 'foo';
     });
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', ['get']);
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue(new Request()));
     $viewHandler->setContainer($container);
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $this->assertEquals('foo', $viewHandler->handle($view));
 }