public function testCreateJsonResponse()
 {
     $controller = new BaseController();
     $result = array('one' => uniqid(), 'two' => uniqid());
     $code = 202;
     $headers = array('three' => uniqid());
     $response = $controller->createJsonResponse($result, $code, $headers);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response);
     $this->assertEquals($code, $response->getStatusCode());
     $this->assertEquals(json_encode($result), $response->getContent());
     $responseHeaders = $response->headers->all();
     $this->assertArrayHasKey('three', $responseHeaders);
     $this->assertEquals(array($headers['three']), $responseHeaders['three']);
     $this->assertArrayHasKey('content-type', $responseHeaders);
     $this->assertEquals(array('application/json'), $responseHeaders['content-type']);
     $this->assertArrayHasKey('access-control-allow-origin', $responseHeaders);
     $this->assertEquals(array('*'), $responseHeaders['access-control-allow-origin']);
     $this->assertArrayHasKey('access-control-allow-methods', $responseHeaders);
     $this->assertEquals(array('*'), $responseHeaders['access-control-allow-methods']);
     $this->assertArrayHasKey('access-control-allow-headers', $responseHeaders);
     $this->assertEquals(array('*'), $responseHeaders['access-control-allow-headers']);
 }
Exemple #2
0
 public function preExecute(Request $request)
 {
     parent::preExecute($request);
     $this->initStorageApi();
 }