Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BrowserKit] Various changes to the Response class #29881

Merged
merged 3 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE-4.3.md
Original file line number Diff line number Diff line change
@@ -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
------

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/BrowserKit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

4.3.0
-----

* Marked `Response` final.
* Deprecated `Response::buildHeader()`
* Deprecated `Response::getStatus()`, use `Response::getStatusCode()` instead

4.2.0
-----

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public function request(string $method, string $uri, array $parameters = array()

$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');
Expand Down Expand Up @@ -599,7 +599,7 @@ public function followRedirect()

$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;
Expand Down
22 changes: 20 additions & 2 deletions src/Symfony/Component/BrowserKit/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@

/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
*/
class Response
{
/** @internal */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@final is enough, just to be extra clear.

protected $content;
/** @internal */
protected $status;
/** @internal */
protected $headers;

/**
Expand Down Expand Up @@ -45,10 +50,10 @@ public function __toString()
$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);
}
}
}
Expand All @@ -63,9 +68,13 @@ public function __toString()
* @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);
}

Expand All @@ -83,8 +92,17 @@ public function getContent()
* 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent with the method name used by HttpFoundation

{
return $this->status;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function doRequest($request)
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;
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ public function testGetUri()
$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'));
Expand Down