getRequest() public method

public getRequest ( ) : Request | null
return Symfony\Component\HttpFoundation\Request | null A Request instance
Esempio n. 1
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');
     $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');
 }
Esempio n. 2
0
 /** @test */
 public function it_passes_payload_to_token_translator()
 {
     $iat = time();
     $mock = $this->getMock('Jsor\\Stack\\Stub\\CallableStub');
     $mock->expects($this->once())->method('__invoke')->with(['iat' => $iat] + $this->payload())->will($this->returnValue('foo'));
     $app = $this->createDecoratedApplication(['token_translator' => $mock]);
     $client = new Client($app);
     $client->request('GET', '/protected/token', [], [], ['HTTP_AUTHORIZATION' => sprintf('Bearer %s', $this->validToken(['iat' => $iat]))]);
     $this->assertSame('foo', $client->getRequest()->attributes->get('stack.authn.token'));
 }
 public function testFormAuthentication()
 {
     $app = $this->createApplication('form');
     $client = new Client($app);
     $client->request('get', '/');
     $this->assertEquals('ANONYMOUS', $client->getResponse()->getContent());
     $client->request('post', '/login_check', array('_username' => 'fabien', '_password' => 'bar'));
     $this->assertEquals('Bad credentials', $app['security.last_error']($client->getRequest()));
     // hack to re-close the session as the previous assertions re-opens it
     $client->getRequest()->getSession()->save();
     $client->request('post', '/login_check', array('_username' => 'fabien', '_password' => 'foo'));
     $this->assertEquals('', $app['security.last_error']($client->getRequest()));
     $client->getRequest()->getSession()->save();
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $this->assertEquals('http://localhost/', $client->getResponse()->getTargetUrl());
     $client->request('get', '/');
     $this->assertEquals('fabienAUTHENTICATED', $client->getResponse()->getContent());
     $client->request('get', '/admin');
     $this->assertEquals(403, $client->getResponse()->getStatusCode());
     $client->request('get', '/logout');
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $this->assertEquals('http://localhost/', $client->getResponse()->getTargetUrl());
     $client->request('get', '/');
     $this->assertEquals('ANONYMOUS', $client->getResponse()->getContent());
     $client->request('get', '/admin');
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $this->assertEquals('http://localhost/login', $client->getResponse()->getTargetUrl());
     $client->request('post', '/login_check', array('_username' => 'admin', '_password' => 'foo'));
     $this->assertEquals('', $app['security.last_error']($client->getRequest()));
     $client->getRequest()->getSession()->save();
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $this->assertEquals('http://localhost/admin', $client->getResponse()->getTargetUrl());
     $client->request('get', '/');
     $this->assertEquals('adminAUTHENTICATEDADMIN', $client->getResponse()->getContent());
     $client->request('get', '/admin');
     $this->assertEquals('admin', $client->getResponse()->getContent());
 }
 public function testExposedExceptions()
 {
     $app = $this->createApplication('form');
     $app['security.hide_user_not_found'] = false;
     $client = new Client($app);
     $client->request('get', '/');
     $this->assertEquals('ANONYMOUS', $client->getResponse()->getContent());
     $client->request('post', '/login_check', array('_username' => 'fabien', '_password' => 'bar'));
     $this->assertEquals('The presented password is invalid.', $app['security.last_error']($client->getRequest()));
     $client->getRequest()->getSession()->save();
     $client->request('post', '/login_check', array('_username' => 'unknown', '_password' => 'bar'));
     $this->assertEquals('Username "unknown" does not exist.', $app['security.last_error']($client->getRequest()));
     $client->getRequest()->getSession()->save();
 }
Esempio n. 5
0
 public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
 {
     $source = tempnam(sys_get_temp_dir(), 'source');
     $kernel = new TestHttpKernel();
     $client = new Client($kernel);
     $file = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\UploadedFile')->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true))->setMethods(array('getSize'))->getMock();
     $file->expects($this->once())->method('getSize')->will($this->returnValue(INF));
     $client->request('POST', '/', array(), array($file));
     $files = $client->getRequest()->files->all();
     $this->assertCount(1, $files);
     $file = $files[0];
     $this->assertFalse($file->isValid());
     $this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
     $this->assertEquals('mime/original', $file->getClientMimeType());
     $this->assertEquals('original', $file->getClientOriginalName());
     $this->assertEquals(0, $file->getClientSize());
     unlink($source);
 }
 public function resourceTypeDebugEndpointAction(Request $request)
 {
     $parameters = array();
     $server = array('HTTP_Authorization' => implode(' ', array('Bearer', $request->query->get('access_token'))));
     $client = new Client($this->get('kernel'));
     $crawler = $client->request('GET', '/api/v1.0/resource/debug_endpoint', $parameters, array(), $server);
     $resourceResponse = json_decode($client->getResponse()->getContent(), true);
     $resourceRequest = get_object_vars($client->getRequest());
     return $this->render('TestBundle:demo/resource_type:debug_endpoint.html.twig', array('resource_response' => $resourceResponse, 'resource_request' => $resourceRequest));
 }
Esempio n. 7
0
 public function resourceTypeDebugEndpointAction(Request $request, Application $app)
 {
     $parameters = [];
     $server = ['HTTP_Authorization' => implode(' ', ['Bearer', $request->query->get('access_token')])];
     $client = new Client($app);
     $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server);
     $resourceResponse = json_decode($client->getResponse()->getContent(), true);
     $resourceRequest = get_object_vars($client->getRequest());
     return $app['twig']->render('demo/resource_type/debug_endpoint.html.twig', ['resource_response' => $resourceResponse, 'resource_request' => $resourceRequest]);
 }