示例#1
0
 /** @test */
 public function it_logs_critical_exceptions()
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $kernel->expects($this->once())->method('handle')->will($this->throwException(new \Exception()));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('critical');
     $app = new ExceptionConverter($kernel, $logger);
     $request = new Request();
     $request->attributes->set('_format', 'json');
     $app->handle($request);
 }
 /** @test */
 public function it_converts_exception_to_xml()
 {
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $kernel->expects($this->once())->method('handle')->will($this->throwException(new NotFoundHttpException()));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('error');
     $app = new RequestFormatNegotiator($kernel);
     $app = new RequestFormatValidator($app);
     $app = new ExceptionConverter($app, $logger);
     $request = new Request();
     $request->attributes->set('_format', 'xml');
     $response = $app->handle($request)->prepare($request);
     $this->assertSame(404, $response->getStatusCode());
     $this->assertSame('application/vnd.error+xml', $response->headers->get('Content-Type'));
     $this->assertXmlStringEqualsXmlString('<resource><message>Not Found</message></resource>', $response->getContent());
 }