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 -------9045a4e580
[BrowserKit] marked Response as @final0abff982e0
[BrowserKit] deprecated Response::buildHeader()e8e52355d4
[BrowserKit] deprecated Response::getStatus() in favor of Response::getStatusCode()
This commit is contained in:
commit
cdbf40bd9f
@ -1,6 +1,13 @@
|
|||||||
UPGRADE FROM 4.2 to 4.3
|
UPGRADE FROM 4.2 to 4.3
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
BrowserKit
|
||||||
|
----------
|
||||||
|
|
||||||
|
* Marked `Response` final.
|
||||||
|
* Deprecated `Response::buildHeader()`
|
||||||
|
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead
|
||||||
|
|
||||||
Config
|
Config
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ UPGRADE FROM 4.x to 5.0
|
|||||||
BrowserKit
|
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.
|
* The `Client::submit()` method has a new `$serverParameters` argument.
|
||||||
|
|
||||||
Cache
|
Cache
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
4.3.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Marked `Response` final.
|
||||||
|
* Deprecated `Response::buildHeader()`
|
||||||
|
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead
|
||||||
|
|
||||||
4.2.0
|
4.2.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ abstract class Client
|
|||||||
|
|
||||||
$this->cookieJar->updateFromResponse($this->internalResponse, $uri);
|
$this->cookieJar->updateFromResponse($this->internalResponse, $uri);
|
||||||
|
|
||||||
$status = $this->internalResponse->getStatus();
|
$status = $this->internalResponse->getStatusCode();
|
||||||
|
|
||||||
if ($status >= 300 && $status < 400) {
|
if ($status >= 300 && $status < 400) {
|
||||||
$this->redirect = $this->internalResponse->getHeader('Location');
|
$this->redirect = $this->internalResponse->getHeader('Location');
|
||||||
@ -599,7 +599,7 @@ abstract class Client
|
|||||||
|
|
||||||
$request = $this->internalRequest;
|
$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';
|
$method = 'GET';
|
||||||
$files = array();
|
$files = array();
|
||||||
$content = null;
|
$content = null;
|
||||||
|
@ -13,11 +13,16 @@ namespace Symfony\Component\BrowserKit;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* @final since Symfony 4.3
|
||||||
*/
|
*/
|
||||||
class Response
|
class Response
|
||||||
{
|
{
|
||||||
|
/** @internal */
|
||||||
protected $content;
|
protected $content;
|
||||||
|
/** @internal */
|
||||||
protected $status;
|
protected $status;
|
||||||
|
/** @internal */
|
||||||
protected $headers;
|
protected $headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,10 +50,10 @@ class Response
|
|||||||
$headers = '';
|
$headers = '';
|
||||||
foreach ($this->headers as $name => $value) {
|
foreach ($this->headers as $name => $value) {
|
||||||
if (\is_string($value)) {
|
if (\is_string($value)) {
|
||||||
$headers .= $this->buildHeader($name, $value);
|
$headers .= sprintf("%s: %s\n", $name, $value);
|
||||||
} else {
|
} else {
|
||||||
foreach ($value as $headerValue) {
|
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
|
* @param string $value The header value
|
||||||
*
|
*
|
||||||
* @return string The built header line
|
* @return string The built header line
|
||||||
|
*
|
||||||
|
* @deprecated since Symfony 4.3
|
||||||
*/
|
*/
|
||||||
protected function buildHeader($name, $value)
|
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);
|
return sprintf("%s: %s\n", $name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +92,17 @@ class Response
|
|||||||
* Gets the response status code.
|
* Gets the response status code.
|
||||||
*
|
*
|
||||||
* @return int The response status code
|
* @return int The response status code
|
||||||
|
*
|
||||||
|
* @deprecated since Symfony 4.3, use getStatusCode() instead
|
||||||
*/
|
*/
|
||||||
public function getStatus()
|
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;
|
return $this->status;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class TestClient extends Client
|
|||||||
protected function filterResponse($response)
|
protected function filterResponse($response)
|
||||||
{
|
{
|
||||||
if ($response instanceof SpecialResponse) {
|
if ($response instanceof SpecialResponse) {
|
||||||
return new Response($response->getContent(), $response->getStatus(), $response->getHeaders());
|
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -22,12 +22,21 @@ class ResponseTest extends TestCase
|
|||||||
$this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
|
$this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
public function testGetStatus()
|
public function testGetStatus()
|
||||||
{
|
{
|
||||||
$response = new Response('foo', 304);
|
$response = new Response('foo', 304);
|
||||||
$this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
|
$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()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
$response = new Response('foo', 200, array('foo' => 'bar'));
|
$response = new Response('foo', 200, array('foo' => 'bar'));
|
||||||
|
Reference in New Issue
Block a user