diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 66fb4f1d4ad7..82fc6fa15506 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -188,27 +188,7 @@ DomCrawler BrowserKit ---------- - * The `Symfony\Component\BrowserKit\Client::getResponse()` method now - **always** returns a `Symfony\Component\BrowserKit\Response` instance. To - get the response from the code that handled the request, use the new - `getOriginResponse()` method instead of `getResponse()`. - - * The `Symfony\Component\BrowserKit\Client::getRequest()` method now - **always** returns a `Symfony\Component\BrowserKit\Request` instance. To - get the response from the code that handled the request, use the new - `getOriginRequest()` method instead of `getRequest()`. - -HttpKernel ----------- - - * The `Symfony\Component\HttpKernel\Client::getResponse()` now returns a - `Symfony\Component\BrowserKit\Response` instance instead of a - `Symfony\Component\HttpFoundation\Response` one (because of a change in - BrowserKit -- see above). You can still get the `HttpFoundation` response - by using `getOriginResponse()` instead of `getResponse()`. - - * The `Symfony\Component\HttpKernel\Client::getRequest()` now returns a - `Symfony\Component\BrowserKit\Request` instance instead of a - `Symfony\Component\HttpFoundation\Request` one (because of a change in - BrowserKit -- see above). You can still get the `HttpFoundation` response - by using `getOriginRequest()` instead of `getRequest()`. + * The `Symfony\Component\BrowserKit\Client::getResponse()/getRequest()` + methods now **always** return the request/response instance from the code + that handles the request. To get the BrowserKit request/response instances, + use the new `getInternalResponse()/getInternalRequest()` methods. diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index bb208dd5f5a8..52efc80619ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -69,7 +69,7 @@ public function getProfile() return false; } - return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->originResponse); + return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php index f69efac03b24..2676653b1ef6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php @@ -21,6 +21,6 @@ public function testStateAfterSubRequest() $client = $this->createClient(array('test_case' => 'Session', 'root_config' => 'config.yml')); $client->request('GET', 'https://localhost/subrequest/en'); - $this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getOriginResponse()->getContent()); + $this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent()); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php index 54e7755aae71..e94a21e5bae7 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php @@ -19,6 +19,6 @@ public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped() $client->insulate(); $client->request('GET', '/secure-but-not-covered-by-access-control'); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php index 3eb44317967f..4c4c1ac2953a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -29,7 +29,7 @@ public function testFormLoginAndLogoutWithCsrfTokens($config) $form['user_login[password]'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/profile'); + $this->assertRedirect($client->getResponse(), '/profile'); $crawler = $client->followRedirect(); @@ -44,7 +44,7 @@ public function testFormLoginAndLogoutWithCsrfTokens($config) $client->click($logoutLinks[0]); - $this->assertRedirect($client->getOriginResponse(), '/'); + $this->assertRedirect($client->getResponse(), '/'); } /** @@ -59,7 +59,7 @@ public function testFormLoginWithInvalidCsrfToken($config) $form['user_login[_token]'] = ''; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); $text = $client->followRedirect()->text(); $this->assertContains('Invalid CSRF token.', $text); @@ -79,7 +79,7 @@ public function testFormLoginWithCustomTargetPath($config) $form['user_login[_target_path]'] = '/foo'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/foo'); + $this->assertRedirect($client->getResponse(), '/foo'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -95,13 +95,13 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config) $client->insulate(); $client->request('GET', '/protected-resource'); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); $form = $client->followRedirect()->selectButton('login')->form(); $form['user_login[username]'] = 'johannes'; $form['user_login[password]'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/protected-resource'); + $this->assertRedirect($client->getResponse(), '/protected-resource'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php index 4841f3e0a1c1..0dc038e1df26 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -29,7 +29,7 @@ public function testFormLogin($config) $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/profile'); + $this->assertRedirect($client->getResponse(), '/profile'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -50,7 +50,7 @@ public function testFormLoginWithCustomTargetPath($config) $form['_target_path'] = '/foo'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/foo'); + $this->assertRedirect($client->getResponse(), '/foo'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -66,13 +66,13 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config) $client->insulate(); $client->request('GET', '/protected_resource'); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); $form = $client->followRedirect()->selectButton('login')->form(); $form['_username'] = 'johannes'; $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/protected_resource'); + $this->assertRedirect($client->getResponse(), '/protected_resource'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php index d7eeeb28d013..84c79055a977 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php @@ -27,11 +27,11 @@ public function testLoginLogoutProcedure($locale) $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/profile'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/profile'); $this->assertEquals('Profile', $client->followRedirect()->text()); $client->request('GET', '/'.$locale.'/logout'); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/'); $this->assertEquals('Homepage', $client->followRedirect()->text()); } @@ -49,7 +49,7 @@ public function testLoginFailureWithLocalizedFailurePath($locale) $form['_password'] = 'foobar'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); } /** @@ -61,7 +61,7 @@ public function testAccessRestrictedResource($locale) $client->insulate(); $client->request('GET', '/'.$locale.'/secure/'); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); } /** @@ -73,7 +73,7 @@ public function testAccessRestrictedResourceWithForward($locale) $client->insulate(); $crawler = $client->request('GET', '/'.$locale.'/secure/'); - $this->assertCount(1, $crawler->selectButton('login'), (string) $client->getOriginResponse()); + $this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse()); } public function getLocales() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index 2b41e6b9b1cf..a0a1ca2d4ad0 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -22,7 +22,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c $client->insulate(); $client->request('GET', '/protected_resource'); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); } /** @@ -38,7 +38,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config) $client->insulate(); $client->request('GET', '/unprotected_resource'); - $this->assertEquals(404, $client->getOriginResponse()->getStatusCode(), (string) $client->getOriginResponse()); + $this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse()); } /** @@ -60,7 +60,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWith $client->request('GET', '/highly_protected_resource'); - $this->assertNotEquals(404, $client->getOriginResponse()->getStatusCode()); + $this->assertNotEquals(404, $client->getResponse()->getStatusCode()); } /** @@ -93,12 +93,12 @@ public function testSecurityConfigurationForMultipleIPAddresses($config) private function assertAllowed($client, $path) { $client->request('GET', $path); - $this->assertEquals(404, $client->getOriginResponse()->getStatusCode()); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); } private function assertRestricted($client, $path) { $client->request('GET', $path); - $this->assertEquals(302, $client->getOriginResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); } public function getConfigs() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php index ae52de6ff9fc..8c0c33925ca9 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -25,7 +25,7 @@ public function testSwitchUser($originalUser, $targetUser, $expectedUser, $expec $client->request('GET', '/profile?_switch_user='.$targetUser); - $this->assertEquals($expectedStatus, $client->getOriginResponse()->getStatusCode()); + $this->assertEquals($expectedStatus, $client->getResponse()->getStatusCode()); $this->assertEquals($expectedUser, $client->getProfile()->getCollector('security')->getUser()); } @@ -36,7 +36,7 @@ public function testSwitchedUserCannotSwitchToOther() $client->request('GET', '/profile?_switch_user=user_cannot_switch_1'); $client->request('GET', '/profile?_switch_user=user_cannot_switch_2'); - $this->assertEquals(500, $client->getOriginResponse()->getStatusCode()); + $this->assertEquals(500, $client->getResponse()->getStatusCode()); $this->assertEquals('user_cannot_switch_1', $client->getProfile()->getCollector('security')->getUser()); } @@ -47,7 +47,7 @@ public function testSwitchedUserExit() $client->request('GET', '/profile?_switch_user=user_cannot_switch_1'); $client->request('GET', '/profile?_switch_user=_exit'); - $this->assertEquals(200, $client->getOriginResponse()->getStatusCode()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals('user_can_switch', $client->getProfile()->getCollector('security')->getUser()); } diff --git a/src/Symfony/Component/BrowserKit/CHANGELOG.md b/src/Symfony/Component/BrowserKit/CHANGELOG.md index 713f8297fdd3..92885eadcd34 100644 --- a/src/Symfony/Component/BrowserKit/CHANGELOG.md +++ b/src/Symfony/Component/BrowserKit/CHANGELOG.md @@ -4,12 +4,12 @@ CHANGELOG 2.3.0 ----- - * added `Client::getOriginRequest()` and `Client::getOriginResponse()` to - have access to the origin request and response objects + * added `Client::getInternalRequest()` and `Client::getInternalResponse()` to + have access to the BrowserKit internal request and response objects * [BC BREAK] The `Symfony\Component\HttpKernel\Client::getRequest()` method now - returns a `Symfony\Component\BrowserKit\Request` instance + returns the request instance created by the client * [BC BREAK] The `Symfony\Component\HttpKernel\Client::request()` method now - always returns a `Symfony\Component\BrowserKit\Response` instance + always returns the response instance created by the client 2.1.0 ----- diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 6248ed11251e..0e63f75cf5e8 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -33,9 +33,9 @@ abstract class Client protected $history; protected $cookieJar; protected $server; - protected $originRequest; + protected $internalRequest; protected $request; - protected $originResponse; + protected $internalResponse; protected $response; protected $crawler; protected $insulated; @@ -174,9 +174,9 @@ public function getCrawler() * * @api */ - public function getResponse() + public function getInternalResponse() { - return $this->response; + return $this->internalResponse; } /** @@ -186,10 +186,12 @@ public function getResponse() * by the code that handles requests. * * @return object A response instance + * + * @api */ - public function getOriginResponse() + public function getResponse() { - return $this->originResponse; + return $this->response; } /** @@ -199,9 +201,9 @@ public function getOriginResponse() * * @api */ - public function getRequest() + public function getInternalRequest() { - return $this->request; + return $this->internalRequest; } /** @@ -210,11 +212,13 @@ public function getRequest() * The origin request is the request instance that is sent * to the code that handles requests. * + * @api + * * @return object A Request instance */ - public function getOriginRequest() + public function getRequest() { - return $this->originRequest; + return $this->request; } /** @@ -278,31 +282,31 @@ public function request($method, $uri, array $parameters = array(), array $files $server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST); $server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME); - $this->request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content); + $this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content); - $this->originRequest = $this->filterRequest($this->request); + $this->request = $this->filterRequest($this->internalRequest); if (true === $changeHistory) { - $this->history->add($this->request); + $this->history->add($this->internalRequest); } if ($this->insulated) { - $this->originResponse = $this->doRequestInProcess($this->originRequest); + $this->response = $this->doRequestInProcess($this->request); } else { - $this->originResponse = $this->doRequest($this->originRequest); + $this->response = $this->doRequest($this->request); } - $this->response = $this->filterResponse($this->originResponse); + $this->internalResponse = $this->filterResponse($this->response); - $this->cookieJar->updateFromResponse($this->response, $uri); + $this->cookieJar->updateFromResponse($this->internalResponse, $uri); - $this->redirect = $this->response->getHeader('Location'); + $this->redirect = $this->internalResponse->getHeader('Location'); if ($this->followRedirects && $this->redirect) { return $this->crawler = $this->followRedirect(); } - return $this->crawler = $this->createCrawlerFromContent($this->request->getUri(), $this->response->getContent(), $this->response->getHeader('Content-Type')); + return $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type')); } /** diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 2c9540581d66..82322acc5c96 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -103,9 +103,6 @@ public function testGetRequest() $this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request'); } - /** - * @covers Symfony\Component\BrowserKit\Client::getResponse - */ public function testGetResponse() { $client = new TestClient(); @@ -116,18 +113,15 @@ public function testGetResponse() $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse(), '->getCrawler() returns the Response of the last request'); } - /** - * @covers Symfony\Component\BrowserKit\Client::getResponse - */ - public function testgetOriginResponse() + public function testGetInternalResponse() { $client = new TestClient(); $client->setNextResponse(new SpecialResponse('foo')); $client->request('GET', 'http://example.com/'); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse()); - $this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse()); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getOriginResponse()); + $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse()); + $this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getInternalResponse()); + $this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse()); } public function testGetContent() diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index 10573cdb29ae..217623bc31bf 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -55,9 +55,9 @@ public function __construct(HttpKernelInterface $kernel, array $server = array() * * @return Request A Request instance */ - public function getOriginRequest() + public function getRequest() { - return parent::getOriginRequest(); + return parent::getRequest(); } /** @@ -65,9 +65,9 @@ public function getOriginRequest() * * @return Response A Response instance */ - public function getOriginResponse() + public function getResponse() { - return parent::getOriginResponse(); + return parent::getResponse(); } /** diff --git a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php index c2388617f605..755d7f614c97 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -35,17 +35,17 @@ public function testDoRequest() $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->getRequest()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $client->getOriginRequest()); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $client->getOriginResponse()); + $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->getOriginRequest()->getHost(), '->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->getOriginRequest()->getUri(), '->doRequest() uses the request handler to make the request'); + $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 testGetScript() @@ -124,7 +124,7 @@ public function testUploadedFile() foreach ($files as $file) { $client->request('POST', '/', array(), array('foo' => $file)); - $files = $client->getOriginRequest()->files->all(); + $files = $client->getRequest()->files->all(); $this->assertCount(1, $files); @@ -163,7 +163,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize() $client->request('POST', '/', array(), array($file)); - $files = $client->getOriginRequest()->files->all(); + $files = $client->getRequest()->files->all(); $this->assertCount(1, $files);