getResponse() public method

public getResponse ( ) : Response | null
return Symfony\Component\HttpFoundation\Response | null A Response instance
 protected function makeRequest($method, $uri, $annotationOptions = array())
 {
     $this->getClient($annotationOptions);
     $this->client->request($method, $uri, array(), array(), $this->requestOptions);
     $response = $this->client->getResponse();
     return $response;
 }
 /**
  * test login
  */
 public function testLoginSuccess()
 {
     $data = array('username' => 'user', 'password' => 'password');
     $this->client->request('POST', $this->getUrl('api_login_check'), $data);
     $this->assertJsonResponse($this->client->getResponse(), 200);
     $response = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('token', $response);
     // check token from query string work
     $client = static::createClient();
     $client->request('HEAD', $this->getUrl('api_ping', array($this->queryParameterName => $response['token'])));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check token work
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check token works several times, as long as it is valid
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token']));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 200, false);
     // check a bad token does not work
     $client = static::createClient();
     $client->setServerParameter('HTTP_Authorization', sprintf('%s %s', $this->authorizationHeaderPrefix, $response['token'] . 'changed'));
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 401, false);
     // check error if no authorization header
     $client = static::createClient();
     $client->request('HEAD', $this->getUrl('api_ping'));
     $this->assertJsonResponse($client->getResponse(), 401, false);
 }
 /**
  * Do login with username
  *
  * @param string $username
  */
 private function doLogin($username = '******')
 {
     $crawler = $this->client->request('GET', $this->getUrl('fos_user_security_login', array()));
     $form = $crawler->selectButton('_submit')->form(array('_username' => $username, '_password' => 'qwerty'));
     $this->client->submit($form);
     $this->assertTrue($this->client->getResponse()->isRedirect());
     $this->client->followRedirects();
 }
 /**
  * test login
  */
 public function testLoginSuccess()
 {
     $data = array('username' => 'user', 'password' => 'password');
     $this->client->request('POST', $this->getUrl('login_check'), $data);
     $this->assertJsonResponse($this->client->getResponse(), 200);
     $response = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('token', $response);
     $this->assertArrayHasKey('data', $response);
 }
 /**
  * @param string $uri
  * @param string $responseType
  */
 public function navigateToPageAndAssertSuccess($uri, $responseType = null)
 {
     $this->client->request('GET', $uri);
     $this->assertTrue($this->client->getResponse()->isSuccessful(), 'Navigation to ' . $uri . ' did not trigger a successful response.');
     if (null !== $responseType) {
         $responseTypeIsTheOneExpected = $this->client->getResponse()->headers->contains('Content-Type', $responseType);
         $this->assertTrue($responseTypeIsTheOneExpected, 'The content type of the response was not ' . $responseType . '. The header provided was: ' . var_export($this->client->getResponse()->headers, true));
     }
 }
Beispiel #6
0
 public function testDoRequest()
 {
     $client = new Client(new TestHttpKernel());
     $client->request('GET', '/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $client->request('GET', 'http://www.example.com/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
 }
Beispiel #7
0
 protected function assertLinkRel(Client $client, string $linkRel, string $expected)
 {
     $this->assertTrue($client->getResponse()->isSuccessful(), 'request is successful');
     foreach ($client->getResponse()->headers->get('Link', null, false) as $linkValue) {
         if (strpos($linkValue, 'rel="' . $linkRel . '"') !== false) {
             $this->assertSame($expected, $linkValue);
             return;
         }
     }
     $this->fail('No link with rel "' . $linkRel . '" found.');
 }
 /**
  * @dataProvider provideExceptionsAndCode
  */
 public function testError($exception, $code, $contentType)
 {
     $app = new Application('test');
     $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber(PhraseaExceptionHandler::register(), $this->createTranslatorMock()));
     $app->get('/api/oauthv2', function () use($exception) {
         throw $exception;
     });
     $client = new Client($app);
     $client->request('GET', '/api/oauthv2');
     $this->assertEquals($code, $client->getResponse()->getStatusCode());
     $this->assertEquals($contentType, $client->getResponse()->headers->get('content-type'));
 }
 public function testRedirection()
 {
     $app = new Application();
     unset($app['exception_handler']);
     $app['dispatcher']->addSubscriber(new FirewallSubscriber());
     $app->get('/', function () {
         throw new HttpException(500, null, null, ['X-Phraseanet-Redirect' => '/hello-world']);
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $this->assertEquals('/hello-world', $client->getResponse()->headers->get('Location'));
 }
 public function testCheckNegative()
 {
     $app = new Application(Application::ENV_TEST);
     unset($app['exception_handler']);
     $app['dispatcher']->addSubscriber(new MaintenanceSubscriber($app));
     $app->get('/', function () {
         return 'Hello';
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertEquals('Hello', $client->getResponse()->getContent());
 }
Beispiel #11
0
 public function logInBackend($username = '******', $password = '******')
 {
     if ($this->um->isAuthenticated() === false) {
         $this->client->request('GET', '/' . $this->api['backend'] . '/user/login/?username='******'&password='******'CONTENT_TYPE' => 'application/json']);
         $response = $this->client->getResponse();
         $content = $response->getContent();
         $result = json_decode($content, true);
         if ($result['status'] !== true) {
             throw new \LogicException('Authentication failed.');
         }
     }
     return $this->um->isAuthenticated();
 }
 public function logInFrontend($username = '******', $password = '******')
 {
     if ($this->um->isAuthenticated() === false) {
         $data = ['username' => $username, 'password' => $password];
         $this->client->request('POST', '/' . $this->api['frontend'] . '/user/login/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($data));
         $response = $this->client->getResponse();
         $content = $response->getContent();
         $result = json_decode($content, true);
         if ($result['status'] !== true) {
             throw new \LogicException('Authentication failed.');
         }
     }
     return $this->um->isAuthenticated();
 }
 /**
  * @dataProvider dataProviderHTMLSyntax
  * @test
  */
 public function should_use_title_and_resources_if_html($syntax, $dir, $extension)
 {
     // GIVEN
     $this->app->register(new DocumentationProvider(), array("documentation.dir" => __DIR__ . "/datas/" . $dir, "documentation.url" => '/doc', "documentation.extension" => $extension, "documentation.home" => 'index', "documentation.syntax" => $syntax, "documentation.title" => 'My Documentation', "documentation.styles" => array('/components/bootstrap/css/bootstrap.min.css'), "documentation.scripts" => array('/components/jquery/jquery.min.js', '/components/bootstrap/js/bootstrap.min.js')));
     $client = new Client($this->app);
     // WHEN
     $crawler = $client->request('GET', '/doc');
     // THEN
     $this->assertTrue($client->getResponse()->isOk());
     $this->assertContains('text/html', $client->getResponse()->headers->get('Content-Type'));
     $this->assertCount(1, $crawler->filter("title"));
     $this->assertCount(1, $crawler->filter("link"));
     $this->assertCount(2, $crawler->filter("script"));
 }
Beispiel #14
0
 public function testDoRequest()
 {
     $client = new Client(new TestHttpKernel());
     $client->request('GET', '/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Request', $client->getInternalRequest());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $client->getRequest());
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Response', $client->getInternalResponse());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $client->getResponse());
     $client->request('GET', 'http://www.example.com/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
     $client->request('GET', 'http://www.example.com/?parameter=http://google.com');
     $this->assertEquals('http://www.example.com/?parameter=' . urlencode('http://google.com'), $client->getRequest()->getUri(), '->doRequest() uses the request handler to make the request');
 }
 public function testListBucket()
 {
     $this->authorize();
     $listUrl = $this->urlGenerator->generate('list', ['bucket' => 'foo']);
     $listBuckets = new Result(['Buckets' => [['Name' => 'foo', 'CreationDate' => '2014-08-01T14:00:00.000Z'], ['Name' => 'bar', 'CreationDate' => '2014-07-31T20:30:40.000Z']]]);
     $listObjects = new Result(['Contents' => [['Key' => 'baz', 'ETag' => '"' . md5('baz') . '"', 'LastModified' => '2014-09-10T11:12:13.000Z', 'Size' => 1024], ['Key' => 'qux', 'ETag' => '"' . md5('qux') . '"', 'LastModified' => '2014-09-11T21:22:23.000Z', 'Size' => 2048], ['Key' => 'quxx', 'ETag' => '"' . md5('quxx') . '"', 'LastModified' => '2014-09-12T00:00:00.000Z', 'Size' => 512]], 'IsTruncated' => false]);
     $this->s3ClientMock->expects($this->once())->method('listBuckets')->willReturn($listBuckets);
     $this->s3ClientMock->expects($this->once())->method('listObjects')->willReturn($listObjects);
     $crawler = $this->client->request('GET', $listUrl);
     $this->assertTrue($this->client->getResponse()->isOk());
     // buckets
     $list = $crawler->filter('#list-bucket li');
     $active = $list->filter('.active');
     $this->assertCount(count($listBuckets['Buckets']), $list);
     $this->assertCount(1, $active);
     $this->assertEquals($list->eq(0), $active);
     $urlGenerator = $this->urlGenerator;
     $list->each(function (Crawler $bucket, $index) use($urlGenerator, $listBuckets) {
         $link = $bucket->filter('a');
         $expectedName = $listBuckets['Buckets'][$index]['Name'];
         $this->assertEquals($expectedName, $link->text());
         $this->assertEquals($urlGenerator->generate('list', ['bucket' => $expectedName]), $link->attr('href'));
     });
     // objects
     $list = $crawler->filter('#list-object tbody tr');
     $this->assertCount(count($listObjects['Contents']), $list);
     $list->each(function (Crawler $object, $index) use($listObjects) {
         $link = $object->filter('td')->eq(0)->filter('a');
         $expectedKey = $listObjects['Contents'][$index]['Key'];
         $this->assertEquals($expectedKey, $link->text());
         $this->assertEquals('http://foo.s3.amazonaws.com/' . $expectedKey, $link->attr('href'));
         $this->assertEquals($listObjects['Contents'][$index]['Size'], $object->filter('td')->eq(1)->text());
     });
 }
 /**
  * @dataProvider provideExceptionsAndCode
  */
 public function testError($exception, $code)
 {
     $app = new Application('test');
     $app['api'] = function () use($app) {
         return new \API_V1_adapter($app);
     };
     $app->register(new \API_V1_Timer());
     $app['dispatcher']->addSubscriber(new ApiExceptionHandlerSubscriber($app));
     $app->get('/', function () use($exception) {
         throw $exception;
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals($code, $client->getResponse()->getStatusCode());
     $this->assertEquals('application/json', $client->getResponse()->headers->get('content-type'));
 }
 public function testRememberMeAuthentication()
 {
     $app = $this->createApplication();
     $client = new Client($app);
     $client->request('get', '/');
     $client->request('post', '/login_check', array('_username' => 'fabien', '_password' => 'foo', '_remember_me' => 'true'));
     $client->followRedirect();
     $this->assertEquals('AUTHENTICATED_FULLY', $client->getResponse()->getContent());
     $this->assertNotNull($client->getCookiejar()->get('REMEMBERME'), 'The REMEMBERME cookie is set');
     $client->getCookiejar()->expire('MOCKSESSID');
     $client->request('get', '/');
     $this->assertEquals('AUTHENTICATED_REMEMBERED', $client->getResponse()->getContent());
     $client->request('get', '/logout');
     $client->followRedirect();
     $this->assertNull($client->getCookiejar()->get('REMEMBERME'), 'The REMEMBERME cookie has been removed');
 }
 public function testWithRoutesThatDoNotUseSession()
 {
     $app = new Application();
     $app['exception_handler']->disable();
     $app->get('/', function () {
         return 'A welcome page.';
     });
     $app->get('/robots.txt', function () {
         return 'Informations for robots.';
     });
     $app = $this->sessionify($app);
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals('A welcome page.', $client->getResponse()->getContent());
     $client->request('GET', '/robots.txt');
     $this->assertEquals('Informations for robots.', $client->getResponse()->getContent());
 }
 /**
  * test login
  *
  * @covers UserController::postUserTokenAction
  * @group authentication
  */
 public function testLoginSuccess()
 {
     $data = array('username' => 'admin', 'password' => 'pass');
     $this->client->request('POST', $this->getUrl($this->loginRoute), $data);
     $this->assertJsonResponse($this->client->getResponse(), 200);
     $response = json_decode($this->client->getResponse()->getContent(), true);
     $this->assertArrayHasKey('token', $response);
     $this->assertArrayHasKey('user', $response);
     $this->assertArrayHasKey('id', $response['user']);
     $this->assertArrayHasKey('firstName', $response['user']);
     $this->assertArrayHasKey('lastName', $response['user']);
     $this->checkTokenInQueryString($response['token']);
     $this->checkTokenInHeaders($response['token']);
     $this->checkTokenMultipleTimes($response['token']);
     $this->checkBadToken($response['token']);
     $this->checkNoToken($response['token']);
 }
Beispiel #20
0
 public function testCget()
 {
     $this->client->request('GET', '/api/operators');
     $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
     $response = json_decode($this->client->getResponse()->getContent());
     $this->assertNotEmpty($response);
     $this->assertEquals(3, count($response->_embedded->items));
 }
Beispiel #21
0
 /**
  * Checks response code.
  *
  * @param $num
  */
 public function seeResponseCodeIs($num)
 {
     if (method_exists($this->client->getResponse(), 'getStatusCode')) {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatusCode());
     } else {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatus());
     }
 }
 public function testDoesNotReturn401IfValidToken()
 {
     $this->register('chain');
     $jwt = JWT::encode(['sub' => 'John'], 'secret', 'HS256');
     $client = new Client($this->app);
     $client->request('GET', '/?jwt=' . $jwt);
     $response = $client->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
 }
 public function testWithRoutesThatDoesNotUseSession()
 {
     $app = new Application();
     $app->register(new SessionServiceProvider(), array('session.test' => true));
     $app->get('/', function () {
         return 'A welcome page.';
     });
     $app->get('/robots.txt', function () {
         return 'Informations for robots.';
     });
     $app['debug'] = true;
     $app['exception_handler']->disable();
     $client = new Client($app);
     $client->request('get', '/');
     $this->assertEquals('A welcome page.', $client->getResponse()->getContent());
     $client->request('get', '/robots.txt');
     $this->assertEquals('Informations for robots.', $client->getResponse()->getContent());
 }
 /**
  * @param int $orderId
  * @param string $refKey
  */
 private function assertCode400DeleteResponse($orderId, $refKey = null)
 {
     $url = '/api/v1/order?id=' . $orderId;
     if (!is_null($refKey)) {
         $url .= '&ref=' . $refKey;
     }
     $this->sendRequest('DELETE', $url);
     $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
 }
Beispiel #25
0
 /** @dataProvider provideOverrideSessionParams */
 public function testOverrideSessionParams($expectedDomain, $expectedPath, $expectedSecure, $expectedHttponly, $expectedExpire, $config)
 {
     $app = new CallableHttpKernel(function (Request $request) {
         $request->getSession()->set('some_session_var', 'is set');
         return new Response('test');
     });
     $app = $this->sessionify($app, $config);
     $client = new Client($app);
     $client->setServerParameters(array('REQUEST_TIME' => static::SIMULATED_TIME));
     $client->request('GET', '/');
     $this->assertEquals('test', $client->getResponse()->getContent());
     $cookies = $client->getResponse()->headers->getCookies();
     $this->assertCount(1, $cookies);
     $cookie = $cookies[0];
     $expectedCookie = new Cookie($this->mockFileSessionStorage->getName(), $this->mockFileSessionStorage->getId(), $expectedExpire, $expectedPath, $expectedDomain, $expectedSecure, $expectedHttponly);
     $this->assertEquals($expectedCookie, $cookie);
     $bag = $this->mockFileSessionStorage->getBag('attributes');
     $this->assertEquals('is set', $bag->get('some_session_var'));
 }
 /**
  * @dataProvider provideData
  */
 public function testValidJsonData($label, $data, $expectedResponse)
 {
     $this->app['aiv.input'] = new \AIV\Input\SymfonyRequest\JSONInput();
     $client = new Client($this->app, []);
     $label = 'Test Case: ' . $label;
     $client->request('POST', '/', [], [], [], json_encode(['test-name' => $data]));
     $response = $client->getResponse();
     $this->assertTrue($response->isOk(), $label);
     $this->assertContains($expectedResponse, $response->getContent(), $label);
 }
 private function request($accept)
 {
     $app = new Application('test');
     $app['dispatcher']->addSubscriber(new ContentNegotiationSubscriber($app));
     $app->get('/content/negociation', function () {
         return '';
     });
     $client = new Client($app);
     $client->request('GET', '/content/negociation', array(), array(), array('HTTP_Accept' => $accept));
     return $client->getResponse();
 }
 public function testANotFoundResponseIsReturned()
 {
     $app = new Application();
     $app['exception_handler'] = new PhraseaExceptionHandlerSubscriber(PhraseaExceptionHandler::register());
     $app->get('/', function () {
         throw new NotFoundHttpException();
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals(404, $client->getResponse()->getStatusCode());
 }
 public function testHttpAuthentication()
 {
     $app = $this->createApplication('http');
     $client = new Client($app);
     $client->request('get', '/');
     $this->assertEquals(401, $client->getResponse()->getStatusCode());
     $this->assertEquals('Basic realm="Secured"', $client->getResponse()->headers->get('www-authenticate'));
     $client->request('get', '/', array(), array(), array('PHP_AUTH_USER' => 'dennis', 'PHP_AUTH_PW' => 'foo'));
     $this->assertEquals('dennisAUTHENTICATED', $client->getResponse()->getContent());
     $client->request('get', '/admin');
     $this->assertEquals(403, $client->getResponse()->getStatusCode());
     $client->restart();
     $client->request('get', '/');
     $this->assertEquals(401, $client->getResponse()->getStatusCode());
     $this->assertEquals('Basic realm="Secured"', $client->getResponse()->headers->get('www-authenticate'));
     $client->request('get', '/', array(), array(), array('PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => 'foo'));
     $this->assertEquals('adminAUTHENTICATEDADMIN', $client->getResponse()->getContent());
     $client->request('get', '/admin');
     $this->assertEquals('admin', $client->getResponse()->getContent());
 }
 /**
  * @dataProvider provideExceptionsAndCode
  */
 public function testError($exception, $code)
 {
     $app = new Application('test');
     $app['dispatcher']->addSubscriber(new ApiExceptionHandlerSubscriber($app));
     $app->get('/', function () use($exception) {
         throw $exception;
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals($code, $client->getResponse()->getStatusCode());
 }