Ejemplo n.º 1
0
 /** @test */
 public function it_converts_exception_to_json()
 {
     $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
     $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
         throw new NotFoundHttpException();
     }));
     $resolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('error');
     $dispatcher = new EventDispatcher();
     $httpKernel = new HttpKernel($dispatcher, $resolver);
     $kernel = new KernelForTest('test', true);
     $kernel->boot();
     $kernel->getContainer()->set('http_kernel', $httpKernel);
     $dispatcher->addSubscriber(new RequestFormatNegotiationListener());
     $dispatcher->addSubscriber(new RequestFormatValidationListener());
     $dispatcher->addSubscriber(new ResponseConversionListener());
     $dispatcher->addSubscriber(new ExceptionConversionListener($logger));
     $request = Request::create('/exception', 'GET', [], [], [], ['HTTP_ACCEPT' => 'application/json']);
     $request->attributes->set('_format', 'json');
     $response = $kernel->handle($request)->prepare($request);
     $this->assertSame(404, $response->getStatusCode());
     $this->assertSame('application/vnd.error+json', $response->headers->get('Content-Type'));
     $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Not Found']), $response->getContent());
 }
Ejemplo n.º 2
0
 public function testConstructor()
 {
     $env = 'test_env';
     $debug = true;
     $kernel = new KernelForTest($env, $debug);
     $this->assertEquals($env, $kernel->getEnvironment());
     $this->assertEquals($debug, $kernel->isDebug());
     $this->assertFalse($kernel->isBooted());
     $this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());
     $this->assertNull($kernel->getContainer());
 }