Skip to content

Commit 84ca34b

Browse files
committed
alternate fix where we had accessor for the BrowerKit request/response instances
1 parent 1005fd1 commit 84ca34b

File tree

14 files changed

+73
-95
lines changed

14 files changed

+73
-95
lines changed

UPGRADE-2.3.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,7 @@ DomCrawler
188188
BrowserKit
189189
----------
190190

191-
* The `Symfony\Component\BrowserKit\Client::getResponse()` method now
192-
**always** returns a `Symfony\Component\BrowserKit\Response` instance. To
193-
get the response from the code that handled the request, use the new
194-
`getOriginResponse()` method instead of `getResponse()`.
195-
196-
* The `Symfony\Component\BrowserKit\Client::getRequest()` method now
197-
**always** returns a `Symfony\Component\BrowserKit\Request` instance. To
198-
get the response from the code that handled the request, use the new
199-
`getOriginRequest()` method instead of `getRequest()`.
200-
201-
HttpKernel
202-
----------
203-
204-
* The `Symfony\Component\HttpKernel\Client::getResponse()` now returns a
205-
`Symfony\Component\BrowserKit\Response` instance instead of a
206-
`Symfony\Component\HttpFoundation\Response` one (because of a change in
207-
BrowserKit -- see above). You can still get the `HttpFoundation` response
208-
by using `getOriginResponse()` instead of `getResponse()`.
209-
210-
* The `Symfony\Component\HttpKernel\Client::getRequest()` now returns a
211-
`Symfony\Component\BrowserKit\Request` instance instead of a
212-
`Symfony\Component\HttpFoundation\Request` one (because of a change in
213-
BrowserKit -- see above). You can still get the `HttpFoundation` response
214-
by using `getOriginRequest()` instead of `getRequest()`.
191+
* The `Symfony\Component\BrowserKit\Client::getResponse()/getRequest()`
192+
methods now **always** return the request/response instance from the code
193+
that handles the request. To get the BrowserKit request/response instances,
194+
use the new `getInternalResponse()/getInternalRequest()` methods.

src/Symfony/Bundle/FrameworkBundle/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getProfile()
6969
return false;
7070
}
7171

72-
return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->originResponse);
72+
return $this->kernel->getContainer()->get('profiler')->loadProfileFromResponse($this->response);
7373
}
7474

7575
/**

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public function testStateAfterSubRequest()
2121
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => 'config.yml'));
2222
$client->request('GET', 'https://localhost/subrequest/en');
2323

24-
$this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getOriginResponse()->getContent());
24+
$this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent());
2525
}
2626
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
1919
$client->insulate();
2020

2121
$client->request('GET', '/secure-but-not-covered-by-access-control');
22-
$this->assertRedirect($client->getOriginResponse(), '/login');
22+
$this->assertRedirect($client->getResponse(), '/login');
2323
}
2424
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testFormLoginAndLogoutWithCsrfTokens($config)
2929
$form['user_login[password]'] = 'test';
3030
$client->submit($form);
3131

32-
$this->assertRedirect($client->getOriginResponse(), '/profile');
32+
$this->assertRedirect($client->getResponse(), '/profile');
3333

3434
$crawler = $client->followRedirect();
3535

@@ -44,7 +44,7 @@ public function testFormLoginAndLogoutWithCsrfTokens($config)
4444

4545
$client->click($logoutLinks[0]);
4646

47-
$this->assertRedirect($client->getOriginResponse(), '/');
47+
$this->assertRedirect($client->getResponse(), '/');
4848
}
4949

5050
/**
@@ -59,7 +59,7 @@ public function testFormLoginWithInvalidCsrfToken($config)
5959
$form['user_login[_token]'] = '';
6060
$client->submit($form);
6161

62-
$this->assertRedirect($client->getOriginResponse(), '/login');
62+
$this->assertRedirect($client->getResponse(), '/login');
6363

6464
$text = $client->followRedirect()->text();
6565
$this->assertContains('Invalid CSRF token.', $text);
@@ -79,7 +79,7 @@ public function testFormLoginWithCustomTargetPath($config)
7979
$form['user_login[_target_path]'] = '/foo';
8080
$client->submit($form);
8181

82-
$this->assertRedirect($client->getOriginResponse(), '/foo');
82+
$this->assertRedirect($client->getResponse(), '/foo');
8383

8484
$text = $client->followRedirect()->text();
8585
$this->assertContains('Hello johannes!', $text);
@@ -95,13 +95,13 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
9595
$client->insulate();
9696

9797
$client->request('GET', '/protected-resource');
98-
$this->assertRedirect($client->getOriginResponse(), '/login');
98+
$this->assertRedirect($client->getResponse(), '/login');
9999

100100
$form = $client->followRedirect()->selectButton('login')->form();
101101
$form['user_login[username]'] = 'johannes';
102102
$form['user_login[password]'] = 'test';
103103
$client->submit($form);
104-
$this->assertRedirect($client->getOriginResponse(), '/protected-resource');
104+
$this->assertRedirect($client->getResponse(), '/protected-resource');
105105

106106
$text = $client->followRedirect()->text();
107107
$this->assertContains('Hello johannes!', $text);

src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testFormLogin($config)
2929
$form['_password'] = 'test';
3030
$client->submit($form);
3131

32-
$this->assertRedirect($client->getOriginResponse(), '/profile');
32+
$this->assertRedirect($client->getResponse(), '/profile');
3333

3434
$text = $client->followRedirect()->text();
3535
$this->assertContains('Hello johannes!', $text);
@@ -50,7 +50,7 @@ public function testFormLoginWithCustomTargetPath($config)
5050
$form['_target_path'] = '/foo';
5151
$client->submit($form);
5252

53-
$this->assertRedirect($client->getOriginResponse(), '/foo');
53+
$this->assertRedirect($client->getResponse(), '/foo');
5454

5555
$text = $client->followRedirect()->text();
5656
$this->assertContains('Hello johannes!', $text);
@@ -66,13 +66,13 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
6666
$client->insulate();
6767

6868
$client->request('GET', '/protected_resource');
69-
$this->assertRedirect($client->getOriginResponse(), '/login');
69+
$this->assertRedirect($client->getResponse(), '/login');
7070

7171
$form = $client->followRedirect()->selectButton('login')->form();
7272
$form['_username'] = 'johannes';
7373
$form['_password'] = 'test';
7474
$client->submit($form);
75-
$this->assertRedirect($client->getOriginResponse(), '/protected_resource');
75+
$this->assertRedirect($client->getResponse(), '/protected_resource');
7676

7777
$text = $client->followRedirect()->text();
7878
$this->assertContains('Hello johannes!', $text);

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public function testLoginLogoutProcedure($locale)
2727
$form['_password'] = 'test';
2828
$client->submit($form);
2929

30-
$this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/profile');
30+
$this->assertRedirect($client->getResponse(), '/'.$locale.'/profile');
3131
$this->assertEquals('Profile', $client->followRedirect()->text());
3232

3333
$client->request('GET', '/'.$locale.'/logout');
34-
$this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/');
34+
$this->assertRedirect($client->getResponse(), '/'.$locale.'/');
3535
$this->assertEquals('Homepage', $client->followRedirect()->text());
3636
}
3737

@@ -49,7 +49,7 @@ public function testLoginFailureWithLocalizedFailurePath($locale)
4949
$form['_password'] = 'foobar';
5050
$client->submit($form);
5151

52-
$this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login');
52+
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
5353
}
5454

5555
/**
@@ -61,7 +61,7 @@ public function testAccessRestrictedResource($locale)
6161
$client->insulate();
6262

6363
$client->request('GET', '/'.$locale.'/secure/');
64-
$this->assertRedirect($client->getOriginResponse(), '/'.$locale.'/login');
64+
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
6565
}
6666

6767
/**
@@ -73,7 +73,7 @@ public function testAccessRestrictedResourceWithForward($locale)
7373
$client->insulate();
7474

7575
$crawler = $client->request('GET', '/'.$locale.'/secure/');
76-
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getOriginResponse());
76+
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
7777
}
7878

7979
public function getLocales()

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
2222
$client->insulate();
2323
$client->request('GET', '/protected_resource');
2424

25-
$this->assertRedirect($client->getOriginResponse(), '/login');
25+
$this->assertRedirect($client->getResponse(), '/login');
2626
}
2727

2828
/**
@@ -38,7 +38,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
3838
$client->insulate();
3939
$client->request('GET', '/unprotected_resource');
4040

41-
$this->assertEquals(404, $client->getOriginResponse()->getStatusCode(), (string) $client->getOriginResponse());
41+
$this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse());
4242
}
4343

4444
/**
@@ -60,7 +60,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWith
6060

6161
$client->request('GET', '/highly_protected_resource');
6262

63-
$this->assertNotEquals(404, $client->getOriginResponse()->getStatusCode());
63+
$this->assertNotEquals(404, $client->getResponse()->getStatusCode());
6464
}
6565

6666
/**
@@ -93,12 +93,12 @@ public function testSecurityConfigurationForMultipleIPAddresses($config)
9393

9494
private function assertAllowed($client, $path) {
9595
$client->request('GET', $path);
96-
$this->assertEquals(404, $client->getOriginResponse()->getStatusCode());
96+
$this->assertEquals(404, $client->getResponse()->getStatusCode());
9797
}
9898

9999
private function assertRestricted($client, $path) {
100100
$client->request('GET', $path);
101-
$this->assertEquals(302, $client->getOriginResponse()->getStatusCode());
101+
$this->assertEquals(302, $client->getResponse()->getStatusCode());
102102
}
103103

104104
public function getConfigs()

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testSwitchUser($originalUser, $targetUser, $expectedUser, $expec
2525

2626
$client->request('GET', '/profile?_switch_user='.$targetUser);
2727

28-
$this->assertEquals($expectedStatus, $client->getOriginResponse()->getStatusCode());
28+
$this->assertEquals($expectedStatus, $client->getResponse()->getStatusCode());
2929
$this->assertEquals($expectedUser, $client->getProfile()->getCollector('security')->getUser());
3030
}
3131

@@ -36,7 +36,7 @@ public function testSwitchedUserCannotSwitchToOther()
3636
$client->request('GET', '/profile?_switch_user=user_cannot_switch_1');
3737
$client->request('GET', '/profile?_switch_user=user_cannot_switch_2');
3838

39-
$this->assertEquals(500, $client->getOriginResponse()->getStatusCode());
39+
$this->assertEquals(500, $client->getResponse()->getStatusCode());
4040
$this->assertEquals('user_cannot_switch_1', $client->getProfile()->getCollector('security')->getUser());
4141
}
4242

@@ -47,7 +47,7 @@ public function testSwitchedUserExit()
4747
$client->request('GET', '/profile?_switch_user=user_cannot_switch_1');
4848
$client->request('GET', '/profile?_switch_user=_exit');
4949

50-
$this->assertEquals(200, $client->getOriginResponse()->getStatusCode());
50+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
5151
$this->assertEquals('user_can_switch', $client->getProfile()->getCollector('security')->getUser());
5252
}
5353

src/Symfony/Component/BrowserKit/CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ CHANGELOG
44
2.3.0
55
-----
66

7-
* added `Client::getOriginRequest()` and `Client::getOriginResponse()` to
8-
have access to the origin request and response objects
7+
* added `Client::getInternalRequest()` and `Client::getInternalResponse()` to
8+
have access to the BrowserKit internal request and response objects
99
* [BC BREAK] The `Symfony\Component\HttpKernel\Client::getRequest()` method now
10-
returns a `Symfony\Component\BrowserKit\Request` instance
10+
returns the request instance created by the client
1111
* [BC BREAK] The `Symfony\Component\HttpKernel\Client::request()` method now
12-
always returns a `Symfony\Component\BrowserKit\Response` instance
12+
always returns the response instance created by the client
1313

1414
2.1.0
1515
-----

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ abstract class Client
3333
protected $history;
3434
protected $cookieJar;
3535
protected $server;
36-
protected $originRequest;
36+
protected $internalRequest;
3737
protected $request;
38-
protected $originResponse;
38+
protected $internalResponse;
3939
protected $response;
4040
protected $crawler;
4141
protected $insulated;
@@ -174,9 +174,9 @@ public function getCrawler()
174174
*
175175
* @api
176176
*/
177-
public function getResponse()
177+
public function getInternalResponse()
178178
{
179-
return $this->response;
179+
return $this->internalResponse;
180180
}
181181

182182
/**
@@ -186,10 +186,12 @@ public function getResponse()
186186
* by the code that handles requests.
187187
*
188188
* @return object A response instance
189+
*
190+
* @api
189191
*/
190-
public function getOriginResponse()
192+
public function getResponse()
191193
{
192-
return $this->originResponse;
194+
return $this->response;
193195
}
194196

195197
/**
@@ -199,9 +201,9 @@ public function getOriginResponse()
199201
*
200202
* @api
201203
*/
202-
public function getRequest()
204+
public function getInternalRequest()
203205
{
204-
return $this->request;
206+
return $this->internalRequest;
205207
}
206208

207209
/**
@@ -210,11 +212,13 @@ public function getRequest()
210212
* The origin request is the request instance that is sent
211213
* to the code that handles requests.
212214
*
215+
* @api
216+
*
213217
* @return object A Request instance
214218
*/
215-
public function getOriginRequest()
219+
public function getRequest()
216220
{
217-
return $this->originRequest;
221+
return $this->request;
218222
}
219223

220224
/**
@@ -278,31 +282,31 @@ public function request($method, $uri, array $parameters = array(), array $files
278282
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
279283
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
280284

281-
$this->request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
285+
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
282286

283-
$this->originRequest = $this->filterRequest($this->request);
287+
$this->request = $this->filterRequest($this->internalRequest);
284288

285289
if (true === $changeHistory) {
286-
$this->history->add($this->request);
290+
$this->history->add($this->internalRequest);
287291
}
288292

289293
if ($this->insulated) {
290-
$this->originResponse = $this->doRequestInProcess($this->originRequest);
294+
$this->response = $this->doRequestInProcess($this->request);
291295
} else {
292-
$this->originResponse = $this->doRequest($this->originRequest);
296+
$this->response = $this->doRequest($this->request);
293297
}
294298

295-
$this->response = $this->filterResponse($this->originResponse);
299+
$this->internalResponse = $this->filterResponse($this->response);
296300

297-
$this->cookieJar->updateFromResponse($this->response, $uri);
301+
$this->cookieJar->updateFromResponse($this->internalResponse, $uri);
298302

299-
$this->redirect = $this->response->getHeader('Location');
303+
$this->redirect = $this->internalResponse->getHeader('Location');
300304

301305
if ($this->followRedirects && $this->redirect) {
302306
return $this->crawler = $this->followRedirect();
303307
}
304308

305-
return $this->crawler = $this->createCrawlerFromContent($this->request->getUri(), $this->response->getContent(), $this->response->getHeader('Content-Type'));
309+
return $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type'));
306310
}
307311

308312
/**

0 commit comments

Comments
 (0)