diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index d6a7f00203..4eb383d467 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -1,6 +1,13 @@ UPGRADE FROM 4.2 to 4.3 ======================= +BrowserKit +---------- + + * Marked `Response` final. + * Deprecated `Response::buildHeader()` + * Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead + Config ------ diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index cf677c478a..f446a7c15a 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -4,6 +4,9 @@ UPGRADE FROM 4.x to 5.0 BrowserKit ---------- + * Removed the possibility to extend `Response` by making it final. + * Removed `Response::buildHeader()` + * Removed `Response::getStatus()`, use `Response::getStatusCode()` instead * The `Client::submit()` method has a new `$serverParameters` argument. Cache diff --git a/src/Symfony/Component/BrowserKit/CHANGELOG.md b/src/Symfony/Component/BrowserKit/CHANGELOG.md index 51d8fbf48c..5ff92bb024 100644 --- a/src/Symfony/Component/BrowserKit/CHANGELOG.md +++ b/src/Symfony/Component/BrowserKit/CHANGELOG.md @@ -1,6 +1,13 @@ CHANGELOG ========= +4.3.0 +----- + + * Marked `Response` final. + * Deprecated `Response::buildHeader()` + * Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead + 4.2.0 ----- diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index d483dbcb07..0d1382a5f0 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -409,7 +409,7 @@ abstract class Client $this->cookieJar->updateFromResponse($this->internalResponse, $uri); - $status = $this->internalResponse->getStatus(); + $status = $this->internalResponse->getStatusCode(); if ($status >= 300 && $status < 400) { $this->redirect = $this->internalResponse->getHeader('Location'); @@ -599,7 +599,7 @@ abstract class Client $request = $this->internalRequest; - if (\in_array($this->internalResponse->getStatus(), array(301, 302, 303))) { + if (\in_array($this->internalResponse->getStatusCode(), array(301, 302, 303))) { $method = 'GET'; $files = array(); $content = null; diff --git a/src/Symfony/Component/BrowserKit/Response.php b/src/Symfony/Component/BrowserKit/Response.php index 6c50aeee43..845be10b68 100644 --- a/src/Symfony/Component/BrowserKit/Response.php +++ b/src/Symfony/Component/BrowserKit/Response.php @@ -13,11 +13,16 @@ namespace Symfony\Component\BrowserKit; /** * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class Response { + /** @internal */ protected $content; + /** @internal */ protected $status; + /** @internal */ protected $headers; /** @@ -45,10 +50,10 @@ class Response $headers = ''; foreach ($this->headers as $name => $value) { if (\is_string($value)) { - $headers .= $this->buildHeader($name, $value); + $headers .= sprintf("%s: %s\n", $name, $value); } else { foreach ($value as $headerValue) { - $headers .= $this->buildHeader($name, $headerValue); + $headers .= sprintf("%s: %s\n", $name, $headerValue); } } } @@ -63,9 +68,13 @@ class Response * @param string $value The header value * * @return string The built header line + * + * @deprecated since Symfony 4.3 */ protected function buildHeader($name, $value) { + @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED); + return sprintf("%s: %s\n", $name, $value); } @@ -83,8 +92,17 @@ class Response * Gets the response status code. * * @return int The response status code + * + * @deprecated since Symfony 4.3, use getStatusCode() instead */ public function getStatus() + { + @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3, use getStatusCode() instead.', __METHOD__), E_USER_DEPRECATED); + + return $this->status; + } + + public function getStatusCode(): int { return $this->status; } diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 1a34c623bc..e4cec8b393 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -52,7 +52,7 @@ class TestClient extends Client protected function filterResponse($response) { if ($response instanceof SpecialResponse) { - return new Response($response->getContent(), $response->getStatus(), $response->getHeaders()); + return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders()); } return $response; diff --git a/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php b/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php index 0ba4e3b3a7..8afebe454c 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php @@ -22,12 +22,21 @@ class ResponseTest extends TestCase $this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response'); } + /** + * @group legacy + */ public function testGetStatus() { $response = new Response('foo', 304); $this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response'); } + public function testGetStatusCode() + { + $response = new Response('foo', 304); + $this->assertEquals('304', $response->getStatusCode(), '->getStatusCode() returns the status of the response'); + } + public function testGetHeaders() { $response = new Response('foo', 200, array('foo' => 'bar'));