From 1005fd1f7988d8fbfe420dd5b4f005447f2d03f0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 24 Apr 2013 18:19:42 +0200 Subject: [PATCH 1/3] fixed Client implementation to return the right Response (closes #4475) --- UPGRADE-2.3.md | 37 +++++++++++-- src/Symfony/Bundle/FrameworkBundle/Client.php | 2 +- .../Tests/Functional/SubRequestsTest.php | 2 +- .../AuthenticationCommencingTest.php | 2 +- .../Tests/Functional/CsrfFormLoginTest.php | 12 ++--- .../Tests/Functional/FormLoginTest.php | 8 +-- .../Functional/LocalizedRoutesAsPathTest.php | 10 ++-- .../SecurityRoutingIntegrationTest.php | 10 ++-- .../Tests/Functional/SwitchUserTest.php | 6 +-- src/Symfony/Component/BrowserKit/CHANGELOG.md | 10 ++++ src/Symfony/Component/BrowserKit/Client.php | 54 ++++++++++++++----- .../Component/BrowserKit/Tests/ClientTest.php | 28 ++++++++++ src/Symfony/Component/HttpKernel/Client.php | 21 ++++++++ .../Component/HttpKernel/Tests/ClientTest.php | 12 +++-- 14 files changed, 168 insertions(+), 46 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 4bfdf76423..66fb4f1d4a 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -1,7 +1,8 @@ UPGRADE FROM 2.2 to 2.3 ======================= -### Form +Form +---- * Although this was not officially supported nor documented, it was possible to set the option "validation_groups" to false, resulting in the group "Default" @@ -109,7 +110,8 @@ } ``` -### PropertyAccess +PropertyAccess +-------------- * PropertyAccessor was changed to continue its search for a property or method even if a non-public match was found. This means that the property "author" @@ -161,7 +163,8 @@ } ``` -### DomCrawler +DomCrawler +---------- * `Crawler::each()` and `Crawler::reduce()` now return Crawler instances instead of DomElement instances: @@ -181,3 +184,31 @@ return $crawler->text(); }); ``` + +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()`. diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index 52efc80619..bb208dd5f5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -69,7 +69,7 @@ class Client extends BaseClient return false; } - return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response); + return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->originResponse); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php index 2676653b1e..f69efac03b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php @@ -21,6 +21,6 @@ class SubRequestsTest extends WebTestCase $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->getResponse()->getContent()); + $this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getOriginResponse()->getContent()); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php index e94a21e5ba..54e7755aae 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php @@ -19,6 +19,6 @@ class AuthenticationCommencingTest extends WebTestCase $client->insulate(); $client->request('GET', '/secure-but-not-covered-by-access-control'); - $this->assertRedirect($client->getResponse(), '/login'); + $this->assertRedirect($client->getOriginResponse(), '/login'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php index 4c4c1ac295..3eb4431796 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -29,7 +29,7 @@ class CsrfFormLoginTest extends WebTestCase $form['user_login[password]'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/profile'); + $this->assertRedirect($client->getOriginResponse(), '/profile'); $crawler = $client->followRedirect(); @@ -44,7 +44,7 @@ class CsrfFormLoginTest extends WebTestCase $client->click($logoutLinks[0]); - $this->assertRedirect($client->getResponse(), '/'); + $this->assertRedirect($client->getOriginResponse(), '/'); } /** @@ -59,7 +59,7 @@ class CsrfFormLoginTest extends WebTestCase $form['user_login[_token]'] = ''; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/login'); + $this->assertRedirect($client->getOriginResponse(), '/login'); $text = $client->followRedirect()->text(); $this->assertContains('Invalid CSRF token.', $text); @@ -79,7 +79,7 @@ class CsrfFormLoginTest extends WebTestCase $form['user_login[_target_path]'] = '/foo'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/foo'); + $this->assertRedirect($client->getOriginResponse(), '/foo'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -95,13 +95,13 @@ class CsrfFormLoginTest extends WebTestCase $client->insulate(); $client->request('GET', '/protected-resource'); - $this->assertRedirect($client->getResponse(), '/login'); + $this->assertRedirect($client->getOriginResponse(), '/login'); $form = $client->followRedirect()->selectButton('login')->form(); $form['user_login[username]'] = 'johannes'; $form['user_login[password]'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/protected-resource'); + $this->assertRedirect($client->getOriginResponse(), '/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 0dc038e1df..4841f3e0a1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -29,7 +29,7 @@ class FormLoginTest extends WebTestCase $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/profile'); + $this->assertRedirect($client->getOriginResponse(), '/profile'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -50,7 +50,7 @@ class FormLoginTest extends WebTestCase $form['_target_path'] = '/foo'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/foo'); + $this->assertRedirect($client->getOriginResponse(), '/foo'); $text = $client->followRedirect()->text(); $this->assertContains('Hello johannes!', $text); @@ -66,13 +66,13 @@ class FormLoginTest extends WebTestCase $client->insulate(); $client->request('GET', '/protected_resource'); - $this->assertRedirect($client->getResponse(), '/login'); + $this->assertRedirect($client->getOriginResponse(), '/login'); $form = $client->followRedirect()->selectButton('login')->form(); $form['_username'] = 'johannes'; $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/protected_resource'); + $this->assertRedirect($client->getOriginResponse(), '/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 84c79055a9..d7eeeb28d0 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php @@ -27,11 +27,11 @@ class LocalizedRoutesAsPathTest extends WebTestCase $form['_password'] = 'test'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/'.$locale.'/profile'); + $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/profile'); $this->assertEquals('Profile', $client->followRedirect()->text()); $client->request('GET', '/'.$locale.'/logout'); - $this->assertRedirect($client->getResponse(), '/'.$locale.'/'); + $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/'); $this->assertEquals('Homepage', $client->followRedirect()->text()); } @@ -49,7 +49,7 @@ class LocalizedRoutesAsPathTest extends WebTestCase $form['_password'] = 'foobar'; $client->submit($form); - $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); } /** @@ -61,7 +61,7 @@ class LocalizedRoutesAsPathTest extends WebTestCase $client->insulate(); $client->request('GET', '/'.$locale.'/secure/'); - $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); } /** @@ -73,7 +73,7 @@ class LocalizedRoutesAsPathTest extends WebTestCase $client->insulate(); $crawler = $client->request('GET', '/'.$locale.'/secure/'); - $this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse()); + $this->assertCount(1, $crawler->selectButton('login'), (string) $client->getOriginResponse()); } public function getLocales() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index a0a1ca2d4a..2b41e6b9b1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -22,7 +22,7 @@ class SecurityRoutingIntegrationTest extends WebTestCase $client->insulate(); $client->request('GET', '/protected_resource'); - $this->assertRedirect($client->getResponse(), '/login'); + $this->assertRedirect($client->getOriginResponse(), '/login'); } /** @@ -38,7 +38,7 @@ class SecurityRoutingIntegrationTest extends WebTestCase $client->insulate(); $client->request('GET', '/unprotected_resource'); - $this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse()); + $this->assertEquals(404, $client->getOriginResponse()->getStatusCode(), (string) $client->getOriginResponse()); } /** @@ -60,7 +60,7 @@ class SecurityRoutingIntegrationTest extends WebTestCase $client->request('GET', '/highly_protected_resource'); - $this->assertNotEquals(404, $client->getResponse()->getStatusCode()); + $this->assertNotEquals(404, $client->getOriginResponse()->getStatusCode()); } /** @@ -93,12 +93,12 @@ class SecurityRoutingIntegrationTest extends WebTestCase private function assertAllowed($client, $path) { $client->request('GET', $path); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertEquals(404, $client->getOriginResponse()->getStatusCode()); } private function assertRestricted($client, $path) { $client->request('GET', $path); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getOriginResponse()->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 8c0c33925c..ae52de6ff9 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -25,7 +25,7 @@ class SwitchUserTest extends WebTestCase $client->request('GET', '/profile?_switch_user='.$targetUser); - $this->assertEquals($expectedStatus, $client->getResponse()->getStatusCode()); + $this->assertEquals($expectedStatus, $client->getOriginResponse()->getStatusCode()); $this->assertEquals($expectedUser, $client->getProfile()->getCollector('security')->getUser()); } @@ -36,7 +36,7 @@ class SwitchUserTest extends WebTestCase $client->request('GET', '/profile?_switch_user=user_cannot_switch_1'); $client->request('GET', '/profile?_switch_user=user_cannot_switch_2'); - $this->assertEquals(500, $client->getResponse()->getStatusCode()); + $this->assertEquals(500, $client->getOriginResponse()->getStatusCode()); $this->assertEquals('user_cannot_switch_1', $client->getProfile()->getCollector('security')->getUser()); } @@ -47,7 +47,7 @@ class SwitchUserTest extends WebTestCase $client->request('GET', '/profile?_switch_user=user_cannot_switch_1'); $client->request('GET', '/profile?_switch_user=_exit'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(200, $client->getOriginResponse()->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 42d32a7efe..713f8297fd 100644 --- a/src/Symfony/Component/BrowserKit/CHANGELOG.md +++ b/src/Symfony/Component/BrowserKit/CHANGELOG.md @@ -1,6 +1,16 @@ CHANGELOG ========= +2.3.0 +----- + + * added `Client::getOriginRequest()` and `Client::getOriginResponse()` to + have access to the origin request and response objects + * [BC BREAK] The `Symfony\Component\HttpKernel\Client::getRequest()` method now + returns a `Symfony\Component\BrowserKit\Request` instance + * [BC BREAK] The `Symfony\Component\HttpKernel\Client::request()` method now + always returns a `Symfony\Component\BrowserKit\Response` instance + 2.1.0 ----- diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index fe7c3adfc9..6248ed1125 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -33,7 +33,9 @@ abstract class Client protected $history; protected $cookieJar; protected $server; + protected $originRequest; protected $request; + protected $originResponse; protected $response; protected $crawler; protected $insulated; @@ -177,6 +179,19 @@ abstract class Client return $this->response; } + /** + * Returns the origin response instance. + * + * The origin response is the response instance that is returned + * by the code that handles requests. + * + * @return object A response instance + */ + public function getOriginResponse() + { + return $this->originResponse; + } + /** * Returns the current Request instance. * @@ -189,6 +204,19 @@ abstract class Client return $this->request; } + /** + * Returns the origin Request instance. + * + * The origin request is the request instance that is sent + * to the code that handles requests. + * + * @return object A Request instance + */ + public function getOriginRequest() + { + return $this->originRequest; + } + /** * Clicks on a given link. * @@ -250,39 +278,39 @@ abstract class Client $server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST); $server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME); - $request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content); + $this->request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content); - $this->request = $this->filterRequest($request); + $this->originRequest = $this->filterRequest($this->request); if (true === $changeHistory) { - $this->history->add($request); + $this->history->add($this->request); } if ($this->insulated) { - $this->response = $this->doRequestInProcess($this->request); + $this->originResponse = $this->doRequestInProcess($this->originRequest); } else { - $this->response = $this->doRequest($this->request); + $this->originResponse = $this->doRequest($this->originRequest); } - $response = $this->filterResponse($this->response); + $this->response = $this->filterResponse($this->originResponse); - $this->cookieJar->updateFromResponse($response, $uri); + $this->cookieJar->updateFromResponse($this->response, $uri); - $this->redirect = $response->getHeader('Location'); + $this->redirect = $this->response->getHeader('Location'); if ($this->followRedirects && $this->redirect) { return $this->crawler = $this->followRedirect(); } - return $this->crawler = $this->createCrawlerFromContent($request->getUri(), $response->getContent(), $response->getHeader('Content-Type')); + return $this->crawler = $this->createCrawlerFromContent($this->request->getUri(), $this->response->getContent(), $this->response->getHeader('Content-Type')); } /** * Makes a request in another process. * - * @param Request $request A Request instance + * @param object $request An origin request instance * - * @return Response A Response instance + * @return object An origin response instance * * @throws \RuntimeException When processing returns exit code */ @@ -302,9 +330,9 @@ abstract class Client /** * Makes a request. * - * @param Request $request A Request instance + * @param object $request An origin request instance * - * @return Response A Response instance + * @return object An origin response instance */ abstract protected function doRequest($request); diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 1bf9e5c844..2c9540581d 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -17,6 +17,10 @@ use Symfony\Component\BrowserKit\CookieJar; use Symfony\Component\BrowserKit\Request; use Symfony\Component\BrowserKit\Response; +class SpecialResponse extends Response +{ +} + class TestClient extends Client { protected $nextResponse = null; @@ -44,6 +48,15 @@ class TestClient extends Client return $response; } + protected function filterResponse($response) + { + if ($response instanceof SpecialResponse) { + return new Response($response->getContent(), $response->getStatus(), $response->getHeaders()); + } + + return $response; + } + protected function getScript($request) { $r = new \ReflectionClass('Symfony\Component\BrowserKit\Response'); @@ -100,6 +113,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client->request('GET', 'http://example.com/'); $this->assertEquals('foo', $client->getResponse()->getContent(), '->getCrawler() returns the Response of the last request'); + $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() + { + $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()); } public function testGetContent() diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index 6c896749a3..10573cdb29 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\BrowserKit\Client as BaseClient; use Symfony\Component\BrowserKit\Request as DomRequest; use Symfony\Component\BrowserKit\Response as DomResponse; @@ -49,6 +50,26 @@ class Client extends BaseClient $this->followRedirects = false; } + /** + * {@inheritdoc} + * + * @return Request A Request instance + */ + public function getOriginRequest() + { + return parent::getOriginRequest(); + } + + /** + * {@inheritdoc} + * + * @return Response A Response instance + */ + public function getOriginResponse() + { + return parent::getOriginResponse(); + } + /** * Makes a request. * diff --git a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php index d85b1e4aec..c2388617f6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -35,13 +35,17 @@ class ClientTest extends \PHPUnit_Framework_TestCase $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()); $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'); + $this->assertEquals('www.example.com', $client->getOriginRequest()->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'); + $this->assertEquals('http://www.example.com/?parameter='.urlencode('http://google.com'), $client->getOriginRequest()->getUri(), '->doRequest() uses the request handler to make the request'); } public function testGetScript() @@ -120,7 +124,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase foreach ($files as $file) { $client->request('POST', '/', array(), array('foo' => $file)); - $files = $client->getRequest()->files->all(); + $files = $client->getOriginRequest()->files->all(); $this->assertCount(1, $files); @@ -159,7 +163,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client->request('POST', '/', array(), array($file)); - $files = $client->getRequest()->files->all(); + $files = $client->getOriginRequest()->files->all(); $this->assertCount(1, $files); From 84ca34b45ef4c438f5553d62c945d0b97d102d63 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 24 Apr 2013 21:08:47 +0200 Subject: [PATCH 2/3] alternate fix where we had accessor for the BrowerKit request/response instances --- UPGRADE-2.3.md | 28 ++----------- src/Symfony/Bundle/FrameworkBundle/Client.php | 2 +- .../Tests/Functional/SubRequestsTest.php | 2 +- .../AuthenticationCommencingTest.php | 2 +- .../Tests/Functional/CsrfFormLoginTest.php | 12 +++--- .../Tests/Functional/FormLoginTest.php | 8 ++-- .../Functional/LocalizedRoutesAsPathTest.php | 10 ++--- .../SecurityRoutingIntegrationTest.php | 10 ++--- .../Tests/Functional/SwitchUserTest.php | 6 +-- src/Symfony/Component/BrowserKit/CHANGELOG.md | 8 ++-- src/Symfony/Component/BrowserKit/Client.php | 42 ++++++++++--------- .../Component/BrowserKit/Tests/ClientTest.php | 14 ++----- src/Symfony/Component/HttpKernel/Client.php | 8 ++-- .../Component/HttpKernel/Tests/ClientTest.php | 16 +++---- 14 files changed, 73 insertions(+), 95 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 66fb4f1d4a..82fc6fa155 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 bb208dd5f5..52efc80619 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -69,7 +69,7 @@ class Client extends BaseClient 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 f69efac03b..2676653b1e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php @@ -21,6 +21,6 @@ class SubRequestsTest extends WebTestCase $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 54e7755aae..e94a21e5ba 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php @@ -19,6 +19,6 @@ class AuthenticationCommencingTest extends WebTestCase $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 3eb4431796..4c4c1ac295 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -29,7 +29,7 @@ class CsrfFormLoginTest extends WebTestCase $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 @@ class CsrfFormLoginTest extends WebTestCase $client->click($logoutLinks[0]); - $this->assertRedirect($client->getOriginResponse(), '/'); + $this->assertRedirect($client->getResponse(), '/'); } /** @@ -59,7 +59,7 @@ class CsrfFormLoginTest extends WebTestCase $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 @@ class CsrfFormLoginTest extends WebTestCase $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 @@ class CsrfFormLoginTest extends WebTestCase $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 4841f3e0a1..0dc038e1df 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -29,7 +29,7 @@ class FormLoginTest extends WebTestCase $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 @@ class FormLoginTest extends WebTestCase $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 @@ class FormLoginTest extends WebTestCase $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 d7eeeb28d0..84c79055a9 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php @@ -27,11 +27,11 @@ class LocalizedRoutesAsPathTest extends WebTestCase $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 @@ class LocalizedRoutesAsPathTest extends WebTestCase $form['_password'] = 'foobar'; $client->submit($form); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); } /** @@ -61,7 +61,7 @@ class LocalizedRoutesAsPathTest extends WebTestCase $client->insulate(); $client->request('GET', '/'.$locale.'/secure/'); - $this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login'); + $this->assertRedirect($client->getResponse(), '/'.$locale.'/login'); } /** @@ -73,7 +73,7 @@ class LocalizedRoutesAsPathTest extends WebTestCase $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 2b41e6b9b1..a0a1ca2d4a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -22,7 +22,7 @@ class SecurityRoutingIntegrationTest extends WebTestCase $client->insulate(); $client->request('GET', '/protected_resource'); - $this->assertRedirect($client->getOriginResponse(), '/login'); + $this->assertRedirect($client->getResponse(), '/login'); } /** @@ -38,7 +38,7 @@ class SecurityRoutingIntegrationTest extends WebTestCase $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 @@ class SecurityRoutingIntegrationTest extends WebTestCase $client->request('GET', '/highly_protected_resource'); - $this->assertNotEquals(404, $client->getOriginResponse()->getStatusCode()); + $this->assertNotEquals(404, $client->getResponse()->getStatusCode()); } /** @@ -93,12 +93,12 @@ class SecurityRoutingIntegrationTest extends WebTestCase 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 ae52de6ff9..8c0c33925c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -25,7 +25,7 @@ class SwitchUserTest extends WebTestCase $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 @@ class SwitchUserTest extends WebTestCase $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 @@ class SwitchUserTest extends WebTestCase $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 713f8297fd..92885eadcd 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 6248ed1125..0e63f75cf5 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 @@ abstract class Client * * @api */ - public function getResponse() + public function getInternalResponse() { - return $this->response; + return $this->internalResponse; } /** @@ -186,10 +186,12 @@ abstract class Client * 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 @@ abstract class Client * * @api */ - public function getRequest() + public function getInternalRequest() { - return $this->request; + return $this->internalRequest; } /** @@ -210,11 +212,13 @@ abstract class Client * 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 @@ abstract class Client $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 2c9540581d..82322acc5c 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -103,9 +103,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase $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 @@ class ClientTest extends \PHPUnit_Framework_TestCase $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 10573cdb29..217623bc31 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -55,9 +55,9 @@ class Client extends BaseClient * * @return Request A Request instance */ - public function getOriginRequest() + public function getRequest() { - return parent::getOriginRequest(); + return parent::getRequest(); } /** @@ -65,9 +65,9 @@ class Client extends BaseClient * * @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 c2388617f6..755d7f614c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/ClientTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/ClientTest.php @@ -35,17 +35,17 @@ class ClientTest extends \PHPUnit_Framework_TestCase $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 @@ class ClientTest extends \PHPUnit_Framework_TestCase 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 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client->request('POST', '/', array(), array($file)); - $files = $client->getOriginRequest()->files->all(); + $files = $client->getRequest()->files->all(); $this->assertCount(1, $files); From 31cefc642b0ea7f17916171301845606e77d5906 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 25 Apr 2013 07:52:12 +0200 Subject: [PATCH 3/3] made some small tweaks --- UPGRADE-2.3.md | 8 ---- src/Symfony/Bundle/FrameworkBundle/Client.php | 6 ++- src/Symfony/Component/BrowserKit/CHANGELOG.md | 4 -- src/Symfony/Component/BrowserKit/Client.php | 38 ++++++++++--------- src/Symfony/Component/HttpKernel/Client.php | 8 ++-- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 82fc6fa155..445e460a05 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -184,11 +184,3 @@ DomCrawler return $crawler->text(); }); ``` - -BrowserKit ----------- - - * 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 52efc80619..1819649769 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -85,7 +85,7 @@ class Client extends BaseClient } /** - * Makes a request. + * {@inheritdoc} * * @param Request $request A Request instance * @@ -113,6 +113,10 @@ class Client extends BaseClient /** * {@inheritdoc} + * + * @param Request $request A Request instance + * + * @return Response A Response instance */ protected function doRequestInProcess($request) { diff --git a/src/Symfony/Component/BrowserKit/CHANGELOG.md b/src/Symfony/Component/BrowserKit/CHANGELOG.md index 92885eadcd..f67099bdbe 100644 --- a/src/Symfony/Component/BrowserKit/CHANGELOG.md +++ b/src/Symfony/Component/BrowserKit/CHANGELOG.md @@ -6,10 +6,6 @@ CHANGELOG * 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 the request instance created by the client - * [BC BREAK] The `Symfony\Component\HttpKernel\Client::request()` method now - 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 0e63f75cf5..39945740b0 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -158,7 +158,7 @@ abstract class Client /** * Returns the current Crawler instance. * - * @return Crawler A Crawler instance + * @return Crawler|null A Crawler instance * * @api */ @@ -168,9 +168,9 @@ abstract class Client } /** - * Returns the current Response instance. + * Returns the current BrowserKit Response instance. * - * @return Response A Response instance + * @return Response|null A BrowserKit Response instance * * @api */ @@ -180,12 +180,14 @@ abstract class Client } /** - * Returns the origin response instance. + * Returns the current origin response instance. * * The origin response is the response instance that is returned * by the code that handles requests. * - * @return object A response instance + * @return object|null A response instance + * + * @see doRequest * * @api */ @@ -195,9 +197,9 @@ abstract class Client } /** - * Returns the current Request instance. + * Returns the current BrowserKit Request instance. * - * @return Request A Request instance + * @return Request|null A BrowserKit Request instance * * @api */ @@ -207,14 +209,16 @@ abstract class Client } /** - * Returns the origin Request instance. + * Returns the current origin Request instance. * * The origin request is the request instance that is sent * to the code that handles requests. * - * @api + * @return object|null A Request instance * - * @return object A Request instance + * @see doRequest + * + * @api */ public function getRequest() { @@ -343,7 +347,7 @@ abstract class Client /** * Returns the script to execute when the request must be insulated. * - * @param Request $request A Request instance + * @param object $request An origin request instance * * @throws \LogicException When this abstract class is not implemented */ @@ -355,11 +359,11 @@ abstract class Client } /** - * Filters the request. + * Filters the BrowserKit request to the origin one. * - * @param Request $request The request to filter + * @param Request $request The BrowserKit Request to filter * - * @return Request + * @return object An origin request instance */ protected function filterRequest(Request $request) { @@ -367,11 +371,11 @@ abstract class Client } /** - * Filters the Response. + * Filters the origin response to the BrowserKit one. * - * @param Response $response The Response to filter + * @param object $response The origin response to filter * - * @return Response + * @return Response An BrowserKit Response instance */ protected function filterResponse($response) { diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index 217623bc31..bb427b35af 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -53,7 +53,7 @@ class Client extends BaseClient /** * {@inheritdoc} * - * @return Request A Request instance + * @return Request|null A Request instance */ public function getRequest() { @@ -63,7 +63,7 @@ class Client extends BaseClient /** * {@inheritdoc} * - * @return Response A Response instance + * @return Response|null A Response instance */ public function getResponse() { @@ -121,7 +121,7 @@ EOF; /** * Converts the BrowserKit request to a HttpKernel request. * - * @param DomRequest $request A Request instance + * @param DomRequest $request A DomRequest instance * * @return Request A Request instance */ @@ -188,7 +188,7 @@ EOF; * * @param Response $response A Response instance * - * @return Response A Response instance + * @return DomResponse A DomResponse instance */ protected function filterResponse($response) {