8000 feature #29881 [BrowserKit] Various changes to the Response class (fa… · symfony/symfony@cdbf40b · GitHub
[go: up one dir, main page]

Skip to content

Commit cdbf40b

Browse files
committed
feature #29881 [BrowserKit] Various changes to the Response class (fabpot)
This PR was squashed before being merged into the 4.3-dev branch (closes #29881). Discussion ---------- [BrowserKit] Various changes to the Response class | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This is the first PR of a series when I'm trying to "modernize" BrowserKit. Commits ------- 9045a4e [BrowserKit] marked Response as @Final 0abff98 [BrowserKit] deprecated Response::buildHeader() e8e5235 [BrowserKit] deprecated Response::getStatus() in favor of Response::getStatusCode()
2 parents 33dbf1a + 9045a4e commit cdbf40b

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
lines changed

UPGRADE-4.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
UPGRADE FROM 4.2 to 4.3
22
=======================
33

4+
BrowserKit
5+
----------
6+
7+
* Marked `Response` final.
8+
* Deprecated `Response::buildHeader()`
9+
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead
10+
411
Config
512
------
613

UPGRADE-5.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ UPGRADE FROM 4.x to 5.0
44
BrowserKit
55
----------
66

7+
* Removed the possibility to extend `Response` by making it final.
8+
* Removed `Response::buildHeader()`
9+
* Removed `Response::getStatus()`, use `Response::getStatusCode()` instead
710
* The `Client::submit()` method has a new `$serverParameters` argument.
811

912
Cache

src/Symfony/Component/BrowserKit/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Marked `Response` final.
8+
* Deprecated `Response::buildHeader()`
9+
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead
10+
411
4.2.0
512
-----
613

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public function request(string $method, string $uri, array $parameters = array()
409409

410410
$this->cookieJar->updateFromResponse($this->internalResponse, $uri);
411411

412-
$status = $this->internalResponse->getStatus();
412+
$status = $this->internalResponse->getStatusCode();
413413

414414
if ($status >= 300 && $status < 400) {
415415
$this->redirect = $this->internalResponse->getHeader('Location');
@@ -599,7 +599,7 @@ public function followRedirect()
599599

600600
$request = $this->internalRequest;
601601

602-
if (\in_array($this->internalResponse->getStatus(), array(301, 302, 303))) {
602+
if (\in_array($this->internalResponse->getStatusCode(), array(301, 302, 303))) {
603603
$method = 'GET';
604604
$files = array();
605605
$content = null;

src/Symfony/Component/BrowserKit/Response.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313

1414
/**
1515
* @author Fabien Potencier <fabien@symfony.com>
16+
*
17+
* @final since Symfony 4.3
1618
*/
1719
class Response
1820
{
21+
/** @internal */
1922
protected $content;
23+
/** @internal */
2024
protected $status;
25+
/** @internal */
2126
protected $headers;
2227

2328
/**
@@ -45,10 +50,10 @@ public function __toString()
4550
$headers = '';
4651
foreach ($this->headers as $name => $value) {
4752
if (\is_string($value)) {
48-
$headers .= $this->buildHeader($name, $value);
53+
$headers .= sprintf("%s: %s\n", $name, $value);
4954
} else {
5055
foreach ($value as $headerValue) {
51-
$headers .= $this->buildHeader($name, $headerValue);
56+
$headers .= sprintf("%s: %s\n", $name, $headerValue);
5257
}
5358
}
5459
}
@@ -63,9 +68,13 @@ public function __toString()
6368
* @param string $value The header value
6469
*
6570
* @return string The built header line
71+
*
72+
* @deprecated since Symfony 4.3
6673
*/
6774
protected function buildHeader($name, $value)
6875
{
76+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
77+
6978
return sprintf("%s: %s\n", $name, $value);
7079
}
7180

@@ -83,8 +92,17 @@ public function getContent()
8392
* Gets the response status code.
8493
*
8594
* @return int The response status code
95+
*
96+
* @deprecated since Symfony 4.3, use getStatusCode() instead
8697
*/
8798
public function getStatus()
99+
{
100+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3, use getStatusCode() instead.', __METHOD__), E_USER_DEPRECATED);
101+
102+
return $this->status;
103+
}
104+
105+
public function getStatusCode(): int
88106
{
89107
return $this->status;
90108
}

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function doRequest($request)
5252
protected function filterResponse($response)
5353
{
5454
if ($response instanceof SpecialResponse) {
55-
return new Response($response->getContent(), $response->getStatus(), $response->getHeaders());
55+
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
5656
}
5757

5858
return $response;

src/Symfony/Component/BrowserKit/Tests/ResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@ public function testGetUri()
2222
$this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
2323
}
2424

25+
/**
26+
* @group legacy
27+
*/
2528
public function testGetStatus()
2629
{
2730
$response = new Response('foo', 304);
2831
$this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
2932
}
3033

34+
public function testGetStatusCode()
35+
{
36+
$response = new Response('foo', 304);
37+
$this->assertEquals('304', $response->getStatusCode(), '->getStatusCode() returns the status of the response');
38+
}
39+
3140
public function testGetHeaders()
3241
{
3342
$response = new Response('foo', 200, array('foo' => 'bar'));

0 commit comments

Comments
 (0)
0