/** @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()); }
protected function getContainerBaseClass() { if ('test' == $this->environment) { return '\\RDV\\SymfonyContainerMocks\\DependencyInjection\\ContainerMocks'; } return parent::getContainerBaseClass(); }
public function testSerialize() { $env = 'test_env'; $debug = true; $kernel = new KernelForTest($env, $debug); $expected = serialize(array($env, $debug)); $this->assertEquals($expected, $kernel->serialize()); }
public function testRemoveAbsolutePathsFromContainerGiveUpWhenComposerJsonPathNotGuessable() { $kernel = new KernelForTest('dev', true); $kernel->setRootDir($symfonyRootDir = sys_get_temp_dir()); $content = file_get_contents(__DIR__ . '/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php'); $content = str_replace('ROOT_DIR', __DIR__ . '/Fixtures/DumpedContainers', $content); $m = new \ReflectionMethod($kernel, 'removeAbsolutePathsFromContainer'); $m->setAccessible(true); $newContent = $m->invoke($kernel, $content); $this->assertEquals($newContent, $content); }
/** * {@inheritdoc} */ protected function getContainerClass() { return parent::getContainerClass() . mt_rand(); }