Skip to content

Commit

Permalink
feature #29881 [BrowserKit] Various changes to the Response class (fa…
Browse files Browse the repository at this point in the history
…bpot)

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()
  • Loading branch information
fabpot committed Jan 14, 2019
2 parents 33dbf1a + 9045a4e commit cdbf40b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
7 changes: 7 additions & 0 deletions 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
------

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-5.0.md
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
@@ -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
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
Expand Up @@ -13,11 +13,16 @@

/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.3
*/
class Response
{
/** @internal */
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
{
return $this->status;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Tests/ClientTest.php
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
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

0 comments on commit cdbf40b

Please sign in to comment.