From ac1103f80b2cd64b707401936c3cf12961d882c9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 9 May 2019 09:23:25 +0200 Subject: [PATCH 001/127] updated version to 4.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f30975114..bf73d393c 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "4.4-dev" } } } From 000820ae107d2f8c9cc54d4171a5658c5a974c43 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 28 May 2019 17:41:12 +0200 Subject: [PATCH 002/127] Allow Symfony 5.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bf73d393c..efc4b9425 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ ], "require": { "php": "^7.1.3", - "symfony/mime": "^4.3", + "symfony/mime": "^4.3|^5.0", "symfony/polyfill-mbstring": "~1.1" }, "require-dev": { "predis/predis": "~1.0", - "symfony/expression-language": "~3.4|~4.0" + "symfony/expression-language": "^3.4|^4.0|^5.0" }, "autoload": { "psr-4": { "Symfony\\Component\\HttpFoundation\\": "" }, From 01d599bc5b401d0dfafb2e0829a4338826219144 Mon Sep 17 00:00:00 2001 From: dFayet Date: Tue, 28 May 2019 18:10:09 +0200 Subject: [PATCH 003/127] [HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe() --- BinaryFileResponse.php | 2 +- CHANGELOG.md | 5 +++++ Request.php | 9 +++------ Tests/RequestTest.php | 12 +----------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index e21782095..443c02888 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -204,7 +204,7 @@ public function prepare(Request $request) if (!$this->headers->has('Accept-Ranges')) { // Only accept ranges on safe HTTP methods - $this->headers->set('Accept-Ranges', $request->isMethodSafe(false) ? 'bytes' : 'none'); + $this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none'); } if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) { diff --git a/CHANGELOG.md b/CHANGELOG.md index 54acd6ae1..7ecbdffa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.4.0 +----- + + * passing arguments to `Request::isMethodSafe()` is deprecated. + 4.3.0 ----- diff --git a/Request.php b/Request.php index fffe2ab81..83cdf6016 100644 --- a/Request.php +++ b/Request.php @@ -1437,15 +1437,12 @@ public function isMethod($method) * * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 * - * @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default. - * * @return bool */ - public function isMethodSafe(/* $andCacheable = true */) + public function isMethodSafe() { - if (!\func_num_args() || func_get_arg(0)) { - // setting $andCacheable to false should be deprecated in 4.1 - throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.'); + if (\func_num_args() > 0) { + @trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable() to check if the method is cacheable instead."', __METHOD__, __CLASS__), E_USER_DEPRECATED); } return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index ab0dcf681..c1168f5e4 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2115,7 +2115,7 @@ public function testMethodSafe($method, $safe) { $request = new Request(); $request->setMethod($method); - $this->assertEquals($safe, $request->isMethodSafe(false)); + $this->assertEquals($safe, $request->isMethodSafe()); } public function methodSafeProvider() @@ -2134,16 +2134,6 @@ public function methodSafeProvider() ]; } - /** - * @expectedException \BadMethodCallException - */ - public function testMethodSafeChecksCacheable() - { - $request = new Request(); - $request->setMethod('OPTIONS'); - $request->isMethodSafe(); - } - /** * @dataProvider methodCacheableProvider */ From daa0601bef971bdca35b8b33d01db7720bee77d8 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 17 Jun 2019 00:17:09 +0100 Subject: [PATCH 004/127] Fine tune constructor types --- RedirectResponse.php | 4 ++-- Tests/RedirectResponseTest.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/RedirectResponse.php b/RedirectResponse.php index 8d04aa42c..c6b559beb 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -32,7 +32,7 @@ class RedirectResponse extends Response * * @see http://tools.ietf.org/html/rfc2616#section-10.3 */ - public function __construct(?string $url, int $status = 302, array $headers = []) + public function __construct(string $url, int $status = 302, array $headers = []) { parent::__construct('', $status, $headers); @@ -82,7 +82,7 @@ public function getTargetUrl() */ public function setTargetUrl($url) { - if (empty($url)) { + if ('' == $url) { throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); } diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index 5f6a8ac08..24d703d52 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -28,10 +28,11 @@ public function testGenerateMetaRedirect() /** * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Cannot redirect to an empty URL. */ - public function testRedirectResponseConstructorNullUrl() + public function testRedirectResponseConstructorEmptyUrl() { - $response = new RedirectResponse(null); + $response = new RedirectResponse(''); } /** From 38c04ea9fccc0d3f75199e99c8a92ed3644c79c7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 17 Jun 2019 20:33:53 +0200 Subject: [PATCH 005/127] Add BC layer for updated constructor types --- RedirectResponse.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/RedirectResponse.php b/RedirectResponse.php index c6b559beb..1d4f37cae 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -32,8 +32,13 @@ class RedirectResponse extends Response * * @see http://tools.ietf.org/html/rfc2616#section-10.3 */ - public function __construct(string $url, int $status = 302, array $headers = []) + public function __construct(?string $url, int $status = 302, array $headers = []) { + if (null === $url) { + @trigger_error(sprintf('Passing a null url when instantiating a "%s" is deprecated since Symfony 4.4.', __CLASS__), E_USER_DEPRECATED); + $url = ''; + } + parent::__construct('', $status, $headers); $this->setTargetUrl($url); @@ -82,7 +87,7 @@ public function getTargetUrl() */ public function setTargetUrl($url) { - if ('' == $url) { + if ('' === ($url ?? '')) { throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); } From 25720602691b20baac68bad101b2361194fe1ab3 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Wed, 19 Jun 2019 12:46:55 +0100 Subject: [PATCH 006/127] Don't assume port 0 for X-Forwarded-Port --- Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.php b/Request.php index ea3f460c4..fc26304ad 100644 --- a/Request.php +++ b/Request.php @@ -1037,7 +1037,7 @@ public function getPort() $pos = strrpos($host, ':'); } - if (false !== $pos) { + if (false !== $pos && !empty(substr($host, $pos + 1))) { return (int) substr($host, $pos + 1); } From 75c9946dee51091ce3fa561f5c76da3aef16bb11 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Wed, 19 Jun 2019 17:03:11 +0100 Subject: [PATCH 007/127] Update Request.php --- Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Request.php b/Request.php index fc26304ad..38b7fc216 100644 --- a/Request.php +++ b/Request.php @@ -1037,8 +1037,8 @@ public function getPort() $pos = strrpos($host, ':'); } - if (false !== $pos && !empty(substr($host, $pos + 1))) { - return (int) substr($host, $pos + 1); + if (false !== $pos && '' !== $port = substr($host, $pos + 1)) { + return (int) $port; } return 'https' === $this->getScheme() ? 443 : 80; From 6005107cf296be17c4d342fb4dffcfcd410399b4 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Thu, 27 Jun 2019 13:35:22 +0300 Subject: [PATCH 008/127] [HttpFoundation] Throw exception when the \"session\" extension is not loaded --- Session/Storage/NativeSessionStorage.php | 4 ++++ Session/Storage/PhpBridgeSessionStorage.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index c4dbe7586..809d7002c 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -100,6 +100,10 @@ class NativeSessionStorage implements SessionStorageInterface */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) { + if (!\extension_loaded('session')) { + throw new \LogicException('PHP extension "session" is required.'); + } + $options += [ 'cache_limiter' => '', 'cache_expire' => 0, diff --git a/Session/Storage/PhpBridgeSessionStorage.php b/Session/Storage/PhpBridgeSessionStorage.php index 662ed5015..8969e609a 100644 --- a/Session/Storage/PhpBridgeSessionStorage.php +++ b/Session/Storage/PhpBridgeSessionStorage.php @@ -24,6 +24,10 @@ class PhpBridgeSessionStorage extends NativeSessionStorage */ public function __construct($handler = null, MetadataBag $metaBag = null) { + if (!\extension_loaded('session')) { + throw new \LogicException('PHP extension "session" is required.'); + } + $this->setMetadataBag($metaBag); $this->setSaveHandler($handler); } From 91b374c7e43da52615e8e59232c55c13352fb141 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sun, 30 Jun 2019 23:48:04 +0100 Subject: [PATCH 009/127] Add test case --- Tests/RequestTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index d266e1f68..650d8fca7 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2427,6 +2427,18 @@ public function testTrustedPort() $this->assertSame(443, $request->getPort()); } + + public function testTrustedPortDoesNotDefaultToZero() + { + Request::setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_ALL); + + $request = Request::create('/'); + $request->server->set('REMOTE_ADDR', '1.1.1.1'); + $request->headers->set('X-Forwarded-Host', 'test.example.com'); + $request->headers->set('X-Forwarded-Port', null); + + $this->assertSame(80, $request->getPort()); + } } class RequestContentProxy extends Request From 9b9980bab1e08b1518cbfe3530970254f2e36027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 28 Jun 2019 15:18:47 +0200 Subject: [PATCH 010/127] [HttpFoundation] Deprecated ApacheRequest --- ApacheRequest.php | 4 ++++ CHANGELOG.md | 1 + Tests/ApacheRequestTest.php | 1 + 3 files changed, 6 insertions(+) diff --git a/ApacheRequest.php b/ApacheRequest.php index 4e99186dc..f189cde58 100644 --- a/ApacheRequest.php +++ b/ApacheRequest.php @@ -11,9 +11,13 @@ namespace Symfony\Component\HttpFoundation; +@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ApacheRequest::class, Request::class), E_USER_DEPRECATED); + /** * Request represents an HTTP request from an Apache server. * + * @deprecated since Symfony 4.4. Use the Request class instead. + * * @author Fabien Potencier */ class ApacheRequest extends Request diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ecbdffa9..29e06e678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * passing arguments to `Request::isMethodSafe()` is deprecated. + * `ApacheRequest` is deprecated, use the `Request` class instead. 4.3.0 ----- diff --git a/Tests/ApacheRequestTest.php b/Tests/ApacheRequestTest.php index 6fa3b8891..7a5bd378a 100644 --- a/Tests/ApacheRequestTest.php +++ b/Tests/ApacheRequestTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\ApacheRequest; +/** @group legacy */ class ApacheRequestTest extends TestCase { /** From 703f5084a775c652eb806df0f6c973ae1e9b2c5c Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 2 Jul 2019 17:48:31 -0400 Subject: [PATCH 011/127] Improving the request/response format autodetection --- Request.php | 23 +++++++++++++++++++++++ Response.php | 2 +- Tests/RequestTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 83cdf6016..a950b0a15 100644 --- a/Request.php +++ b/Request.php @@ -192,6 +192,10 @@ class Request protected static $requestFactory; + /** + * @var string|null + */ + private $preferredFormat; private $isHostValid = true; private $isForwardedValid = true; @@ -1559,6 +1563,25 @@ public function isNoCache() return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma'); } + public function getPreferredFormat(?string $default = 'html'): ?string + { + if (null !== $this->preferredFormat) { + return $this->preferredFormat; + } + + $this->preferredFormat = $this->getRequestFormat($this->getContentType()); + + if (null === $this->preferredFormat) { + foreach ($this->getAcceptableContentTypes() as $contentType) { + if (null !== $this->preferredFormat = $this->getFormat($contentType)) { + break; + } + } + } + + return $this->preferredFormat ?: $default; + } + /** * Returns the preferred language. * diff --git a/Response.php b/Response.php index d1263ca7a..168155849 100644 --- a/Response.php +++ b/Response.php @@ -270,7 +270,7 @@ public function prepare(Request $request) } else { // Content-type based on the Request if (!$headers->has('Content-Type')) { - $format = $request->getRequestFormat(); + $format = $request->getPreferredFormat(); if (null !== $format && $mimeType = $request->getMimeType($format)) { $headers->set('Content-Type', $mimeType); } diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index c1168f5e4..6573da078 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -399,6 +399,32 @@ public function testDuplicateWithFormat() $this->assertEquals('xml', $dup->getRequestFormat()); } + public function testGetPreferredFormat() + { + $request = new Request(); + $this->assertNull($request->getPreferredFormat(null)); + $this->assertSame('html', $request->getPreferredFormat()); + $this->assertSame('json', $request->getPreferredFormat('json')); + + $request->setRequestFormat('atom'); + $request->headers->set('Content-Type', 'application/json'); + $request->headers->set('Accept', 'application/xml'); + $this->assertSame('atom', $request->getPreferredFormat()); + + $request = new Request(); + $request->headers->set('Content-Type', 'application/json'); + $request->headers->set('Accept', 'application/xml'); + $this->assertSame('json', $request->getPreferredFormat()); + + $request = new Request(); + $request->headers->set('Accept', 'application/xml'); + $this->assertSame('xml', $request->getPreferredFormat()); + + $request = new Request(); + $request->headers->set('Accept', 'application/json;q=0.8,application/xml;q=0.9'); + $this->assertSame('xml', $request->getPreferredFormat()); + } + /** * @dataProvider getFormatToMimeTypeMapProviderWithAdditionalNullFormat */ From 732978b1804fa00c86befd8d3808054969d154ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 3 Jul 2019 22:32:34 +0200 Subject: [PATCH 012/127] [HttpFoundation] Accept must take the lead for Request::getPreferredFormat() --- Request.php | 21 ++++++++++++++------- Tests/RequestTest.php | 8 ++++---- Tests/ResponseTest.php | 1 + 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Request.php b/Request.php index a950b0a15..4c5260520 100644 --- a/Request.php +++ b/Request.php @@ -1347,6 +1347,8 @@ public function setFormat($format, $mimeTypes) * * _format request attribute * * $default * + * @see getPreferredFormat + * * @param string|null $default The default format * * @return string|null The request format @@ -1563,22 +1565,27 @@ public function isNoCache() return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma'); } + /** + * Gets the preferred format for the response by inspecting, in the following order: + * * the request format set using setRequestFormat + * * the values of the Accept HTTP header + * * the content type of the body of the request. + */ public function getPreferredFormat(?string $default = 'html'): ?string { if (null !== $this->preferredFormat) { return $this->preferredFormat; } - $this->preferredFormat = $this->getRequestFormat($this->getContentType()); - - if (null === $this->preferredFormat) { - foreach ($this->getAcceptableContentTypes() as $contentType) { - if (null !== $this->preferredFormat = $this->getFormat($contentType)) { - break; - } + $preferredFormat = null; + foreach ($this->getAcceptableContentTypes() as $contentType) { + if ($preferredFormat = $this->getFormat($contentType)) { + break; } } + $this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType()); + return $this->preferredFormat ?: $default; } diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 6573da078..500d590f7 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -407,14 +407,14 @@ public function testGetPreferredFormat() $this->assertSame('json', $request->getPreferredFormat('json')); $request->setRequestFormat('atom'); - $request->headers->set('Content-Type', 'application/json'); - $request->headers->set('Accept', 'application/xml'); + $request->headers->set('Accept', 'application/ld+json'); + $request->headers->set('Content-Type', 'application/merge-patch+json'); $this->assertSame('atom', $request->getPreferredFormat()); $request = new Request(); - $request->headers->set('Content-Type', 'application/json'); $request->headers->set('Accept', 'application/xml'); - $this->assertSame('json', $request->getPreferredFormat()); + $request->headers->set('Content-Type', 'application/json'); + $this->assertSame('xml', $request->getPreferredFormat()); $request = new Request(); $request->headers->set('Accept', 'application/xml'); diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 7856a77c0..550d7ce0b 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -504,6 +504,7 @@ public function testPrepareSetContentType() $response = new Response('foo'); $request = Request::create('/'); $request->setRequestFormat('json'); + $request->headers->remove('accept'); $response->prepare($request); From e135ecf5443500a310d29ef3df722096d39f53de Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 4 Jul 2019 22:58:06 +0200 Subject: [PATCH 013/127] PHP 5 compat --- Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 38b7fc216..7185d75e9 100644 --- a/Request.php +++ b/Request.php @@ -1037,7 +1037,7 @@ public function getPort() $pos = strrpos($host, ':'); } - if (false !== $pos && '' !== $port = substr($host, $pos + 1)) { + if (false !== $pos && $port = substr($host, $pos + 1)) { return (int) $port; } From 85e59da0c73e3c7e7a2fb92f55759571a85e408b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 5 Jul 2019 09:04:50 +0200 Subject: [PATCH 014/127] Fix CS regarding nullable arguments --- UrlHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UrlHelper.php b/UrlHelper.php index 3c06e9321..f114c0a9f 100644 --- a/UrlHelper.php +++ b/UrlHelper.php @@ -23,7 +23,7 @@ final class UrlHelper private $requestStack; private $requestContext; - public function __construct(RequestStack $requestStack, ?RequestContext $requestContext = null) + public function __construct(RequestStack $requestStack, RequestContext $requestContext = null) { $this->requestStack = $requestStack; $this->requestContext = $requestContext; From 8d530ef09f8303aba64a8400f41fff6ecf8dc924 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Jul 2019 13:57:06 +0200 Subject: [PATCH 015/127] fixed CS --- Tests/RequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 650d8fca7..73d12cb3f 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2435,7 +2435,7 @@ public function testTrustedPortDoesNotDefaultToZero() $request = Request::create('/'); $request->server->set('REMOTE_ADDR', '1.1.1.1'); $request->headers->set('X-Forwarded-Host', 'test.example.com'); - $request->headers->set('X-Forwarded-Port', null); + $request->headers->set('X-Forwarded-Port', ''); $this->assertSame(80, $request->getPort()); } From 61217e46f7fbc5cfbb22e15e50744c151e2675ad Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 19 Jul 2019 13:42:31 +0200 Subject: [PATCH 016/127] Remove dead tests fixtures --- Tests/ResponseTest.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index fe6bc027a..40200ee31 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -1001,14 +1001,3 @@ public function __toString() class DefaultResponse extends Response { } - -class ExtendedResponse extends Response -{ - public function setLastModified(\DateTime $date = null) - { - } - - public function getDate() - { - } -} From c450706851050ade2e1f30d012d50bb9173f7f3d Mon Sep 17 00:00:00 2001 From: Arman Hosseini <44655055+Arman-Hosseini@users.noreply.github.com> Date: Fri, 19 Jul 2019 23:09:57 +0430 Subject: [PATCH 017/127] [HttpFoundation] Fix URLs --- Session/Storage/Handler/MongoDbSessionHandler.php | 2 +- Session/Storage/Handler/NativeFileSessionHandler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index 3b5ccaa83..ddedacffb 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -17,7 +17,7 @@ * @author Markus Bachmann * * @see https://packagist.org/packages/mongodb/mongodb - * @see http://php.net/manual/en/set.mongodb.php + * @see https://php.net/mongodb */ class MongoDbSessionHandler extends AbstractSessionHandler { diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index 4e9704bd5..04bcbbfe3 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -23,7 +23,7 @@ class NativeFileSessionHandler extends NativeSessionHandler * Default null will leave setting as defined by PHP. * '/path', 'N;/path', or 'N;octal-mode;/path * - * @see http://php.net/session.configuration.php#ini.session.save-path for further details. + * @see https://php.net/manual/session.configuration.php#ini.session.save-path for further details. * * @throws \InvalidArgumentException On invalid $savePath * @throws \RuntimeException When failing to create the save directory From a72c8a528271cb2dd5e210e8cdaa0df55fdbd0da Mon Sep 17 00:00:00 2001 From: Gocha Ossinkine Date: Tue, 23 Jul 2019 19:02:38 +0500 Subject: [PATCH 018/127] [HttpFoundation] Revert getClientIp @return docblock --- Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 7185d75e9..0f7f46fff 100644 --- a/Request.php +++ b/Request.php @@ -912,7 +912,7 @@ public function getClientIps() * ("Client-Ip" for instance), configure it via the $trustedHeaderSet * argument of the Request::setTrustedProxies() method instead. * - * @return string|null The client IP address + * @return string The client IP address * * @see getClientIps() * @see http://en.wikipedia.org/wiki/X-Forwarded-For From a9a0140d87d8e3c5f3a19ee4f8f150350ebfa268 Mon Sep 17 00:00:00 2001 From: Benny Born Date: Sun, 28 Jul 2019 12:33:26 +0200 Subject: [PATCH 019/127] [HttpFoundation] Fix `getMaxFilesize` --- File/UploadedFile.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/File/UploadedFile.php b/File/UploadedFile.php index a44c664b4..093aaf832 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -214,13 +214,26 @@ public function move($directory, $name = null) */ public static function getMaxFilesize() { - $iniMax = strtolower(ini_get('upload_max_filesize')); + $sizePostMax = self::parseFilesize(ini_get('post_max_size')); + $sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize')); - if ('' === $iniMax) { - return PHP_INT_MAX; + return min([$sizePostMax, $sizeUploadMax]); + } + + /** + * Returns the given size from an ini value in bytes. + * + * @return int The given size in bytes + */ + private static function parseFilesize($size) + { + if ('' === $size) { + return 0; } - $max = ltrim($iniMax, '+'); + $size = strtolower($size); + + $max = ltrim($size, '+'); if (0 === strpos($max, '0x')) { $max = \intval($max, 16); } elseif (0 === strpos($max, '0')) { @@ -229,7 +242,7 @@ public static function getMaxFilesize() $max = (int) $max; } - switch (substr($iniMax, -1)) { + switch (substr($size, -1)) { case 't': $max *= 1024; // no break case 'g': $max *= 1024; From 25b5dd2a2da777de754695f0c30d2c6aa28070e4 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 27 Jul 2019 20:05:40 +0200 Subject: [PATCH 020/127] add parameter type declarations to private methods --- BinaryFileResponse.php | 2 +- Request.php | 4 ++-- Session/Storage/Handler/PdoSessionHandler.php | 20 ++++--------------- Session/Storage/MetadataBag.php | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 443c02888..79329e2e2 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -269,7 +269,7 @@ public function prepare(Request $request) return $this; } - private function hasValidIfRangeHeader($header) + private function hasValidIfRangeHeader(?string $header) { if ($this->getEtag() === $header) { return true; diff --git a/Request.php b/Request.php index 8da2d77de..3b0dbfbfd 100644 --- a/Request.php +++ b/Request.php @@ -1983,7 +1983,7 @@ public function isFromTrustedProxy() return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies); } - private function getTrustedValues($type, $ip = null) + private function getTrustedValues(int $type, string $ip = null) { $clientValues = []; $forwardedValues = []; @@ -2034,7 +2034,7 @@ private function getTrustedValues($type, $ip = null) throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::$trustedHeaders[self::HEADER_FORWARDED], self::$trustedHeaders[$type])); } - private function normalizeAndFilterClientIps(array $clientIps, $ip) + private function normalizeAndFilterClientIps(array $clientIps, string $ip) { if (!$clientIps) { return []; diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index a3877ef4c..f40d9ec60 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -423,10 +423,8 @@ public function close() /** * Lazy-connects to the database. - * - * @param string $dsn DSN string */ - private function connect($dsn) + private function connect(string $dsn) { $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); @@ -436,13 +434,11 @@ private function connect($dsn) /** * Builds a PDO DSN from a URL-like connection string. * - * @param string $dsnOrUrl - * * @return string * * @todo implement missing support for oci DSN (which look totally different from other PDO ones) */ - private function buildDsnFromUrl($dsnOrUrl) + private function buildDsnFromUrl(string $dsnOrUrl) { // (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid $url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $dsnOrUrl); @@ -775,13 +771,9 @@ private function getSelectSql(): string /** * Returns an insert statement supported by the database for writing session data. * - * @param string $sessionId Session ID - * @param string $sessionData Encoded session data - * @param int $maxlifetime session.gc_maxlifetime - * * @return \PDOStatement The insert statement */ - private function getInsertStatement($sessionId, $sessionData, $maxlifetime) + private function getInsertStatement(string $sessionId, string $sessionData, int $maxlifetime) { switch ($this->driver) { case 'oci': @@ -808,13 +800,9 @@ private function getInsertStatement($sessionId, $sessionData, $maxlifetime) /** * Returns an update statement supported by the database for writing session data. * - * @param string $sessionId Session ID - * @param string $sessionData Encoded session data - * @param int $maxlifetime session.gc_maxlifetime - * * @return \PDOStatement The update statement */ - private function getUpdateStatement($sessionId, $sessionData, $maxlifetime) + private function getUpdateStatement(string $sessionId, string $sessionData, int $maxlifetime) { switch ($this->driver) { case 'oci': diff --git a/Session/Storage/MetadataBag.php b/Session/Storage/MetadataBag.php index 2eff4109b..ece3ff34f 100644 --- a/Session/Storage/MetadataBag.php +++ b/Session/Storage/MetadataBag.php @@ -159,7 +159,7 @@ public function setName($name) $this->name = $name; } - private function stampCreated($lifetime = null) + private function stampCreated(int $lifetime = null) { $timeStamp = time(); $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp; From c7bad486caf88e15b55b244cdaebf8bf03d07f8f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 Jul 2019 21:19:25 +0200 Subject: [PATCH 021/127] Make tests support phpunit 8 --- Tests/BinaryFileResponseTest.php | 5 ++++- Tests/File/MimeType/MimeTypeTest.php | 5 ++++- Tests/File/UploadedFileTest.php | 5 ++++- Tests/FileBagTest.php | 7 +++++-- Tests/JsonResponseTest.php | 5 ++++- Tests/RequestTest.php | 5 ++++- Tests/ResponseFunctionalTest.php | 7 +++++-- Tests/Session/Attribute/AttributeBagTest.php | 7 +++++-- Tests/Session/Attribute/NamespacedAttributeBagTest.php | 7 +++++-- Tests/Session/Flash/AutoExpireFlashBagTest.php | 7 +++++-- Tests/Session/Flash/FlashBagTest.php | 7 +++++-- Tests/Session/SessionTest.php | 7 +++++-- .../Session/Storage/Handler/AbstractSessionHandlerTest.php | 7 +++++-- .../Session/Storage/Handler/MemcacheSessionHandlerTest.php | 7 +++++-- .../Storage/Handler/MemcachedSessionHandlerTest.php | 7 +++++-- .../Session/Storage/Handler/MongoDbSessionHandlerTest.php | 5 ++++- Tests/Session/Storage/Handler/PdoSessionHandlerTest.php | 5 ++++- Tests/Session/Storage/MetadataBagTest.php | 7 +++++-- Tests/Session/Storage/MockArraySessionStorageTest.php | 7 +++++-- Tests/Session/Storage/MockFileSessionStorageTest.php | 7 +++++-- Tests/Session/Storage/NativeSessionStorageTest.php | 7 +++++-- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 7 +++++-- Tests/Session/Storage/Proxy/AbstractProxyTest.php | 7 +++++-- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 7 +++++-- 24 files changed, 113 insertions(+), 41 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 853b4bb3d..74d3e8162 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpFoundation\Tests; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Stream; use Symfony\Component\HttpFoundation\Request; @@ -19,6 +20,8 @@ class BinaryFileResponseTest extends ResponseTestCase { + use ForwardCompatTestTrait; + public function testConstruction() { $file = __DIR__.'/../README.md'; @@ -356,7 +359,7 @@ protected function provideResponse() return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']); } - public static function tearDownAfterClass() + private static function doTearDownAfterClass() { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index bb88807ab..9f3c87c98 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\File\MimeType; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; @@ -20,6 +21,8 @@ */ class MimeTypeTest extends TestCase { + use ForwardCompatTestTrait; + protected $path; public function testGuessImageWithoutExtension() @@ -79,7 +82,7 @@ public function testGuessWithNonReadablePath() } } - public static function tearDownAfterClass() + private static function doTearDownAfterClass() { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 5a37cda35..f886ebcd1 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\HttpFoundation\Tests\File; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\UploadedFile; class UploadedFileTest extends TestCase { - protected function setUp() + use ForwardCompatTestTrait; + + private function doSetUp() { if (!ini_get('file_uploads')) { $this->markTestSkipped('file_uploads is disabled in php.ini'); diff --git a/Tests/FileBagTest.php b/Tests/FileBagTest.php index 0b6d66042..3ef868eaf 100644 --- a/Tests/FileBagTest.php +++ b/Tests/FileBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\FileBag; @@ -23,6 +24,8 @@ */ class FileBagTest extends TestCase { + use ForwardCompatTestTrait; + /** * @expectedException \InvalidArgumentException */ @@ -159,12 +162,12 @@ protected function createTempFile() return tempnam(sys_get_temp_dir().'/form_test', 'FormTest'); } - protected function setUp() + private function doSetUp() { mkdir(sys_get_temp_dir().'/form_test', 0777, true); } - protected function tearDown() + private function doTearDown() { foreach (glob(sys_get_temp_dir().'/form_test/*') as $file) { unlink($file); diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index ef0346cbe..56a40420a 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\JsonResponse; class JsonResponseTest extends TestCase { - protected function setUp() + use ForwardCompatTestTrait; + + private function doSetUp() { parent::setUp(); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 73d12cb3f..219a16256 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Session; @@ -19,7 +20,9 @@ class RequestTest extends TestCase { - protected function tearDown() + use ForwardCompatTestTrait; + + private function doTearDown() { Request::setTrustedProxies([], -1); Request::setTrustedHosts([]); diff --git a/Tests/ResponseFunctionalTest.php b/Tests/ResponseFunctionalTest.php index 3d3e696c7..e264710d1 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -12,15 +12,18 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @requires PHP 7.0 */ class ResponseFunctionalTest extends TestCase { + use ForwardCompatTestTrait; + private static $server; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -32,7 +35,7 @@ public static function setUpBeforeClass() sleep(1); } - public static function tearDownAfterClass() + private static function doTearDownAfterClass() { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/Session/Attribute/AttributeBagTest.php b/Tests/Session/Attribute/AttributeBagTest.php index 3f2f7b3c8..aef66da1d 100644 --- a/Tests/Session/Attribute/AttributeBagTest.php +++ b/Tests/Session/Attribute/AttributeBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; /** @@ -21,6 +22,8 @@ */ class AttributeBagTest extends TestCase { + use ForwardCompatTestTrait; + private $array = []; /** @@ -28,7 +31,7 @@ class AttributeBagTest extends TestCase */ private $bag; - protected function setUp() + private function doSetUp() { $this->array = [ 'hello' => 'world', @@ -49,7 +52,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + private function doTearDown() { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Attribute/NamespacedAttributeBagTest.php b/Tests/Session/Attribute/NamespacedAttributeBagTest.php index 6b4bb17d6..a1f6bf5eb 100644 --- a/Tests/Session/Attribute/NamespacedAttributeBagTest.php +++ b/Tests/Session/Attribute/NamespacedAttributeBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag; /** @@ -21,6 +22,8 @@ */ class NamespacedAttributeBagTest extends TestCase { + use ForwardCompatTestTrait; + private $array = []; /** @@ -28,7 +31,7 @@ class NamespacedAttributeBagTest extends TestCase */ private $bag; - protected function setUp() + private function doSetUp() { $this->array = [ 'hello' => 'world', @@ -49,7 +52,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + private function doTearDown() { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Flash/AutoExpireFlashBagTest.php b/Tests/Session/Flash/AutoExpireFlashBagTest.php index b4e2c3a5a..65b205814 100644 --- a/Tests/Session/Flash/AutoExpireFlashBagTest.php +++ b/Tests/Session/Flash/AutoExpireFlashBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Flash; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag; /** @@ -21,6 +22,8 @@ */ class AutoExpireFlashBagTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag */ @@ -28,7 +31,7 @@ class AutoExpireFlashBagTest extends TestCase protected $array = []; - protected function setUp() + private function doSetUp() { parent::setUp(); $this->bag = new FlashBag(); @@ -36,7 +39,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + private function doTearDown() { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/Flash/FlashBagTest.php b/Tests/Session/Flash/FlashBagTest.php index 6d8619e07..427af6d67 100644 --- a/Tests/Session/Flash/FlashBagTest.php +++ b/Tests/Session/Flash/FlashBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Flash; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; /** @@ -21,6 +22,8 @@ */ class FlashBagTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface */ @@ -28,7 +31,7 @@ class FlashBagTest extends TestCase protected $array = []; - protected function setUp() + private function doSetUp() { parent::setUp(); $this->bag = new FlashBag(); @@ -36,7 +39,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + private function doTearDown() { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/SessionTest.php b/Tests/Session/SessionTest.php index acb129984..51516e2f2 100644 --- a/Tests/Session/SessionTest.php +++ b/Tests/Session/SessionTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Session; @@ -27,6 +28,8 @@ */ class SessionTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface */ @@ -37,13 +40,13 @@ class SessionTest extends TestCase */ protected $session; - protected function setUp() + private function doSetUp() { $this->storage = new MockArraySessionStorage(); $this->session = new Session($this->storage, new AttributeBag(), new FlashBag()); } - protected function tearDown() + private function doTearDown() { $this->storage = null; $this->session = null; diff --git a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php index 98bc67bca..d83182be7 100644 --- a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php @@ -12,15 +12,18 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @requires PHP 7.0 */ class AbstractSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + private static $server; - public static function setUpBeforeClass() + private static function doSetUpBeforeClass() { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -32,7 +35,7 @@ public static function setUpBeforeClass() sleep(1); } - public static function tearDownAfterClass() + private static function doTearDownAfterClass() { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php index d7a324fc2..d2526868d 100644 --- a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler; /** @@ -21,6 +22,8 @@ */ class MemcacheSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + const PREFIX = 'prefix_'; const TTL = 1000; @@ -31,7 +34,7 @@ class MemcacheSessionHandlerTest extends TestCase protected $memcache; - protected function setUp() + private function doSetUp() { if (\defined('HHVM_VERSION')) { $this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcache class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289'); @@ -45,7 +48,7 @@ protected function setUp() ); } - protected function tearDown() + private function doTearDown() { $this->memcache = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index c3deb7aed..86ac574d2 100644 --- a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler; /** @@ -20,6 +21,8 @@ */ class MemcachedSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + const PREFIX = 'prefix_'; const TTL = 1000; @@ -30,7 +33,7 @@ class MemcachedSessionHandlerTest extends TestCase protected $memcached; - protected function setUp() + private function doSetUp() { if (\defined('HHVM_VERSION')) { $this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcached class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289'); @@ -49,7 +52,7 @@ protected function setUp() ); } - protected function tearDown() + private function doTearDown() { $this->memcached = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 5ce6a9e5a..a762de01c 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; /** @@ -21,6 +22,8 @@ */ class MongoDbSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -28,7 +31,7 @@ class MongoDbSessionHandlerTest extends TestCase private $storage; public $options; - protected function setUp() + private function doSetUp() { parent::setUp(); diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index f0914eb43..e9439c3da 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; /** @@ -20,9 +21,11 @@ */ class PdoSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + private $dbFile; - protected function tearDown() + private function doTearDown() { // make sure the temporary database file is deleted when it has been created (even when a test fails) if ($this->dbFile) { diff --git a/Tests/Session/Storage/MetadataBagTest.php b/Tests/Session/Storage/MetadataBagTest.php index 2c4758b91..02cea3292 100644 --- a/Tests/Session/Storage/MetadataBagTest.php +++ b/Tests/Session/Storage/MetadataBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; /** @@ -21,6 +22,8 @@ */ class MetadataBagTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var MetadataBag */ @@ -28,7 +31,7 @@ class MetadataBagTest extends TestCase protected $array = []; - protected function setUp() + private function doSetUp() { parent::setUp(); $this->bag = new MetadataBag(); @@ -36,7 +39,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + private function doTearDown() { $this->array = []; $this->bag = null; diff --git a/Tests/Session/Storage/MockArraySessionStorageTest.php b/Tests/Session/Storage/MockArraySessionStorageTest.php index 2e3024ef1..c60a78910 100644 --- a/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -23,6 +24,8 @@ */ class MockArraySessionStorageTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var MockArraySessionStorage */ @@ -40,7 +43,7 @@ class MockArraySessionStorageTest extends TestCase private $data; - protected function setUp() + private function doSetUp() { $this->attributes = new AttributeBag(); $this->flashes = new FlashBag(); @@ -56,7 +59,7 @@ protected function setUp() $this->storage->setSessionData($this->data); } - protected function tearDown() + private function doTearDown() { $this->data = null; $this->flashes = null; diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index 9e2692dc0..36b4e605b 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; @@ -23,6 +24,8 @@ */ class MockFileSessionStorageTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var string */ @@ -33,13 +36,13 @@ class MockFileSessionStorageTest extends TestCase */ protected $storage; - protected function setUp() + private function doSetUp() { $this->sessionDir = sys_get_temp_dir().'/sf2test'; $this->storage = $this->getStorage(); } - protected function tearDown() + private function doTearDown() { $this->sessionDir = null; $this->storage = null; diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 7cc2eb79c..035b674c1 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; @@ -31,9 +32,11 @@ */ class NativeSessionStorageTest extends TestCase { + use ForwardCompatTestTrait; + private $savePath; - protected function setUp() + private function doSetUp() { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test'); @@ -42,7 +45,7 @@ protected function setUp() } } - protected function tearDown() + private function doTearDown() { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 752be618b..c8a53f169 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage; @@ -27,9 +28,11 @@ */ class PhpBridgeSessionStorageTest extends TestCase { + use ForwardCompatTestTrait; + private $savePath; - protected function setUp() + private function doSetUp() { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test'); @@ -38,7 +41,7 @@ protected function setUp() } } - protected function tearDown() + private function doTearDown() { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index cbb291f19..499a54a8e 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; @@ -22,17 +23,19 @@ */ class AbstractProxyTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var AbstractProxy */ protected $proxy; - protected function setUp() + private function doSetUp() { $this->proxy = $this->getMockForAbstractClass(AbstractProxy::class); } - protected function tearDown() + private function doTearDown() { $this->proxy = null; } diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index b6e0da99d..63b3c8afb 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; /** @@ -24,6 +25,8 @@ */ class SessionHandlerProxyTest extends TestCase { + use ForwardCompatTestTrait; + /** * @var \PHPUnit_Framework_MockObject_Matcher */ @@ -34,13 +37,13 @@ class SessionHandlerProxyTest extends TestCase */ private $proxy; - protected function setUp() + private function doSetUp() { $this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $this->proxy = new SessionHandlerProxy($this->mock); } - protected function tearDown() + private function doTearDown() { $this->mock = null; $this->proxy = null; From 5abed9c1593767e333a86e733400699f1582b37a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 00:51:35 +0200 Subject: [PATCH 022/127] fix tests --- .../Handler/MemcacheSessionHandlerTest.php | 138 ------------------ 1 file changed, 138 deletions(-) delete mode 100644 Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php diff --git a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php deleted file mode 100644 index d2526868d..000000000 --- a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php +++ /dev/null @@ -1,138 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; - -use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; -use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler; - -/** - * @requires extension memcache - * @group time-sensitive - * @group legacy - */ -class MemcacheSessionHandlerTest extends TestCase -{ - use ForwardCompatTestTrait; - - const PREFIX = 'prefix_'; - const TTL = 1000; - - /** - * @var MemcacheSessionHandler - */ - protected $storage; - - protected $memcache; - - private function doSetUp() - { - if (\defined('HHVM_VERSION')) { - $this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcache class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289'); - } - - parent::setUp(); - $this->memcache = $this->getMockBuilder('Memcache')->getMock(); - $this->storage = new MemcacheSessionHandler( - $this->memcache, - ['prefix' => self::PREFIX, 'expiretime' => self::TTL] - ); - } - - private function doTearDown() - { - $this->memcache = null; - $this->storage = null; - parent::tearDown(); - } - - public function testOpenSession() - { - $this->assertTrue($this->storage->open('', '')); - } - - public function testCloseSession() - { - $this->assertTrue($this->storage->close()); - } - - public function testReadSession() - { - $this->memcache - ->expects($this->once()) - ->method('get') - ->with(self::PREFIX.'id') - ; - - $this->assertEquals('', $this->storage->read('id')); - } - - public function testWriteSession() - { - $this->memcache - ->expects($this->once()) - ->method('set') - ->with(self::PREFIX.'id', 'data', 0, $this->equalTo(time() + self::TTL, 2)) - ->willReturn(true) - ; - - $this->assertTrue($this->storage->write('id', 'data')); - } - - public function testDestroySession() - { - $this->memcache - ->expects($this->once()) - ->method('delete') - ->with(self::PREFIX.'id') - ->willReturn(true) - ; - - $this->assertTrue($this->storage->destroy('id')); - } - - public function testGcSession() - { - $this->assertTrue($this->storage->gc(123)); - } - - /** - * @dataProvider getOptionFixtures - */ - public function testSupportedOptions($options, $supported) - { - try { - new MemcacheSessionHandler($this->memcache, $options); - $this->assertTrue($supported); - } catch (\InvalidArgumentException $e) { - $this->assertFalse($supported); - } - } - - public function getOptionFixtures() - { - return [ - [['prefix' => 'session'], true], - [['expiretime' => 100], true], - [['prefix' => 'session', 'expiretime' => 200], true], - [['expiretime' => 100, 'foo' => 'bar'], false], - ]; - } - - public function testGetConnection() - { - $method = new \ReflectionMethod($this->storage, 'getMemcache'); - $method->setAccessible(true); - - $this->assertInstanceOf('\Memcache', $method->invoke($this->storage)); - } -} From c51914dec54b1f7b27f24cda5eb73399d908395b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 09:31:22 +0200 Subject: [PATCH 023/127] Fix assertInternalType deprecation in phpunit 9 --- Tests/JsonResponseTest.php | 4 ++-- Tests/RequestTest.php | 4 ++-- Tests/Session/Storage/NativeSessionStorageTest.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index 56a40420a..d19620530 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -56,7 +56,7 @@ public function testConstructorWithSimpleTypes() $response = new JsonResponse(0.1); $this->assertEquals('0.1', $response->getContent()); - $this->assertInternalType('string', $response->getContent()); + $this->assertIsString($response->getContent()); $response = new JsonResponse(true); $this->assertSame('true', $response->getContent()); @@ -145,7 +145,7 @@ public function testStaticCreateWithSimpleTypes() $response = JsonResponse::create(0.1); $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); $this->assertEquals('0.1', $response->getContent()); - $this->assertInternalType('string', $response->getContent()); + $this->assertIsString($response->getContent()); $response = JsonResponse::create(true); $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 219a16256..3f7ba6017 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -1156,7 +1156,7 @@ public function testGetContentReturnsResource() { $req = new Request(); $retval = $req->getContent(true); - $this->assertInternalType('resource', $retval); + $this->assertIsResource($retval); $this->assertEquals('', fread($retval, 1)); $this->assertTrue(feof($retval)); } @@ -1166,7 +1166,7 @@ public function testGetContentReturnsResourceWhenContentSetInConstructor() $req = new Request([], [], [], [], [], [], 'MyContent'); $resource = $req->getContent(true); - $this->assertInternalType('resource', $resource); + $this->assertIsResource($resource); $this->assertEquals('MyContent', stream_get_contents($resource)); } diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 035b674c1..18540264d 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -101,7 +101,7 @@ public function testGetId() $storage->start(); $id = $storage->getId(); - $this->assertInternalType('string', $id); + $this->assertIsString($id); $this->assertNotSame('', $id); $storage->save(); From d443039fcc0a029146ceeacdd20c1f8b32d894e0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 12:27:54 +0200 Subject: [PATCH 024/127] fix tests --- Tests/JsonResponseTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index a1c04e975..b7482d033 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\JsonResponse; class JsonResponseTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructorEmptyCreatesJsonObject() { $response = new JsonResponse(); From de20f46d83ec4ab128a5f8d5b28cded6efabbf8a Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Thu, 1 Aug 2019 11:16:35 +0100 Subject: [PATCH 025/127] Ensure signatures for setUp|tearDown|setUpAfterClass|tearDownAfterClass methods in tests are compatible with phpunit 8.2 --- Tests/Session/Storage/Handler/MigratingSessionHandlerTest.php | 2 +- .../Session/Storage/Handler/RedisClusterSessionHandlerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Session/Storage/Handler/MigratingSessionHandlerTest.php b/Tests/Session/Storage/Handler/MigratingSessionHandlerTest.php index 6dc5b0cb5..01615e6b1 100644 --- a/Tests/Session/Storage/Handler/MigratingSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MigratingSessionHandlerTest.php @@ -20,7 +20,7 @@ class MigratingSessionHandlerTest extends TestCase private $currentHandler; private $writeOnlyHandler; - protected function setUp() + protected function setUp(): void { $this->currentHandler = $this->createMock(\SessionHandlerInterface::class); $this->writeOnlyHandler = $this->createMock(\SessionHandlerInterface::class); diff --git a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php index 7d85a59ee..c1ba70dcb 100644 --- a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php @@ -13,7 +13,7 @@ class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { - public static function setupBeforeClass() + public static function setUpBeforeClass(): void { if (!class_exists('RedisCluster')) { self::markTestSkipped('The RedisCluster class is required.'); From f5527fa8c3a5c76f327f9171d9e7c60194b64da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 16:27:42 +0200 Subject: [PATCH 026/127] Replace calls to setExpectedException by Pollyfill --- Tests/File/FileTest.php | 5 ++++- Tests/File/MimeType/MimeTypeTest.php | 6 +++--- Tests/File/UploadedFileTest.php | 2 +- Tests/RequestTest.php | 8 ++------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Tests/File/FileTest.php b/Tests/File/FileTest.php index caf202992..1f2582145 100644 --- a/Tests/File/FileTest.php +++ b/Tests/File/FileTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\HttpFoundation\Tests\File; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; class FileTest extends TestCase { + use ForwardCompatTestTrait; + protected $file; public function testGetMimeTypeUsesMimeTypeGuessers() @@ -64,7 +67,7 @@ public function testGuessExtensionWithReset() public function testConstructWhenFileNotExists() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); new File(__DIR__.'/Fixtures/not_here'); } diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index 9f3c87c98..299fc7a24 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -32,7 +32,7 @@ public function testGuessImageWithoutExtension() public function testGuessImageWithDirectory() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory'); } @@ -56,7 +56,7 @@ public function testGuessFileWithUnknownExtension() public function testGuessWithIncorrectPath() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here'); } @@ -75,7 +75,7 @@ public function testGuessWithNonReadablePath() @chmod($path, 0333); if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException'); + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException'); MimeTypeGuesser::getInstance()->guess($path); } else { $this->markTestSkipped('Can not verify chmod operations, change of file permissions failed'); diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index f886ebcd1..3a203b4da 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -28,7 +28,7 @@ private function doSetUp() public function testConstructWhenFileNotExists() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); new UploadedFile( __DIR__.'/Fixtures/not_here', diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 3f7ba6017..e0e719d38 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2121,12 +2121,8 @@ public function testHostValidity($host, $isValid, $expectedHost = null, $expecte $this->assertSame($expectedPort, $request->getPort()); } } else { - if (method_exists($this, 'expectException')) { - $this->expectException(SuspiciousOperationException::class); - $this->expectExceptionMessage('Invalid Host'); - } else { - $this->setExpectedException(SuspiciousOperationException::class, 'Invalid Host'); - } + $this->expectException(SuspiciousOperationException::class); + $this->expectExceptionMessage('Invalid Host'); $request->getHost(); } From c8b6934f07abf8642a9110a53d551a1e78ff7778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 00:48:42 +0200 Subject: [PATCH 027/127] Fix deprecated phpunit annotation --- Tests/BinaryFileResponseTest.php | 4 +--- Tests/CookieTest.php | 9 +++++---- Tests/ExpressionRequestMatcherTest.php | 7 ++++--- Tests/File/UploadedFileTest.php | 4 +--- Tests/FileBagTest.php | 4 +--- Tests/HeaderBagTest.php | 7 ++++--- Tests/IpUtilsTest.php | 5 ++++- Tests/JsonResponseTest.php | 14 ++++---------- Tests/RedirectResponseTest.php | 15 ++++++--------- Tests/RequestTest.php | 12 +++++------- Tests/ResponseHeaderBagTest.php | 13 ++++++------- Tests/ResponseTest.php | 11 +++++++---- .../Handler/MongoDbSessionHandlerTest.php | 8 ++------ .../Handler/NativeFileSessionHandlerTest.php | 7 ++++--- .../Storage/Handler/PdoSessionHandlerTest.php | 12 +++--------- .../Storage/MockArraySessionStorageTest.php | 4 +--- .../Storage/MockFileSessionStorageTest.php | 4 +--- .../Session/Storage/NativeSessionStorageTest.php | 16 ++++------------ .../Session/Storage/Proxy/AbstractProxyTest.php | 4 ++-- .../Storage/Proxy/SessionHandlerProxyTest.php | 2 +- Tests/StreamedResponseTest.php | 11 +++++------ 21 files changed, 71 insertions(+), 102 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 74d3e8162..9e27c7313 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -49,11 +49,9 @@ public function testConstructWithNonAsciiFilename() $this->assertSame('fööö.html', $response->getFile()->getFilename()); } - /** - * @expectedException \LogicException - */ public function testSetContent() { + $this->expectException('LogicException'); $response = new BinaryFileResponse(__FILE__); $response->setContent('foo'); } diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index aaf2edb38..2d69d9ace 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Cookie; /** @@ -24,6 +25,8 @@ */ class CookieTest extends TestCase { + use ForwardCompatTestTrait; + public function invalidNames() { return [ @@ -41,18 +44,16 @@ public function invalidNames() /** * @dataProvider invalidNames - * @expectedException \InvalidArgumentException */ public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name) { + $this->expectException('InvalidArgumentException'); new Cookie($name); } - /** - * @expectedException \InvalidArgumentException - */ public function testInvalidExpiration() { + $this->expectException('InvalidArgumentException'); new Cookie('MyCookie', 'foo', 'bar'); } diff --git a/Tests/ExpressionRequestMatcherTest.php b/Tests/ExpressionRequestMatcherTest.php index 2afdade67..e750f39e6 100644 --- a/Tests/ExpressionRequestMatcherTest.php +++ b/Tests/ExpressionRequestMatcherTest.php @@ -12,17 +12,18 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\HttpFoundation\ExpressionRequestMatcher; use Symfony\Component\HttpFoundation\Request; class ExpressionRequestMatcherTest extends TestCase { - /** - * @expectedException \LogicException - */ + use ForwardCompatTestTrait; + public function testWhenNoExpressionIsSet() { + $this->expectException('LogicException'); $expressionRequestMatcher = new ExpressionRequestMatcher(); $expressionRequestMatcher->matches(new Request()); } diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 3a203b4da..9b48da7a2 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -145,11 +145,9 @@ public function testGetClientOriginalExtension() $this->assertEquals('gif', $file->getClientOriginalExtension()); } - /** - * @expectedException \Symfony\Component\HttpFoundation\File\Exception\FileException - */ public function testMoveLocalFileIsNotAllowed() { + $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileException'); $file = new UploadedFile( __DIR__.'/Fixtures/test.gif', 'original.gif', diff --git a/Tests/FileBagTest.php b/Tests/FileBagTest.php index 3ef868eaf..289c12bd3 100644 --- a/Tests/FileBagTest.php +++ b/Tests/FileBagTest.php @@ -26,11 +26,9 @@ class FileBagTest extends TestCase { use ForwardCompatTestTrait; - /** - * @expectedException \InvalidArgumentException - */ public function testFileMustBeAnArrayOrUploadedFile() { + $this->expectException('InvalidArgumentException'); new FileBag(['file' => 'foo']); } diff --git a/Tests/HeaderBagTest.php b/Tests/HeaderBagTest.php index 6c4915f2e..3eff56840 100644 --- a/Tests/HeaderBagTest.php +++ b/Tests/HeaderBagTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\HeaderBag; class HeaderBagTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $bag = new HeaderBag(['foo' => 'bar']); @@ -48,11 +51,9 @@ public function testGetDate() $this->assertInstanceOf('DateTime', $headerDate); } - /** - * @expectedException \RuntimeException - */ public function testGetDateException() { + $this->expectException('RuntimeException'); $bag = new HeaderBag(['foo' => 'Tue']); $headerDate = $bag->getDate('foo'); } diff --git a/Tests/IpUtilsTest.php b/Tests/IpUtilsTest.php index c7f76b5de..338da1d25 100644 --- a/Tests/IpUtilsTest.php +++ b/Tests/IpUtilsTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\IpUtils; class IpUtilsTest extends TestCase { + use ForwardCompatTestTrait; + /** * @dataProvider getIpv4Data */ @@ -73,11 +76,11 @@ public function getIpv6Data() } /** - * @expectedException \RuntimeException * @requires extension sockets */ public function testAnIpv6WithOptionDisabledIpv6() { + $this->expectException('RuntimeException'); if (\defined('AF_INET6')) { $this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".'); } diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index d19620530..2e2645dab 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -219,29 +219,23 @@ public function testItAcceptsJsonAsString() $this->assertSame('{"foo":"bar"}', $response->getContent()); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetCallbackInvalidIdentifier() { + $this->expectException('InvalidArgumentException'); $response = new JsonResponse('foo'); $response->setCallback('+invalid'); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetContent() { + $this->expectException('InvalidArgumentException'); JsonResponse::create("\xB1\x31"); } - /** - * @expectedException \Exception - * @expectedExceptionMessage This error is expected - */ public function testSetContentJsonSerializeError() { + $this->expectException('Exception'); + $this->expectExceptionMessage('This error is expected'); if (!interface_exists('JsonSerializable', false)) { $this->markTestSkipped('JsonSerializable is required.'); } diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index 5f6a8ac08..1e4b7a6ca 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\RedirectResponse; class RedirectResponseTest extends TestCase { + use ForwardCompatTestTrait; + public function testGenerateMetaRedirect() { $response = new RedirectResponse('foo.bar'); @@ -26,19 +29,15 @@ public function testGenerateMetaRedirect() )); } - /** - * @expectedException \InvalidArgumentException - */ public function testRedirectResponseConstructorNullUrl() { + $this->expectException('InvalidArgumentException'); $response = new RedirectResponse(null); } - /** - * @expectedException \InvalidArgumentException - */ public function testRedirectResponseConstructorWrongStatusCode() { + $this->expectException('InvalidArgumentException'); $response = new RedirectResponse('foo.bar', 404); } @@ -65,11 +64,9 @@ public function testSetTargetUrl() $this->assertEquals('baz.beep', $response->getTargetUrl()); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetTargetUrlNull() { + $this->expectException('InvalidArgumentException'); $response = new RedirectResponse('foo.bar'); $response->setTargetUrl(null); } diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index e0e719d38..dad3f0bf2 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -889,11 +889,9 @@ public function testGetPort() $this->assertEquals(80, $port, 'With only PROTO set and value is not recognized, getPort() defaults to 80.'); } - /** - * @expectedException \RuntimeException - */ public function testGetHostWithFakeHttpHostValue() { + $this->expectException('RuntimeException'); $request = new Request(); $request->initialize([], [], [], [], [], ['HTTP_HOST' => 'www.host.com?query=string']); $request->getHost(); @@ -1058,11 +1056,11 @@ public function getClientIpsProvider() } /** - * @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException * @dataProvider getClientIpsWithConflictingHeadersProvider */ public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXForwardedFor) { + $this->expectException('Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException'); $request = new Request(); $server = [ @@ -1182,11 +1180,11 @@ public function testContentAsResource() } /** - * @expectedException \LogicException * @dataProvider getContentCantBeCalledTwiceWithResourcesProvider */ public function testGetContentCantBeCalledTwiceWithResources($first, $second) { + $this->expectException('LogicException'); if (\PHP_VERSION_ID >= 50600) { $this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.'); } @@ -1971,20 +1969,20 @@ public function testTrustedProxiesForwarded() /** * @group legacy - * @expectedException \InvalidArgumentException */ public function testSetTrustedProxiesInvalidHeaderName() { + $this->expectException('InvalidArgumentException'); Request::create('http://example.com/'); Request::setTrustedHeaderName('bogus name', 'X_MY_FOR'); } /** * @group legacy - * @expectedException \InvalidArgumentException */ public function testGetTrustedProxiesInvalidHeaderName() { + $this->expectException('InvalidArgumentException'); Request::create('http://example.com/'); Request::getTrustedHeaderName('bogus name'); } diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index 93aacf24d..17be3cb60 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\ResponseHeaderBag; @@ -20,6 +21,8 @@ */ class ResponseHeaderBagTest extends TestCase { + use ForwardCompatTestTrait; + public function testAllPreserveCase() { $headers = [ @@ -240,21 +243,17 @@ public function testSetCookieHeader() $this->assertEquals([], $bag->getCookies()); } - /** - * @expectedException \InvalidArgumentException - */ public function testGetCookiesWithInvalidArgument() { + $this->expectException('InvalidArgumentException'); $bag = new ResponseHeaderBag(); $bag->getCookies('invalid_argument'); } - /** - * @expectedException \InvalidArgumentException - */ public function testMakeDispositionInvalidDisposition() { + $this->expectException('InvalidArgumentException'); $headers = new ResponseHeaderBag(); $headers->makeDisposition('invalid', 'foo.html'); @@ -298,10 +297,10 @@ public function provideMakeDisposition() /** * @dataProvider provideMakeDispositionFail - * @expectedException \InvalidArgumentException */ public function testMakeDispositionFail($disposition, $filename) { + $this->expectException('InvalidArgumentException'); $headers = new ResponseHeaderBag(); $headers->makeDisposition($disposition, $filename); diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 40200ee31..7515a7a9e 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpFoundation\Tests; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -19,6 +20,8 @@ */ class ResponseTest extends ResponseTestCase { + use ForwardCompatTestTrait; + public function testCreate() { $response = Response::create('foo', 301, ['Foo' => 'bar']); @@ -846,11 +849,11 @@ public function testSetContent($content) } /** - * @expectedException \UnexpectedValueException * @dataProvider invalidContentProvider */ public function testSetContentInvalid($content) { + $this->expectException('UnexpectedValueException'); $response = new Response(); $response->setContent($content); } @@ -928,11 +931,11 @@ protected function provideResponse() } /** - * @see http://github.com/zendframework/zend-diactoros for the canonical source repository + * @see http://github.com/zendframework/zend-diactoros for the canonical source repository * - * @author Fábio Pacheco + * @author Fábio Pacheco * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) - * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License */ public function ianaCodesReasonPhrasesProvider() { diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index a762de01c..8fd72a91f 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -65,19 +65,15 @@ private function doSetUp() $this->storage = new MongoDbSessionHandler($this->mongo, $this->options); } - /** - * @expectedException \InvalidArgumentException - */ public function testConstructorShouldThrowExceptionForInvalidMongo() { + $this->expectException('InvalidArgumentException'); new MongoDbSessionHandler(new \stdClass(), $this->options); } - /** - * @expectedException \InvalidArgumentException - */ public function testConstructorShouldThrowExceptionForMissingOptions() { + $this->expectException('InvalidArgumentException'); new MongoDbSessionHandler($this->mongo, []); } diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index dc827d8ab..303ad3026 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; @@ -25,6 +26,8 @@ */ class NativeFileSessionHandlerTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstruct() { $storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir())); @@ -59,11 +62,9 @@ public function savePathDataProvider() ]; } - /** - * @expectedException \InvalidArgumentException - */ public function testConstructException() { + $this->expectException('InvalidArgumentException'); $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args'); } diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index e9439c3da..0571306ab 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -51,22 +51,18 @@ protected function getMemorySqlitePdo() return $pdo; } - /** - * @expectedException \InvalidArgumentException - */ public function testWrongPdoErrMode() { + $this->expectException('InvalidArgumentException'); $pdo = $this->getMemorySqlitePdo(); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); $storage = new PdoSessionHandler($pdo); } - /** - * @expectedException \RuntimeException - */ public function testInexistentTable() { + $this->expectException('RuntimeException'); $storage = new PdoSessionHandler($this->getMemorySqlitePdo(), ['db_table' => 'inexistent_table']); $storage->open('', 'sid'); $storage->read('id'); @@ -74,11 +70,9 @@ public function testInexistentTable() $storage->close(); } - /** - * @expectedException \RuntimeException - */ public function testCreateTableTwice() { + $this->expectException('RuntimeException'); $storage = new PdoSessionHandler($this->getMemorySqlitePdo()); $storage->createTable(); } diff --git a/Tests/Session/Storage/MockArraySessionStorageTest.php b/Tests/Session/Storage/MockArraySessionStorageTest.php index c60a78910..1285dbf1a 100644 --- a/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -124,11 +124,9 @@ public function testClearWithNoBagsStartsSession() $this->assertTrue($storage->isStarted()); } - /** - * @expectedException \RuntimeException - */ public function testUnstartedSave() { + $this->expectException('RuntimeException'); $this->storage->save(); } } diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index 36b4e605b..9a5ef1ca8 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -110,11 +110,9 @@ public function testMultipleInstances() $this->assertEquals('bar', $storage2->getBag('attributes')->get('foo'), 'values persist between instances'); } - /** - * @expectedException \RuntimeException - */ public function testSaveWithoutStart() { + $this->expectException('RuntimeException'); $storage1 = $this->getStorage(); $storage1->save(); } diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 18540264d..886a5f9c9 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -75,20 +75,16 @@ public function testBag() $this->assertSame($bag, $storage->getBag($bag->getName())); } - /** - * @expectedException \InvalidArgumentException - */ public function testRegisterBagException() { + $this->expectException('InvalidArgumentException'); $storage = $this->getStorage(); $storage->getBag('non_existing'); } - /** - * @expectedException \LogicException - */ public function testRegisterBagForAStartedSessionThrowsException() { + $this->expectException('LogicException'); $storage = $this->getStorage(); $storage->start(); $storage->registerBag(new AttributeBag()); @@ -204,11 +200,9 @@ public function testSessionOptions() $this->assertSame('200', ini_get('session.cache_expire')); } - /** - * @expectedException \InvalidArgumentException - */ public function testSetSaveHandlerException() { + $this->expectException('InvalidArgumentException'); $storage = $this->getStorage(); $storage->setSaveHandler(new \stdClass()); } @@ -231,11 +225,9 @@ public function testSetSaveHandler() $this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler()); } - /** - * @expectedException \RuntimeException - */ public function testStarted() { + $this->expectException('RuntimeException'); $storage = $this->getStorage(); $this->assertFalse($storage->getSaveHandler()->isActive()); diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index 499a54a8e..dcd300364 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -83,10 +83,10 @@ public function testName() /** * @runInSeparateProcess * @preserveGlobalState disabled - * @expectedException \LogicException */ public function testNameException() { + $this->expectException('LogicException'); session_start(); $this->proxy->setName('foo'); } @@ -106,10 +106,10 @@ public function testId() /** * @runInSeparateProcess * @preserveGlobalState disabled - * @expectedException \LogicException */ public function testIdException() { + $this->expectException('LogicException'); session_start(); $this->proxy->setId('foo'); } diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index 63b3c8afb..d6459e10d 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -28,7 +28,7 @@ class SessionHandlerProxyTest extends TestCase use ForwardCompatTestTrait; /** - * @var \PHPUnit_Framework_MockObject_Matcher + * @var \PHPUnit\Framework\MockObject\Matcher */ private $mock; diff --git a/Tests/StreamedResponseTest.php b/Tests/StreamedResponseTest.php index 62dfc9bc9..96ab63d49 100644 --- a/Tests/StreamedResponseTest.php +++ b/Tests/StreamedResponseTest.php @@ -12,11 +12,14 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\StreamedResponse; class StreamedResponseTest extends TestCase { + use ForwardCompatTestTrait; + public function testConstructor() { $response = new StreamedResponse(function () { echo 'foo'; }, 404, ['Content-Type' => 'text/plain']); @@ -81,20 +84,16 @@ public function testSendContent() $this->assertEquals(1, $called); } - /** - * @expectedException \LogicException - */ public function testSendContentWithNonCallable() { + $this->expectException('LogicException'); $response = new StreamedResponse(null); $response->sendContent(); } - /** - * @expectedException \LogicException - */ public function testSetContent() { + $this->expectException('LogicException'); $response = new StreamedResponse(function () { echo 'foo'; }); $response->setContent('foo'); } From f256acff193d533bc37faf0f5bdccd74e7fc1e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 19:02:27 +0200 Subject: [PATCH 028/127] Remove use of ForwardCompatTrait --- Tests/BinaryFileResponseTest.php | 5 +---- Tests/CookieTest.php | 3 --- Tests/ExpressionRequestMatcherTest.php | 3 --- Tests/File/FileTest.php | 3 --- Tests/File/MimeType/MimeTypeTest.php | 5 +---- Tests/File/UploadedFileTest.php | 5 +---- Tests/FileBagTest.php | 7 ++----- Tests/HeaderBagTest.php | 3 --- Tests/IpUtilsTest.php | 3 --- Tests/JsonResponseTest.php | 5 +---- Tests/RedirectResponseTest.php | 3 --- Tests/RequestTest.php | 5 +---- Tests/ResponseFunctionalTest.php | 7 ++----- Tests/ResponseHeaderBagTest.php | 3 --- Tests/ResponseTest.php | 3 --- Tests/Session/Attribute/AttributeBagTest.php | 7 ++----- Tests/Session/Attribute/NamespacedAttributeBagTest.php | 7 ++----- Tests/Session/Flash/AutoExpireFlashBagTest.php | 7 ++----- Tests/Session/Flash/FlashBagTest.php | 7 ++----- Tests/Session/SessionTest.php | 7 ++----- .../Session/Storage/Handler/AbstractSessionHandlerTest.php | 7 ++----- .../Session/Storage/Handler/MemcacheSessionHandlerTest.php | 7 ++----- .../Storage/Handler/MemcachedSessionHandlerTest.php | 7 ++----- .../Session/Storage/Handler/MongoDbSessionHandlerTest.php | 5 +---- .../Storage/Handler/NativeFileSessionHandlerTest.php | 3 --- Tests/Session/Storage/Handler/PdoSessionHandlerTest.php | 5 +---- Tests/Session/Storage/MetadataBagTest.php | 7 ++----- Tests/Session/Storage/MockArraySessionStorageTest.php | 7 ++----- Tests/Session/Storage/MockFileSessionStorageTest.php | 7 ++----- Tests/Session/Storage/NativeSessionStorageTest.php | 7 ++----- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 7 ++----- Tests/Session/Storage/Proxy/AbstractProxyTest.php | 7 ++----- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 7 ++----- Tests/StreamedResponseTest.php | 3 --- 34 files changed, 41 insertions(+), 143 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 9e27c7313..0bc150e8d 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\HttpFoundation\Tests; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Stream; use Symfony\Component\HttpFoundation\Request; @@ -20,8 +19,6 @@ class BinaryFileResponseTest extends ResponseTestCase { - use ForwardCompatTestTrait; - public function testConstruction() { $file = __DIR__.'/../README.md'; @@ -357,7 +354,7 @@ protected function provideResponse() return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']); } - private static function doTearDownAfterClass() + public static function tearDownAfterClass() { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index 2d69d9ace..e382182b4 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Cookie; /** @@ -25,8 +24,6 @@ */ class CookieTest extends TestCase { - use ForwardCompatTestTrait; - public function invalidNames() { return [ diff --git a/Tests/ExpressionRequestMatcherTest.php b/Tests/ExpressionRequestMatcherTest.php index e750f39e6..8a389329e 100644 --- a/Tests/ExpressionRequestMatcherTest.php +++ b/Tests/ExpressionRequestMatcherTest.php @@ -12,15 +12,12 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\HttpFoundation\ExpressionRequestMatcher; use Symfony\Component\HttpFoundation\Request; class ExpressionRequestMatcherTest extends TestCase { - use ForwardCompatTestTrait; - public function testWhenNoExpressionIsSet() { $this->expectException('LogicException'); diff --git a/Tests/File/FileTest.php b/Tests/File/FileTest.php index 1f2582145..b463aadf8 100644 --- a/Tests/File/FileTest.php +++ b/Tests/File/FileTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\HttpFoundation\Tests\File; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; class FileTest extends TestCase { - use ForwardCompatTestTrait; - protected $file; public function testGetMimeTypeUsesMimeTypeGuessers() diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index 299fc7a24..3960988a6 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\File\MimeType; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; @@ -21,8 +20,6 @@ */ class MimeTypeTest extends TestCase { - use ForwardCompatTestTrait; - protected $path; public function testGuessImageWithoutExtension() @@ -82,7 +79,7 @@ public function testGuessWithNonReadablePath() } } - private static function doTearDownAfterClass() + public static function tearDownAfterClass() { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 9b48da7a2..629211052 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\HttpFoundation\Tests\File; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\UploadedFile; class UploadedFileTest extends TestCase { - use ForwardCompatTestTrait; - - private function doSetUp() + protected function setUp() { if (!ini_get('file_uploads')) { $this->markTestSkipped('file_uploads is disabled in php.ini'); diff --git a/Tests/FileBagTest.php b/Tests/FileBagTest.php index 289c12bd3..a3882bc86 100644 --- a/Tests/FileBagTest.php +++ b/Tests/FileBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\FileBag; @@ -24,8 +23,6 @@ */ class FileBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testFileMustBeAnArrayOrUploadedFile() { $this->expectException('InvalidArgumentException'); @@ -160,12 +157,12 @@ protected function createTempFile() return tempnam(sys_get_temp_dir().'/form_test', 'FormTest'); } - private function doSetUp() + protected function setUp() { mkdir(sys_get_temp_dir().'/form_test', 0777, true); } - private function doTearDown() + protected function tearDown() { foreach (glob(sys_get_temp_dir().'/form_test/*') as $file) { unlink($file); diff --git a/Tests/HeaderBagTest.php b/Tests/HeaderBagTest.php index 3eff56840..a5876f9e3 100644 --- a/Tests/HeaderBagTest.php +++ b/Tests/HeaderBagTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\HeaderBag; class HeaderBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $bag = new HeaderBag(['foo' => 'bar']); diff --git a/Tests/IpUtilsTest.php b/Tests/IpUtilsTest.php index 338da1d25..d3b262e04 100644 --- a/Tests/IpUtilsTest.php +++ b/Tests/IpUtilsTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\IpUtils; class IpUtilsTest extends TestCase { - use ForwardCompatTestTrait; - /** * @dataProvider getIpv4Data */ diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index 2e2645dab..fd045fb9c 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\JsonResponse; class JsonResponseTest extends TestCase { - use ForwardCompatTestTrait; - - private function doSetUp() + protected function setUp() { parent::setUp(); diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index 1e4b7a6ca..92f4876da 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -12,13 +12,10 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\RedirectResponse; class RedirectResponseTest extends TestCase { - use ForwardCompatTestTrait; - public function testGenerateMetaRedirect() { $response = new RedirectResponse('foo.bar'); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index dad3f0bf2..aaefc0359 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\Session; @@ -20,9 +19,7 @@ class RequestTest extends TestCase { - use ForwardCompatTestTrait; - - private function doTearDown() + protected function tearDown() { Request::setTrustedProxies([], -1); Request::setTrustedHosts([]); diff --git a/Tests/ResponseFunctionalTest.php b/Tests/ResponseFunctionalTest.php index e264710d1..3d3e696c7 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -12,18 +12,15 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @requires PHP 7.0 */ class ResponseFunctionalTest extends TestCase { - use ForwardCompatTestTrait; - private static $server; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -35,7 +32,7 @@ private static function doSetUpBeforeClass() sleep(1); } - private static function doTearDownAfterClass() + public static function tearDownAfterClass() { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index 17be3cb60..d85f6e112 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\ResponseHeaderBag; @@ -21,8 +20,6 @@ */ class ResponseHeaderBagTest extends TestCase { - use ForwardCompatTestTrait; - public function testAllPreserveCase() { $headers = [ diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 7515a7a9e..776f85cd0 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\HttpFoundation\Tests; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -20,8 +19,6 @@ */ class ResponseTest extends ResponseTestCase { - use ForwardCompatTestTrait; - public function testCreate() { $response = Response::create('foo', 301, ['Foo' => 'bar']); diff --git a/Tests/Session/Attribute/AttributeBagTest.php b/Tests/Session/Attribute/AttributeBagTest.php index aef66da1d..3f2f7b3c8 100644 --- a/Tests/Session/Attribute/AttributeBagTest.php +++ b/Tests/Session/Attribute/AttributeBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; /** @@ -22,8 +21,6 @@ */ class AttributeBagTest extends TestCase { - use ForwardCompatTestTrait; - private $array = []; /** @@ -31,7 +28,7 @@ class AttributeBagTest extends TestCase */ private $bag; - private function doSetUp() + protected function setUp() { $this->array = [ 'hello' => 'world', @@ -52,7 +49,7 @@ private function doSetUp() $this->bag->initialize($this->array); } - private function doTearDown() + protected function tearDown() { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Attribute/NamespacedAttributeBagTest.php b/Tests/Session/Attribute/NamespacedAttributeBagTest.php index a1f6bf5eb..6b4bb17d6 100644 --- a/Tests/Session/Attribute/NamespacedAttributeBagTest.php +++ b/Tests/Session/Attribute/NamespacedAttributeBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag; /** @@ -22,8 +21,6 @@ */ class NamespacedAttributeBagTest extends TestCase { - use ForwardCompatTestTrait; - private $array = []; /** @@ -31,7 +28,7 @@ class NamespacedAttributeBagTest extends TestCase */ private $bag; - private function doSetUp() + protected function setUp() { $this->array = [ 'hello' => 'world', @@ -52,7 +49,7 @@ private function doSetUp() $this->bag->initialize($this->array); } - private function doTearDown() + protected function tearDown() { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Flash/AutoExpireFlashBagTest.php b/Tests/Session/Flash/AutoExpireFlashBagTest.php index 65b205814..b4e2c3a5a 100644 --- a/Tests/Session/Flash/AutoExpireFlashBagTest.php +++ b/Tests/Session/Flash/AutoExpireFlashBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Flash; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag; /** @@ -22,8 +21,6 @@ */ class AutoExpireFlashBagTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag */ @@ -31,7 +28,7 @@ class AutoExpireFlashBagTest extends TestCase protected $array = []; - private function doSetUp() + protected function setUp() { parent::setUp(); $this->bag = new FlashBag(); @@ -39,7 +36,7 @@ private function doSetUp() $this->bag->initialize($this->array); } - private function doTearDown() + protected function tearDown() { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/Flash/FlashBagTest.php b/Tests/Session/Flash/FlashBagTest.php index 427af6d67..6d8619e07 100644 --- a/Tests/Session/Flash/FlashBagTest.php +++ b/Tests/Session/Flash/FlashBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Flash; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; /** @@ -22,8 +21,6 @@ */ class FlashBagTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface */ @@ -31,7 +28,7 @@ class FlashBagTest extends TestCase protected $array = []; - private function doSetUp() + protected function setUp() { parent::setUp(); $this->bag = new FlashBag(); @@ -39,7 +36,7 @@ private function doSetUp() $this->bag->initialize($this->array); } - private function doTearDown() + protected function tearDown() { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/SessionTest.php b/Tests/Session/SessionTest.php index 51516e2f2..acb129984 100644 --- a/Tests/Session/SessionTest.php +++ b/Tests/Session/SessionTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Session; @@ -28,8 +27,6 @@ */ class SessionTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface */ @@ -40,13 +37,13 @@ class SessionTest extends TestCase */ protected $session; - private function doSetUp() + protected function setUp() { $this->storage = new MockArraySessionStorage(); $this->session = new Session($this->storage, new AttributeBag(), new FlashBag()); } - private function doTearDown() + protected function tearDown() { $this->storage = null; $this->session = null; diff --git a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php index d83182be7..98bc67bca 100644 --- a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php @@ -12,18 +12,15 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @requires PHP 7.0 */ class AbstractSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - private static $server; - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -35,7 +32,7 @@ private static function doSetUpBeforeClass() sleep(1); } - private static function doTearDownAfterClass() + public static function tearDownAfterClass() { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php index d2526868d..d7a324fc2 100644 --- a/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler; /** @@ -22,8 +21,6 @@ */ class MemcacheSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - const PREFIX = 'prefix_'; const TTL = 1000; @@ -34,7 +31,7 @@ class MemcacheSessionHandlerTest extends TestCase protected $memcache; - private function doSetUp() + protected function setUp() { if (\defined('HHVM_VERSION')) { $this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcache class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289'); @@ -48,7 +45,7 @@ private function doSetUp() ); } - private function doTearDown() + protected function tearDown() { $this->memcache = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index 86ac574d2..c3deb7aed 100644 --- a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler; /** @@ -21,8 +20,6 @@ */ class MemcachedSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - const PREFIX = 'prefix_'; const TTL = 1000; @@ -33,7 +30,7 @@ class MemcachedSessionHandlerTest extends TestCase protected $memcached; - private function doSetUp() + protected function setUp() { if (\defined('HHVM_VERSION')) { $this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcached class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289'); @@ -52,7 +49,7 @@ private function doSetUp() ); } - private function doTearDown() + protected function tearDown() { $this->memcached = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 8fd72a91f..7bc84f876 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; /** @@ -22,8 +21,6 @@ */ class MongoDbSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -31,7 +28,7 @@ class MongoDbSessionHandlerTest extends TestCase private $storage; public $options; - private function doSetUp() + protected function setUp() { parent::setUp(); diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 303ad3026..348714a26 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; @@ -26,8 +25,6 @@ */ class NativeFileSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstruct() { $storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir())); diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 0571306ab..ff513b7ef 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; /** @@ -21,11 +20,9 @@ */ class PdoSessionHandlerTest extends TestCase { - use ForwardCompatTestTrait; - private $dbFile; - private function doTearDown() + protected function tearDown() { // make sure the temporary database file is deleted when it has been created (even when a test fails) if ($this->dbFile) { diff --git a/Tests/Session/Storage/MetadataBagTest.php b/Tests/Session/Storage/MetadataBagTest.php index 02cea3292..2c4758b91 100644 --- a/Tests/Session/Storage/MetadataBagTest.php +++ b/Tests/Session/Storage/MetadataBagTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; /** @@ -22,8 +21,6 @@ */ class MetadataBagTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var MetadataBag */ @@ -31,7 +28,7 @@ class MetadataBagTest extends TestCase protected $array = []; - private function doSetUp() + protected function setUp() { parent::setUp(); $this->bag = new MetadataBag(); @@ -39,7 +36,7 @@ private function doSetUp() $this->bag->initialize($this->array); } - private function doTearDown() + protected function tearDown() { $this->array = []; $this->bag = null; diff --git a/Tests/Session/Storage/MockArraySessionStorageTest.php b/Tests/Session/Storage/MockArraySessionStorageTest.php index 1285dbf1a..7e0d303b9 100644 --- a/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -24,8 +23,6 @@ */ class MockArraySessionStorageTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var MockArraySessionStorage */ @@ -43,7 +40,7 @@ class MockArraySessionStorageTest extends TestCase private $data; - private function doSetUp() + protected function setUp() { $this->attributes = new AttributeBag(); $this->flashes = new FlashBag(); @@ -59,7 +56,7 @@ private function doSetUp() $this->storage->setSessionData($this->data); } - private function doTearDown() + protected function tearDown() { $this->data = null; $this->flashes = null; diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index 9a5ef1ca8..b316c83e6 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; @@ -24,8 +23,6 @@ */ class MockFileSessionStorageTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var string */ @@ -36,13 +33,13 @@ class MockFileSessionStorageTest extends TestCase */ protected $storage; - private function doSetUp() + protected function setUp() { $this->sessionDir = sys_get_temp_dir().'/sf2test'; $this->storage = $this->getStorage(); } - private function doTearDown() + protected function tearDown() { $this->sessionDir = null; $this->storage = null; diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 886a5f9c9..fa170d17d 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; @@ -32,11 +31,9 @@ */ class NativeSessionStorageTest extends TestCase { - use ForwardCompatTestTrait; - private $savePath; - private function doSetUp() + protected function setUp() { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test'); @@ -45,7 +42,7 @@ private function doSetUp() } } - private function doTearDown() + protected function tearDown() { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index c8a53f169..752be618b 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage; @@ -28,11 +27,9 @@ */ class PhpBridgeSessionStorageTest extends TestCase { - use ForwardCompatTestTrait; - private $savePath; - private function doSetUp() + protected function setUp() { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test'); @@ -41,7 +38,7 @@ private function doSetUp() } } - private function doTearDown() + protected function tearDown() { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index dcd300364..ae40f2c29 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; @@ -23,19 +22,17 @@ */ class AbstractProxyTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var AbstractProxy */ protected $proxy; - private function doSetUp() + protected function setUp() { $this->proxy = $this->getMockForAbstractClass(AbstractProxy::class); } - private function doTearDown() + protected function tearDown() { $this->proxy = null; } diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index d6459e10d..ec9029c7d 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; /** @@ -25,8 +24,6 @@ */ class SessionHandlerProxyTest extends TestCase { - use ForwardCompatTestTrait; - /** * @var \PHPUnit\Framework\MockObject\Matcher */ @@ -37,13 +34,13 @@ class SessionHandlerProxyTest extends TestCase */ private $proxy; - private function doSetUp() + protected function setUp() { $this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $this->proxy = new SessionHandlerProxy($this->mock); } - private function doTearDown() + protected function tearDown() { $this->mock = null; $this->proxy = null; diff --git a/Tests/StreamedResponseTest.php b/Tests/StreamedResponseTest.php index 96ab63d49..a084e917d 100644 --- a/Tests/StreamedResponseTest.php +++ b/Tests/StreamedResponseTest.php @@ -12,14 +12,11 @@ namespace Symfony\Component\HttpFoundation\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\StreamedResponse; class StreamedResponseTest extends TestCase { - use ForwardCompatTestTrait; - public function testConstructor() { $response = new StreamedResponse(function () { echo 'foo'; }, 404, ['Content-Type' => 'text/plain']); From 9f3c40c251aa69af0b0e4a6020f7d51e6831e898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sun, 4 Aug 2019 11:16:42 +0200 Subject: [PATCH 029/127] Remove calls to deprecated function assertAttributeX --- .../Storage/Handler/PdoSessionHandlerTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index ff513b7ef..123b605d2 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -324,15 +324,15 @@ public function testGetConnectionConnectsIfNeeded() public function testUrlDsn($url, $expectedDsn, $expectedUser = null, $expectedPassword = null) { $storage = new PdoSessionHandler($url); - - $this->assertAttributeEquals($expectedDsn, 'dsn', $storage); - - if (null !== $expectedUser) { - $this->assertAttributeEquals($expectedUser, 'username', $storage); - } - - if (null !== $expectedPassword) { - $this->assertAttributeEquals($expectedPassword, 'password', $storage); + $reflection = new \ReflectionClass(PdoSessionHandler::class); + + foreach (['dsn' => $expectedDsn, 'username' => $expectedUser, 'password' => $expectedPassword] as $property => $expectedValue) { + if (!isset($expectedValue)) { + continue; + } + $property = $reflection->getProperty($property); + $property->setAccessible(true); + $this->assertSame($expectedValue, $property->getValue($storage)); } } From e42bf5ec53666cf911bcb8119ba5df50f2e4fe61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sun, 4 Aug 2019 18:55:16 +0200 Subject: [PATCH 030/127] Use PHPunit assertion --- Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 348714a26..9daf1a0ee 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -43,7 +43,7 @@ public function testConstructSavePath($savePath, $expectedSavePath, $path) { $handler = new NativeFileSessionHandler($savePath); $this->assertEquals($expectedSavePath, ini_get('session.save_path')); - $this->assertTrue(is_dir(realpath($path))); + $this->assertDirectoryExists(realpath($path)); rmdir($path); } From eca03df7b4d0cff7c35995e657bb211ec5f718e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 5 Aug 2019 16:11:35 +0200 Subject: [PATCH 031/127] Use Phpunit FQDN in tests comments --- Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 7bc84f876..f0f43d05b 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; @@ -22,7 +23,7 @@ class MongoDbSessionHandlerTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ private $mongo; private $storage; From 1bfc779233541e9d5e5245a4258213bdeb59b839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 5 Aug 2019 23:18:16 +0200 Subject: [PATCH 032/127] Use assertEqualsWithDelta when required --- Tests/CookieTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index e382182b4..38c195df3 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -119,7 +119,7 @@ public function testGetExpiresTimeWithStringValue() $cookie = new Cookie('foo', 'bar', $value); $expire = strtotime($value); - $this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date', 1); + $this->assertEqualsWithDelta($expire, $cookie->getExpiresTime(), 1, '->getExpiresTime() returns the expire date'); } public function testGetDomain() From dadec920986892cb7dd445a46159dca44735de23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 6 Aug 2019 00:37:40 +0200 Subject: [PATCH 033/127] Use assertStringContainsString when needed --- Tests/BinaryFileResponseTest.php | 2 +- Tests/RequestTest.php | 6 +++--- Tests/ResponseTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 0bc150e8d..3df96f393 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -261,7 +261,7 @@ public function testXSendfile($file) $this->expectOutputString(''); $response->sendContent(); - $this->assertContains('README.md', $response->headers->get('X-Sendfile')); + $this->assertStringContainsString('README.md', $response->headers->get('X-Sendfile')); } public function provideXSendfileFiles() diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index aaefc0359..396644632 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -1631,14 +1631,14 @@ public function testToString() $asString = (string) $request; - $this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString); - $this->assertContains('Cookie: Foo=Bar', $asString); + $this->assertStringContainsString('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString); + $this->assertStringContainsString('Cookie: Foo=Bar', $asString); $request->cookies->set('Another', 'Cookie'); $asString = (string) $request; - $this->assertContains('Cookie: Foo=Bar; Another=Cookie', $asString); + $this->assertStringContainsString('Cookie: Foo=Bar; Another=Cookie', $asString); } public function testIsMethod() diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 776f85cd0..2858b0a40 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -582,7 +582,7 @@ public function testSetCache() $this->fail('->setCache() throws an InvalidArgumentException if an option is not supported'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '->setCache() throws an InvalidArgumentException if an option is not supported'); - $this->assertContains('"wrong option"', $e->getMessage()); + $this->assertStringContainsString('"wrong option"', $e->getMessage()); } $options = ['etag' => '"whatever"']; @@ -635,7 +635,7 @@ public function testSendContent() ob_start(); $response->sendContent(); $string = ob_get_clean(); - $this->assertContains('test response rendering', $string); + $this->assertStringContainsString('test response rendering', $string); } public function testSetPublic() From 64b07b0f881711af922e31f16d38bd06acb9103a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 6 Aug 2019 07:23:17 +0200 Subject: [PATCH 034/127] removed unneeded phpdocs --- Session/Session.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Session/Session.php b/Session/Session.php index db0b9aeb0..3e0e0f6da 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -31,11 +31,6 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable private $data = []; private $usageIndex = 0; - /** - * @param SessionStorageInterface $storage A SessionStorageInterface instance - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) - */ public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) { $this->storage = $storage ?: new NativeSessionStorage(); From 70055dc0aa71d03ccc7745b030129eb424d3df0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Bla=C5=BEek?= Date: Tue, 6 Aug 2019 10:22:04 +0200 Subject: [PATCH 035/127] Remove deprecated assertContains --- Tests/Test/Constraint/ResponseIsRedirectedTest.php | 2 +- Tests/Test/Constraint/ResponseIsSuccessfulTest.php | 2 +- Tests/Test/Constraint/ResponseStatusCodeSameTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Test/Constraint/ResponseIsRedirectedTest.php b/Tests/Test/Constraint/ResponseIsRedirectedTest.php index a3a460636..a8314c259 100644 --- a/Tests/Test/Constraint/ResponseIsRedirectedTest.php +++ b/Tests/Test/Constraint/ResponseIsRedirectedTest.php @@ -29,7 +29,7 @@ public function testConstraint(): void try { $constraint->evaluate(new Response()); } catch (ExpectationFailedException $e) { - $this->assertContains("Failed asserting that the Response is redirected.\nHTTP/1.0 200 OK", TestFailure::exceptionToString($e)); + $this->assertStringContainsString("Failed asserting that the Response is redirected.\nHTTP/1.0 200 OK", TestFailure::exceptionToString($e)); return; } diff --git a/Tests/Test/Constraint/ResponseIsSuccessfulTest.php b/Tests/Test/Constraint/ResponseIsSuccessfulTest.php index 0c99a5e48..b59daf8a3 100644 --- a/Tests/Test/Constraint/ResponseIsSuccessfulTest.php +++ b/Tests/Test/Constraint/ResponseIsSuccessfulTest.php @@ -29,7 +29,7 @@ public function testConstraint(): void try { $constraint->evaluate(new Response('', 404)); } catch (ExpectationFailedException $e) { - $this->assertContains("Failed asserting that the Response is successful.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e)); + $this->assertStringContainsString("Failed asserting that the Response is successful.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e)); return; } diff --git a/Tests/Test/Constraint/ResponseStatusCodeSameTest.php b/Tests/Test/Constraint/ResponseStatusCodeSameTest.php index 3e15e9067..53200fdd0 100644 --- a/Tests/Test/Constraint/ResponseStatusCodeSameTest.php +++ b/Tests/Test/Constraint/ResponseStatusCodeSameTest.php @@ -31,7 +31,7 @@ public function testConstraint(): void try { $constraint->evaluate(new Response('', 404)); } catch (ExpectationFailedException $e) { - $this->assertContains("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e)); + $this->assertStringContainsString("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e)); return; } From 3c59f90751b047ba1c6abf0bc278ab4a45fc3760 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 6 Aug 2019 17:03:31 +0200 Subject: [PATCH 036/127] Turned return type annotations of private methods into php return types. --- File/UploadedFile.php | 4 +--- Session/Session.php | 4 +--- Session/Storage/Handler/MongoDbSessionHandler.php | 5 +---- Session/Storage/Handler/PdoSessionHandler.php | 14 ++++---------- Session/Storage/MockFileSessionStorage.php | 4 +--- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/File/UploadedFile.php b/File/UploadedFile.php index c33979c8a..91a0525fd 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -251,10 +251,8 @@ public static function getMaxFilesize() /** * Returns the given size from an ini value in bytes. - * - * @return int The given size in bytes */ - private static function parseFilesize($size) + private static function parseFilesize($size): int { if ('' === $size) { return 0; diff --git a/Session/Session.php b/Session/Session.php index 3e0e0f6da..eb1dc2af9 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -267,10 +267,8 @@ public function getFlashBag() * Gets the attributebag interface. * * Note that this method was added to help with IDE autocompletion. - * - * @return AttributeBagInterface */ - private function getAttributeBag() + private function getAttributeBag(): AttributeBagInterface { return $this->getBag($this->attributeName); } diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index 4efaf412a..536c2840e 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -171,10 +171,7 @@ protected function doRead($sessionId) return $dbData[$this->options['data_field']]->getData(); } - /** - * @return \MongoDB\Collection - */ - private function getCollection() + private function getCollection(): \MongoDB\Collection { if (null === $this->collection) { $this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']); diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index f40d9ec60..5c8eb5f5f 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -434,11 +434,9 @@ private function connect(string $dsn) /** * Builds a PDO DSN from a URL-like connection string. * - * @return string - * * @todo implement missing support for oci DSN (which look totally different from other PDO ones) */ - private function buildDsnFromUrl(string $dsnOrUrl) + private function buildDsnFromUrl(string $dsnOrUrl): string { // (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid $url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $dsnOrUrl); @@ -672,7 +670,7 @@ protected function doRead($sessionId) * - for oci using DBMS_LOCK.REQUEST * - for sqlsrv using sp_getapplock with LockOwner = Session */ - private function doAdvisoryLock(string $sessionId) + private function doAdvisoryLock(string $sessionId): \PDOStatement { switch ($this->driver) { case 'mysql': @@ -770,10 +768,8 @@ private function getSelectSql(): string /** * Returns an insert statement supported by the database for writing session data. - * - * @return \PDOStatement The insert statement */ - private function getInsertStatement(string $sessionId, string $sessionData, int $maxlifetime) + private function getInsertStatement(string $sessionId, string $sessionData, int $maxlifetime): \PDOStatement { switch ($this->driver) { case 'oci': @@ -799,10 +795,8 @@ private function getInsertStatement(string $sessionId, string $sessionData, int /** * Returns an update statement supported by the database for writing session data. - * - * @return \PDOStatement The update statement */ - private function getUpdateStatement(string $sessionId, string $sessionData, int $maxlifetime) + private function getUpdateStatement(string $sessionId, string $sessionData, int $maxlifetime): \PDOStatement { switch ($this->driver) { case 'oci': diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index c0316c2c7..b0996abc5 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -131,10 +131,8 @@ private function destroy() /** * Calculate path to file. - * - * @return string File path */ - private function getFilePath() + private function getFilePath(): string { return $this->savePath.'/'.$this->id.'.mocksess'; } From 872ba43ec852cc071e8f7a0ce7cb97141bebbc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 8 Aug 2019 11:17:10 +0200 Subject: [PATCH 037/127] Disable phpunit typehint patch on 4.3 branch --- Tests/BinaryFileResponseTest.php | 2 +- Tests/File/MimeType/MimeTypeTest.php | 2 +- Tests/File/UploadedFileTest.php | 2 +- Tests/FileBagTest.php | 4 ++-- Tests/RequestTest.php | 2 +- Tests/ResponseFunctionalTest.php | 4 ++-- Tests/Session/Attribute/AttributeBagTest.php | 4 ++-- Tests/Session/Attribute/NamespacedAttributeBagTest.php | 4 ++-- Tests/Session/Flash/AutoExpireFlashBagTest.php | 4 ++-- Tests/Session/Flash/FlashBagTest.php | 4 ++-- Tests/Session/SessionTest.php | 4 ++-- .../Storage/Handler/AbstractRedisSessionHandlerTestCase.php | 4 ++-- Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php | 4 ++-- Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php | 4 ++-- Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php | 2 +- Tests/Session/Storage/Handler/PdoSessionHandlerTest.php | 2 +- Tests/Session/Storage/MetadataBagTest.php | 4 ++-- Tests/Session/Storage/MockArraySessionStorageTest.php | 4 ++-- Tests/Session/Storage/MockFileSessionStorageTest.php | 4 ++-- Tests/Session/Storage/NativeSessionStorageTest.php | 4 ++-- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 4 ++-- Tests/Session/Storage/Proxy/AbstractProxyTest.php | 4 ++-- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 4 ++-- 23 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index ab527b699..b90144809 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -355,7 +355,7 @@ protected function provideResponse() return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index f990a4f3b..a43ce819f 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -78,7 +78,7 @@ public function testGuessWithNonReadablePath() } } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { $path = __DIR__.'/../Fixtures/to_delete'; if (file_exists($path)) { diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index dbe875ea8..0662c0e77 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -24,7 +24,7 @@ class UploadedFileTest extends TestCase { - protected function setUp() + protected function setUp(): void { if (!ini_get('file_uploads')) { $this->markTestSkipped('file_uploads is disabled in php.ini'); diff --git a/Tests/FileBagTest.php b/Tests/FileBagTest.php index 041f57fe8..bde664194 100644 --- a/Tests/FileBagTest.php +++ b/Tests/FileBagTest.php @@ -160,12 +160,12 @@ protected function createTempFile() return $tempFile; } - protected function setUp() + protected function setUp(): void { mkdir(sys_get_temp_dir().'/form_test', 0777, true); } - protected function tearDown() + protected function tearDown(): void { foreach (glob(sys_get_temp_dir().'/form_test/*') as $file) { unlink($file); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 414868925..d933432c4 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -19,7 +19,7 @@ class RequestTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { Request::setTrustedProxies([], -1); Request::setTrustedHosts([]); diff --git a/Tests/ResponseFunctionalTest.php b/Tests/ResponseFunctionalTest.php index 3d3e696c7..21a66bbf8 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -20,7 +20,7 @@ class ResponseFunctionalTest extends TestCase { private static $server; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -32,7 +32,7 @@ public static function setUpBeforeClass() sleep(1); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/Session/Attribute/AttributeBagTest.php b/Tests/Session/Attribute/AttributeBagTest.php index 44c8174e3..6313967af 100644 --- a/Tests/Session/Attribute/AttributeBagTest.php +++ b/Tests/Session/Attribute/AttributeBagTest.php @@ -28,7 +28,7 @@ class AttributeBagTest extends TestCase */ private $bag; - protected function setUp() + protected function setUp(): void { $this->array = [ 'hello' => 'world', @@ -49,7 +49,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + protected function tearDown(): void { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Attribute/NamespacedAttributeBagTest.php b/Tests/Session/Attribute/NamespacedAttributeBagTest.php index 6b4bb17d6..3a3251d05 100644 --- a/Tests/Session/Attribute/NamespacedAttributeBagTest.php +++ b/Tests/Session/Attribute/NamespacedAttributeBagTest.php @@ -28,7 +28,7 @@ class NamespacedAttributeBagTest extends TestCase */ private $bag; - protected function setUp() + protected function setUp(): void { $this->array = [ 'hello' => 'world', @@ -49,7 +49,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + protected function tearDown(): void { $this->bag = null; $this->array = []; diff --git a/Tests/Session/Flash/AutoExpireFlashBagTest.php b/Tests/Session/Flash/AutoExpireFlashBagTest.php index b4e2c3a5a..ba2687199 100644 --- a/Tests/Session/Flash/AutoExpireFlashBagTest.php +++ b/Tests/Session/Flash/AutoExpireFlashBagTest.php @@ -28,7 +28,7 @@ class AutoExpireFlashBagTest extends TestCase protected $array = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->bag = new FlashBag(); @@ -36,7 +36,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + protected function tearDown(): void { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/Flash/FlashBagTest.php b/Tests/Session/Flash/FlashBagTest.php index 6d8619e07..24dbbfe98 100644 --- a/Tests/Session/Flash/FlashBagTest.php +++ b/Tests/Session/Flash/FlashBagTest.php @@ -28,7 +28,7 @@ class FlashBagTest extends TestCase protected $array = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->bag = new FlashBag(); @@ -36,7 +36,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + protected function tearDown(): void { $this->bag = null; parent::tearDown(); diff --git a/Tests/Session/SessionTest.php b/Tests/Session/SessionTest.php index acb129984..e216bfc8c 100644 --- a/Tests/Session/SessionTest.php +++ b/Tests/Session/SessionTest.php @@ -37,13 +37,13 @@ class SessionTest extends TestCase */ protected $session; - protected function setUp() + protected function setUp(): void { $this->storage = new MockArraySessionStorage(); $this->session = new Session($this->storage, new AttributeBag(), new FlashBag()); } - protected function tearDown() + protected function tearDown(): void { $this->storage = null; $this->session = null; diff --git a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php index c0651498f..6a15a0687 100644 --- a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php +++ b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php @@ -37,7 +37,7 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase */ abstract protected function createRedisClient(string $host); - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -54,7 +54,7 @@ protected function setUp() ); } - protected function tearDown() + protected function tearDown(): void { $this->redisClient = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php index f65e62b50..b25b68bbb 100644 --- a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php @@ -17,7 +17,7 @@ class AbstractSessionHandlerTest extends TestCase { private static $server; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $spec = [ 1 => ['file', '/dev/null', 'w'], @@ -29,7 +29,7 @@ public static function setUpBeforeClass() sleep(1); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { if (self::$server) { proc_terminate(self::$server); diff --git a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index 2393ddf18..e9c17703a 100644 --- a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -30,7 +30,7 @@ class MemcachedSessionHandlerTest extends TestCase protected $memcached; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -45,7 +45,7 @@ protected function setUp() ); } - protected function tearDown() + protected function tearDown(): void { $this->memcached = null; $this->storage = null; diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 455066676..f956fa276 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -29,7 +29,7 @@ class MongoDbSessionHandlerTest extends TestCase private $storage; public $options; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 6d1b65044..d080ce3ca 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -22,7 +22,7 @@ class PdoSessionHandlerTest extends TestCase { private $dbFile; - protected function tearDown() + protected function tearDown(): void { // make sure the temporary database file is deleted when it has been created (even when a test fails) if ($this->dbFile) { diff --git a/Tests/Session/Storage/MetadataBagTest.php b/Tests/Session/Storage/MetadataBagTest.php index 2c4758b91..e040f4862 100644 --- a/Tests/Session/Storage/MetadataBagTest.php +++ b/Tests/Session/Storage/MetadataBagTest.php @@ -28,7 +28,7 @@ class MetadataBagTest extends TestCase protected $array = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->bag = new MetadataBag(); @@ -36,7 +36,7 @@ protected function setUp() $this->bag->initialize($this->array); } - protected function tearDown() + protected function tearDown(): void { $this->array = []; $this->bag = null; diff --git a/Tests/Session/Storage/MockArraySessionStorageTest.php b/Tests/Session/Storage/MockArraySessionStorageTest.php index 7e0d303b9..b99e71985 100644 --- a/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -40,7 +40,7 @@ class MockArraySessionStorageTest extends TestCase private $data; - protected function setUp() + protected function setUp(): void { $this->attributes = new AttributeBag(); $this->flashes = new FlashBag(); @@ -56,7 +56,7 @@ protected function setUp() $this->storage->setSessionData($this->data); } - protected function tearDown() + protected function tearDown(): void { $this->data = null; $this->flashes = null; diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index 5d2fda84a..d9314075a 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -33,13 +33,13 @@ class MockFileSessionStorageTest extends TestCase */ protected $storage; - protected function setUp() + protected function setUp(): void { $this->sessionDir = sys_get_temp_dir().'/sftest'; $this->storage = $this->getStorage(); } - protected function tearDown() + protected function tearDown(): void { $this->sessionDir = null; $this->storage = null; diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 8b0072717..17f46bef5 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -33,7 +33,7 @@ class NativeSessionStorageTest extends TestCase { private $savePath; - protected function setUp() + protected function setUp(): void { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); @@ -42,7 +42,7 @@ protected function setUp() } } - protected function tearDown() + protected function tearDown(): void { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 433240024..7d6827079 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -29,7 +29,7 @@ class PhpBridgeSessionStorageTest extends TestCase { private $savePath; - protected function setUp() + protected function setUp(): void { $this->iniSet('session.save_handler', 'files'); $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); @@ -38,7 +38,7 @@ protected function setUp() } } - protected function tearDown() + protected function tearDown(): void { session_write_close(); array_map('unlink', glob($this->savePath.'/*')); diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index ae40f2c29..4820a6593 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -27,12 +27,12 @@ class AbstractProxyTest extends TestCase */ protected $proxy; - protected function setUp() + protected function setUp(): void { $this->proxy = $this->getMockForAbstractClass(AbstractProxy::class); } - protected function tearDown() + protected function tearDown(): void { $this->proxy = null; } diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index ec9029c7d..540d58a27 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -34,13 +34,13 @@ class SessionHandlerProxyTest extends TestCase */ private $proxy; - protected function setUp() + protected function setUp(): void { $this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $this->proxy = new SessionHandlerProxy($this->mock); } - protected function tearDown() + protected function tearDown(): void { $this->mock = null; $this->proxy = null; From 1e64c83e8b5395e7a9beef8833ff99f904d664dd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 7 Aug 2019 17:24:11 +0200 Subject: [PATCH 038/127] Remove unneeded phpdocs --- Request.php | 5 ----- Session/Storage/MockFileSessionStorage.php | 5 ++--- Session/Storage/NativeSessionStorage.php | 1 - Session/Storage/PhpBridgeSessionStorage.php | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Request.php b/Request.php index 089793ed3..21f865215 100644 --- a/Request.php +++ b/Request.php @@ -745,11 +745,6 @@ public function hasSession() return null !== $this->session; } - /** - * Sets the Session. - * - * @param SessionInterface $session The Session - */ public function setSession(SessionInterface $session) { $this->session = $session; diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index b0996abc5..7916fa819 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -27,9 +27,8 @@ class MockFileSessionStorage extends MockArraySessionStorage private $savePath; /** - * @param string $savePath Path of directory to save session files - * @param string $name Session name - * @param MetadataBag $metaBag MetadataBag instance + * @param string $savePath Path of directory to save session files + * @param string $name Session name */ public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null) { diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 9e03bfa41..297b114a0 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -99,7 +99,6 @@ class NativeSessionStorage implements SessionStorageInterface * * @param array $options Session configuration options * @param \SessionHandlerInterface|null $handler - * @param MetadataBag $metaBag MetadataBag */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) { diff --git a/Session/Storage/PhpBridgeSessionStorage.php b/Session/Storage/PhpBridgeSessionStorage.php index 8969e609a..f0fac5843 100644 --- a/Session/Storage/PhpBridgeSessionStorage.php +++ b/Session/Storage/PhpBridgeSessionStorage.php @@ -20,7 +20,6 @@ class PhpBridgeSessionStorage extends NativeSessionStorage { /** * @param \SessionHandlerInterface|null $handler - * @param MetadataBag $metaBag MetadataBag */ public function __construct($handler = null, MetadataBag $metaBag = null) { From 65775d28568174fd4b8bd44c58f0e1cdd0dcd787 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 8 Aug 2019 16:01:55 +0200 Subject: [PATCH 039/127] cleanup remaining param and internal Intl FulLTransformer --- Session/Storage/Handler/MemcachedSessionHandler.php | 1 - Session/Storage/Handler/MongoDbSessionHandler.php | 3 --- Session/Storage/Handler/PdoSessionHandler.php | 1 - Session/Storage/Handler/RedisSessionHandler.php | 1 - Session/Storage/NativeSessionStorage.php | 1 - 5 files changed, 7 deletions(-) diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 1db590b36..bcaeef978 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -41,7 +41,6 @@ class MemcachedSessionHandler extends AbstractSessionHandler * * expiretime: The time to live in seconds. * * @param \Memcached $memcached A \Memcached instance - * @param array $options An associative array of Memcached options * * @throws \InvalidArgumentException When unsupported options are passed */ diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index 536c2840e..fd8f05a22 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -61,9 +61,6 @@ class MongoDbSessionHandler extends AbstractSessionHandler * If you use such an index, you can drop `gc_probability` to 0 since * no garbage-collection is required. * - * @param \MongoDB\Client $mongo A MongoDB\Client instance - * @param array $options An associative array of field options - * * @throws \InvalidArgumentException When "database" or "collection" not provided */ public function __construct(\MongoDB\Client $mongo, array $options) diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 5c8eb5f5f..4e044c69b 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -165,7 +165,6 @@ class PdoSessionHandler extends AbstractSessionHandler * * lock_mode: The strategy for locking, see constants [default: LOCK_TRANSACTIONAL] * * @param \PDO|string|null $pdoOrDsn A \PDO instance or DSN string or URL string or null - * @param array $options An associative array of options * * @throws \InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION */ diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index a6498b882..c2e7d34dc 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -35,7 +35,6 @@ class RedisSessionHandler extends AbstractSessionHandler * * prefix: The prefix to use for the keys in order to avoid collision on the Redis server. * * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client|RedisProxy $redis - * @param array $options An associative array of options * * @throws \InvalidArgumentException When unsupported client or options are passed */ diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 297b114a0..98b3199e9 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -97,7 +97,6 @@ class NativeSessionStorage implements SessionStorageInterface * trans_sid_hosts, $_SERVER['HTTP_HOST'] * trans_sid_tags, "a=href,area=href,frame=src,form=" * - * @param array $options Session configuration options * @param \SessionHandlerInterface|null $handler */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) From ae752d690759f8873349915ccf806ffe23c56d3f Mon Sep 17 00:00:00 2001 From: Arman Hosseini <44655055+Arman-Hosseini@users.noreply.github.com> Date: Mon, 29 Jul 2019 21:55:29 +0430 Subject: [PATCH 040/127] Improve some URLs --- CHANGELOG.md | 2 +- File/MimeType/FileinfoMimeTypeGuesser.php | 2 +- JsonResponse.php | 2 +- ParameterBag.php | 2 +- RedirectResponse.php | 2 +- Request.php | 10 +++++----- Response.php | 6 +++--- ServerBag.php | 2 +- .../Storage/Handler/MemcachedSessionHandler.php | 2 +- Session/Storage/Handler/MongoDbSessionHandler.php | 2 +- .../Storage/Handler/NativeFileSessionHandler.php | 2 +- Session/Storage/Handler/NativeSessionHandler.php | 2 +- Session/Storage/Handler/PdoSessionHandler.php | 8 ++++---- Session/Storage/NativeSessionStorage.php | 14 +++++++------- Session/Storage/SessionStorageInterface.php | 2 +- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bfde80ff..c0d890167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ CHANGELOG ----- * the `Request::setTrustedProxies()` method takes a new `$trustedHeaderSet` argument, - see http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info, + see https://symfony.com/doc/current/deployment/proxies.html for more info, * deprecated the `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()` methods, * added `File\Stream`, to be passed to `BinaryFileResponse` when the size of the served file is unknown, disabling `Range` and `Content-Length` handling, switching to chunked encoding instead diff --git a/File/MimeType/FileinfoMimeTypeGuesser.php b/File/MimeType/FileinfoMimeTypeGuesser.php index bf1ee9f5d..62feda2ee 100644 --- a/File/MimeType/FileinfoMimeTypeGuesser.php +++ b/File/MimeType/FileinfoMimeTypeGuesser.php @@ -26,7 +26,7 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface /** * @param string $magicFile A magic file to use with the finfo instance * - * @see http://www.php.net/manual/en/function.finfo-open.php + * @see https://php.net/finfo-open */ public function __construct($magicFile = null) { diff --git a/JsonResponse.php b/JsonResponse.php index a9bdac30f..b0e765167 100644 --- a/JsonResponse.php +++ b/JsonResponse.php @@ -100,7 +100,7 @@ public static function fromJsonString($data = null, $status = 200, $headers = [] public function setCallback($callback = null) { if (null !== $callback) { - // partially taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/ + // partially taken from https://geekality.net/2011/08/03/valid-javascript-identifier/ // partially taken from https://github.com/willdurand/JsonpCallbackValidator // JsonpCallbackValidator is released under the MIT License. See https://github.com/willdurand/JsonpCallbackValidator/blob/v1.1.0/LICENSE for details. // (c) William Durand diff --git a/ParameterBag.php b/ParameterBag.php index f05e4a215..194ba2c6c 100644 --- a/ParameterBag.php +++ b/ParameterBag.php @@ -191,7 +191,7 @@ public function getBoolean($key, $default = false) * @param int $filter FILTER_* constant * @param mixed $options Filter options * - * @see http://php.net/manual/en/function.filter-var.php + * @see https://php.net/filter-var * * @return mixed */ diff --git a/RedirectResponse.php b/RedirectResponse.php index 51fd869ab..4e3cb4f77 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -30,7 +30,7 @@ class RedirectResponse extends Response * * @throws \InvalidArgumentException * - * @see http://tools.ietf.org/html/rfc2616#section-10.3 + * @see https://tools.ietf.org/html/rfc2616#section-10.3 */ public function __construct($url, $status = 302, $headers = []) { diff --git a/Request.php b/Request.php index 7185d75e9..2dd250b80 100644 --- a/Request.php +++ b/Request.php @@ -915,7 +915,7 @@ public function getClientIps() * @return string|null The client IP address * * @see getClientIps() - * @see http://en.wikipedia.org/wiki/X-Forwarded-For + * @see https://wikipedia.org/wiki/X-Forwarded-For */ public function getClientIp() { @@ -1204,7 +1204,7 @@ public function getRelativeUriForPath($path) // A reference to the same base directory or an empty subdirectory must be prefixed with "./". // This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used // as the first segment of a relative-path reference, as it would be mistaken for a scheme name - // (see http://tools.ietf.org/html/rfc3986#section-4.2). + // (see https://tools.ietf.org/html/rfc3986#section-4.2). return !isset($path[0]) || '/' === $path[0] || false !== ($colonPos = strpos($path, ':')) && ($colonPos < ($slashPos = strpos($path, '/')) || false === $slashPos) ? "./$path" : $path; @@ -1823,7 +1823,7 @@ public function getAcceptableContentTypes() * It works if your JavaScript library sets an X-Requested-With HTTP header. * It is known to work with common JavaScript frameworks: * - * @see http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript + * @see https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript * * @return bool true if the request is an XMLHttpRequest, false otherwise */ @@ -1835,9 +1835,9 @@ public function isXmlHttpRequest() /* * The following methods are derived from code of the Zend Framework (1.10dev - 2010-01-24) * - * Code subject to the new BSD license (http://framework.zend.com/license/new-bsd). + * Code subject to the new BSD license (https://framework.zend.com/license). * - * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * Copyright (c) 2005-2010 Zend Technologies USA Inc. (https://www.zend.com/) */ protected function prepareRequestUri() diff --git a/Response.php b/Response.php index 4ab05066f..47dae9534 100644 --- a/Response.php +++ b/Response.php @@ -121,7 +121,7 @@ class Response * Status codes translation table. * * The list of codes is complete according to the - * {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry} + * {@link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry} * (last updated 2016-03-01). * * Unless otherwise noted, the status code is defined in RFC2616. @@ -1025,7 +1025,7 @@ public function setCache(array $options) * * @return $this * - * @see http://tools.ietf.org/html/rfc2616#section-10.3.5 + * @see https://tools.ietf.org/html/rfc2616#section-10.3.5 * * @final since version 3.3 */ @@ -1133,7 +1133,7 @@ public function isNotModified(Request $request) * * @return bool * - * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html * * @final since version 3.2 */ diff --git a/ServerBag.php b/ServerBag.php index 90da49fae..4c82b1774 100644 --- a/ServerBag.php +++ b/ServerBag.php @@ -79,7 +79,7 @@ public function getHeaders() /* * XXX: Since there is no PHP_AUTH_BEARER in PHP predefined variables, * I'll just set $headers['AUTHORIZATION'] here. - * http://php.net/manual/en/reserved.variables.server.php + * https://php.net/reserved.variables.server */ $headers['AUTHORIZATION'] = $authorizationHeader; } diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 1db590b36..8965c089c 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -15,7 +15,7 @@ * Memcached based session storage handler based on the Memcached class * provided by the PHP memcached extension. * - * @see http://php.net/memcached + * @see https://php.net/memcached * * @author Drak */ diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index ddedacffb..1dd724066 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -56,7 +56,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler * { "expireAfterSeconds": 0 } * ) * - * More details on: http://docs.mongodb.org/manual/tutorial/expire-data/ + * More details on: https://docs.mongodb.org/manual/tutorial/expire-data/ * * If you use such an index, you can drop `gc_probability` to 0 since * no garbage-collection is required. diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index 04bcbbfe3..8b7615ec1 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -23,7 +23,7 @@ class NativeFileSessionHandler extends NativeSessionHandler * Default null will leave setting as defined by PHP. * '/path', 'N;/path', or 'N;octal-mode;/path * - * @see https://php.net/manual/session.configuration.php#ini.session.save-path for further details. + * @see https://php.net/session.configuration#ini.session.save-path for further details. * * @throws \InvalidArgumentException On invalid $savePath * @throws \RuntimeException When failing to create the save directory diff --git a/Session/Storage/Handler/NativeSessionHandler.php b/Session/Storage/Handler/NativeSessionHandler.php index 9be4528ae..5159b1e35 100644 --- a/Session/Storage/Handler/NativeSessionHandler.php +++ b/Session/Storage/Handler/NativeSessionHandler.php @@ -13,7 +13,7 @@ /** * @deprecated since version 3.4, to be removed in 4.0. Use \SessionHandler instead. - * @see http://php.net/sessionhandler + * @see https://php.net/sessionhandler */ class NativeSessionHandler extends \SessionHandler { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 9369740eb..9a50377bc 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -32,7 +32,7 @@ * Saving it in a character column could corrupt the data. You can use createTable() * to initialize a correctly defined table. * - * @see http://php.net/sessionhandlerinterface + * @see https://php.net/sessionhandlerinterface * * @author Fabien Potencier * @author Michael Williams @@ -538,7 +538,7 @@ private function buildDsnFromUrl($dsnOrUrl) * PDO::rollback or PDO::inTransaction for SQLite. * * Also MySQLs default isolation, REPEATABLE READ, causes deadlock for different sessions - * due to http://www.mysqlperformanceblog.com/2013/12/12/one-more-innodb-gap-lock-to-avoid/ . + * due to https://percona.com/blog/2013/12/12/one-more-innodb-gap-lock-to-avoid/ . * So we change it to READ COMMITTED. */ private function beginTransaction() @@ -864,7 +864,7 @@ private function getMergeStatement($sessionId, $data, $maxlifetime) break; case 'sqlsrv' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '10', '>='): // MERGE is only available since SQL Server 2008 and must be terminated by semicolon - // It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx + // It also requires HOLDLOCK according to https://weblogs.sqlteam.com/dang/2009/01/31/upsert-race-condition-with-merge/ $mergeSql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ". "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ". "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;"; @@ -877,7 +877,7 @@ private function getMergeStatement($sessionId, $data, $maxlifetime) "ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)"; break; default: - // MERGE is not supported with LOBs: http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html + // MERGE is not supported with LOBs: https://oracle.com/technetwork/articles/fuecks-lobs-095315.html return null; } diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 809d7002c..4f1c30ef5 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -54,7 +54,7 @@ class NativeSessionStorage implements SessionStorageInterface * * List of options for $options array with their defaults. * - * @see http://php.net/session.configuration for options + * @see https://php.net/session.configuration for options * but we omit 'session.' from the beginning of the keys for convenience. * * ("auto_start", is not supported as it tells PHP to start a session before @@ -212,7 +212,7 @@ public function regenerate($destroy = false, $lifetime = null) $isRegenerated = session_regenerate_id($destroy); // The reference to $_SESSION in session bags is lost in PHP7 and we need to re-create it. - // @see https://bugs.php.net/bug.php?id=70013 + // @see https://bugs.php.net/70013 $this->loadSession(); return $isRegenerated; @@ -337,7 +337,7 @@ public function isStarted() * * @param array $options Session ini directives [key => value] * - * @see http://php.net/session.configuration + * @see https://php.net/session.configuration */ public function setOptions(array $options) { @@ -378,10 +378,10 @@ public function setOptions(array $options) * constructor, for a template see NativeFileSessionHandler or use handlers in * composer package drak/native-session * - * @see http://php.net/session-set-save-handler - * @see http://php.net/sessionhandlerinterface - * @see http://php.net/sessionhandler - * @see http://github.com/drak/NativeSession + * @see https://php.net/session-set-save-handler + * @see https://php.net/sessionhandlerinterface + * @see https://php.net/sessionhandler + * @see https://github.com/zikula/NativeSession * * @param \SessionHandlerInterface|null $saveHandler * diff --git a/Session/Storage/SessionStorageInterface.php b/Session/Storage/SessionStorageInterface.php index 66e8b33dd..eeb396a2f 100644 --- a/Session/Storage/SessionStorageInterface.php +++ b/Session/Storage/SessionStorageInterface.php @@ -77,7 +77,7 @@ public function setName($name); * only delete the session data from persistent storage. * * Care: When regenerating the session ID no locking is involved in PHP's - * session design. See https://bugs.php.net/bug.php?id=61470 for a discussion. + * session design. See https://bugs.php.net/61470 for a discussion. * So you must make sure the regenerated session is saved BEFORE sending the * headers with the new ID. Symfony's HttpKernel offers a listener for this. * See Symfony\Component\HttpKernel\EventListener\SaveSessionListener. From 8cfd6583ab0685847807c6883cc660f2c943b8c0 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Thu, 20 Jun 2019 21:59:08 +0200 Subject: [PATCH 041/127] [HttpFoundation] deprecate using $first in get and added key in all --- CHANGELOG.md | 1 + HeaderBag.php | 35 +++++++++++++------------- Response.php | 2 +- ResponseHeaderBag.php | 11 +++++++- Test/Constraint/ResponseHeaderSame.php | 2 +- Tests/HeaderBagTest.php | 18 ++++++++++--- Tests/ResponseHeaderBagTest.php | 6 ++--- 7 files changed, 48 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e06e678..4828df888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * passing arguments to `Request::isMethodSafe()` is deprecated. * `ApacheRequest` is deprecated, use the `Request` class instead. + * passing a third argument to `HeaderBag::get()` is deprecated, use method `all()` instead 4.3.0 ----- diff --git a/HeaderBag.php b/HeaderBag.php index fa9d17313..ef549f3c3 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -58,10 +58,18 @@ public function __toString() /** * Returns the headers. * + * @param string|null $key The name of the headers to return or null to get them all + * * @return array An array of headers */ - public function all() + public function all(/*string $key = null*/) { + if (1 <= \func_num_args() && null !== $key = func_get_arg(0)) { + $key = str_replace('_', '-', strtolower($key)); + + return $this->headers[$key] ?? []; + } + return $this->headers; } @@ -103,28 +111,21 @@ public function add(array $headers) * * @param string $key The header name * @param string|null $default The default value - * @param bool $first Whether to return the first value or all header values * - * @return string|string[]|null The first header value or default value if $first is true, an array of values otherwise + * @return string|null The first header value or default value */ - public function get($key, $default = null, $first = true) + public function get($key, $default = null) { - $key = str_replace('_', '-', strtolower($key)); - $headers = $this->all(); + $headers = $this->all((string) $key); + if (2 < \func_num_args()) { + @trigger_error(sprintf('Passing a third argument to "%s()" is deprecated since Symfony 4.4, use method "all()" instead', __METHOD__), E_USER_DEPRECATED); - if (!\array_key_exists($key, $headers)) { - if (null === $default) { - return $first ? null : []; + if (!func_get_arg(2)) { + return $headers; } - - return $first ? $default : [$default]; - } - - if ($first) { - return \count($headers[$key]) ? $headers[$key][0] : $default; } - return $headers[$key]; + return $headers[0] ?? $default; } /** @@ -181,7 +182,7 @@ public function has($key) */ public function contains($key, $value) { - return \in_array($value, $this->get($key, null, false)); + return \in_array($value, $this->all((string) $key)); } /** diff --git a/Response.php b/Response.php index 168155849..fa5682cbd 100644 --- a/Response.php +++ b/Response.php @@ -1024,7 +1024,7 @@ public function hasVary(): bool */ public function getVary(): array { - if (!$vary = $this->headers->get('Vary', null, false)) { + if (!$vary = $this->headers->all('Vary')) { return []; } diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index cf44d0ece..0cfc6f6ac 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -87,10 +87,19 @@ public function replace(array $headers = []) /** * {@inheritdoc} + * + * @param string|null $key The name of the headers to return or null to get them all */ - public function all() + public function all(/*string $key = null*/) { $headers = parent::all(); + + if (1 <= \func_num_args() && null !== $key = func_get_arg(0)) { + $key = str_replace('_', '-', strtolower($key)); + + return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies()); + } + foreach ($this->getCookies() as $cookie) { $headers['set-cookie'][] = (string) $cookie; } diff --git a/Test/Constraint/ResponseHeaderSame.php b/Test/Constraint/ResponseHeaderSame.php index acdea71d1..a27d0c73f 100644 --- a/Test/Constraint/ResponseHeaderSame.php +++ b/Test/Constraint/ResponseHeaderSame.php @@ -40,7 +40,7 @@ public function toString(): string */ protected function matches($response): bool { - return $this->expectedValue === $response->headers->get($this->headerName, null, true); + return $this->expectedValue === $response->headers->get($this->headerName, null); } /** diff --git a/Tests/HeaderBagTest.php b/Tests/HeaderBagTest.php index 6c4915f2e..4c8fe8d3e 100644 --- a/Tests/HeaderBagTest.php +++ b/Tests/HeaderBagTest.php @@ -88,16 +88,26 @@ public function testGet() $bag = new HeaderBag(['foo' => 'bar', 'fuzz' => 'bizz']); $this->assertEquals('bar', $bag->get('foo'), '->get return current value'); $this->assertEquals('bar', $bag->get('FoO'), '->get key in case insensitive'); - $this->assertEquals(['bar'], $bag->get('foo', 'nope', false), '->get return the value as array'); + $this->assertEquals(['bar'], $bag->all('foo'), '->get return the value as array'); // defaults $this->assertNull($bag->get('none'), '->get unknown values returns null'); $this->assertEquals('default', $bag->get('none', 'default'), '->get unknown values returns default'); - $this->assertEquals(['default'], $bag->get('none', 'default', false), '->get unknown values returns default as array'); + $this->assertEquals([], $bag->all('none'), '->get unknown values returns an empty array'); $bag->set('foo', 'bor', false); $this->assertEquals('bar', $bag->get('foo'), '->get return first value'); - $this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array'); + $this->assertEquals(['bar', 'bor'], $bag->all('foo'), '->get return all values as array'); + } + + /** + * @group legacy + * @expectedDeprecation Passing a third argument to "Symfony\Component\HttpFoundation\HeaderBag::get()" is deprecated since Symfony 4.4, use method "all()" instead + */ + public function testGetIsEqualToNewMethod() + { + $bag = new HeaderBag(['foo' => 'bar', 'fuzz' => 'bizz']); + $this->assertSame($bag->all('none'), $bag->get('none', [], false), '->get unknown values returns default as array'); } public function testSetAssociativeArray() @@ -105,7 +115,7 @@ public function testSetAssociativeArray() $bag = new HeaderBag(); $bag->set('foo', ['bad-assoc-index' => 'value']); $this->assertSame('value', $bag->get('foo')); - $this->assertEquals(['value'], $bag->get('foo', 'nope', false), 'assoc indices of multi-valued headers are ignored'); + $this->assertSame(['value'], $bag->all('foo'), 'assoc indices of multi-valued headers are ignored'); } public function testContains() diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index 35df36c1c..72cddfcae 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -89,13 +89,13 @@ public function testCacheControlHeader() $bag = new ResponseHeaderBag(); $bag->set('Cache-Control', ['public', 'must-revalidate']); - $this->assertCount(1, $bag->get('Cache-Control', null, false)); + $this->assertCount(1, $bag->all('Cache-Control')); $this->assertEquals('must-revalidate, public', $bag->get('Cache-Control')); $bag = new ResponseHeaderBag(); $bag->set('Cache-Control', 'public'); $bag->set('Cache-Control', 'must-revalidate', false); - $this->assertCount(1, $bag->get('Cache-Control', null, false)); + $this->assertCount(1, $bag->all('Cache-Control')); $this->assertEquals('must-revalidate, public', $bag->get('Cache-Control')); } @@ -166,7 +166,7 @@ public function testCookiesWithSameNames() 'foo=bar; path=/path/bar; domain=foo.bar; httponly; samesite=lax', 'foo=bar; path=/path/bar; domain=bar.foo; httponly; samesite=lax', 'foo=bar; path=/; httponly; samesite=lax', - ], $bag->get('set-cookie', null, false)); + ], $bag->all('set-cookie')); $this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly; samesite=lax', $bag); $this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly; samesite=lax', $bag); From 8235d3ace62276b1ede9c99c6b78ec1f420be773 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Tue, 9 Jul 2019 10:49:00 +0200 Subject: [PATCH 042/127] [HttpFoundation] Clear invalid session cookie --- Session/Storage/Handler/AbstractSessionHandler.php | 10 +++++++++- Session/Storage/NativeSessionStorage.php | 7 ++++++- .../Session/Storage/Handler/Fixtures/storage.expected | 3 ++- .../Handler/Fixtures/with_cookie_and_session.expected | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index defca606e..78340efbd 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -124,7 +124,15 @@ public function destroy($sessionId) throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this))); } $cookie = SessionUtils::popSessionCookie($this->sessionName, $sessionId); - if (null === $cookie) { + + /* + * We send an invalidation Set-Cookie header (zero lifetime) + * when either the session was started or a cookie with + * the session name was sent by the client (in which case + * we know it's invalid as a valid session cookie would've + * started the session). + */ + if (null === $cookie || isset($_COOKIE[$this->sessionName])) { if (\PHP_VERSION_ID < 70300) { setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN)); } else { diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 9de3dea87..5bdf5e2ac 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -241,6 +241,7 @@ public function regenerate($destroy = false, $lifetime = null) */ public function save() { + // Store a copy so we can restore the bags in case the session was not left empty $session = $_SESSION; foreach ($this->bags as $bag) { @@ -266,7 +267,11 @@ public function save() session_write_close(); } finally { restore_error_handler(); - $_SESSION = $session; + + // Restore only if not empty + if ($_SESSION) { + $_SESSION = $session; + } } $this->closed = true; diff --git a/Tests/Session/Storage/Handler/Fixtures/storage.expected b/Tests/Session/Storage/Handler/Fixtures/storage.expected index 4533a10a1..05a5d5d0b 100644 --- a/Tests/Session/Storage/Handler/Fixtures/storage.expected +++ b/Tests/Session/Storage/Handler/Fixtures/storage.expected @@ -11,10 +11,11 @@ $_SESSION is not empty write destroy close -$_SESSION is not empty +$_SESSION is empty Array ( [0] => Content-Type: text/plain; charset=utf-8 [1] => Cache-Control: max-age=0, private, must-revalidate + [2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly ) shutdown diff --git a/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected b/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected index 5de2d9e39..63078228d 100644 --- a/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected +++ b/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected @@ -20,5 +20,6 @@ Array [0] => Content-Type: text/plain; charset=utf-8 [1] => Cache-Control: max-age=10800, private, must-revalidate [2] => Set-Cookie: abc=def + [3] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly ) shutdown From 1000881e7ac0eaac01ea74b881d869618fec7499 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 10 Aug 2019 22:41:30 +0200 Subject: [PATCH 043/127] cleanups --- Tests/RequestTest.php | 1 - Tests/ResponseTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 396644632..bf70a5f83 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -1549,7 +1549,6 @@ public function testGetLanguages() $request = new Request(); $request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6'); $this->assertEquals(['zh', 'en_US', 'en'], $request->getLanguages()); - $this->assertEquals(['zh', 'en_US', 'en'], $request->getLanguages()); $request = new Request(); $request->headers->set('Accept-language', 'zh, en-us; q=0.6, en; q=0.8'); diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 2858b0a40..c61dbacdd 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -532,7 +532,6 @@ public function testPrepareRemovesContentForInformationalResponse() $response->prepare($request); $this->assertEquals('', $response->getContent()); $this->assertFalse($response->headers->has('Content-Type')); - $this->assertFalse($response->headers->has('Content-Type')); $response->setContent('content'); $response->setStatusCode(304); From 92e98d936e8e06464413f391375f2af9a05a1336 Mon Sep 17 00:00:00 2001 From: azjezz Date: Sun, 11 Aug 2019 11:15:18 +0200 Subject: [PATCH 044/127] [HttpFoundation] some cleanups --- AcceptHeader.php | 2 +- BinaryFileResponse.php | 2 +- File/Exception/AccessDeniedException.php | 3 --- File/Exception/FileNotFoundException.php | 3 --- File/File.php | 5 ++++- FileBag.php | 2 +- HeaderBag.php | 12 ++---------- ParameterBag.php | 7 ------- Request.php | 12 ++++++------ RequestMatcher.php | 3 --- Response.php | 4 ++-- ResponseHeaderBag.php | 2 +- Session/Attribute/AttributeBagInterface.php | 7 +------ Session/Session.php | 2 +- Session/SessionBagProxy.php | 2 +- Session/SessionInterface.php | 16 +++++++--------- .../Storage/Handler/MemcachedSessionHandler.php | 2 -- Session/Storage/Handler/PdoSessionHandler.php | 8 ++++---- Session/Storage/MetadataBag.php | 2 +- Session/Storage/MockFileSessionStorage.php | 4 ++-- Session/Storage/NativeSessionStorage.php | 4 ++-- Session/Storage/PhpBridgeSessionStorage.php | 4 +++- StreamedResponse.php | 2 -- 23 files changed, 40 insertions(+), 70 deletions(-) diff --git a/AcceptHeader.php b/AcceptHeader.php index 3f5fbb8f3..bbbd62a6d 100644 --- a/AcceptHeader.php +++ b/AcceptHeader.php @@ -153,7 +153,7 @@ public function first() /** * Sorts items by descending quality. */ - private function sort() + private function sort(): void { if (!$this->sorted) { uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) { diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 79329e2e2..4fd4aec1a 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -269,7 +269,7 @@ public function prepare(Request $request) return $this; } - private function hasValidIfRangeHeader(?string $header) + private function hasValidIfRangeHeader(?string $header): bool { if ($this->getEtag() === $header) { return true; diff --git a/File/Exception/AccessDeniedException.php b/File/Exception/AccessDeniedException.php index c25c3629b..136d2a9f5 100644 --- a/File/Exception/AccessDeniedException.php +++ b/File/Exception/AccessDeniedException.php @@ -18,9 +18,6 @@ */ class AccessDeniedException extends FileException { - /** - * @param string $path The path to the accessed file - */ public function __construct(string $path) { parent::__construct(sprintf('The file %s could not be accessed', $path)); diff --git a/File/Exception/FileNotFoundException.php b/File/Exception/FileNotFoundException.php index 0f1f3f951..31bdf68fe 100644 --- a/File/Exception/FileNotFoundException.php +++ b/File/Exception/FileNotFoundException.php @@ -18,9 +18,6 @@ */ class FileNotFoundException extends FileException { - /** - * @param string $path The path to the file that was not found - */ public function __construct(string $path) { parent::__construct(sprintf('The file "%s" does not exist', $path)); diff --git a/File/File.php b/File/File.php index 396ff3450..4906588a7 100644 --- a/File/File.php +++ b/File/File.php @@ -99,6 +99,9 @@ public function move($directory, $name = null) return $target; } + /** + * @return self + */ protected function getTargetFile($directory, $name = null) { if (!is_dir($directory)) { @@ -119,7 +122,7 @@ protected function getTargetFile($directory, $name = null) * * @param string $name The new file name * - * @return string containing + * @return string */ protected function getName($name) { diff --git a/FileBag.php b/FileBag.php index efd83ffeb..eec3ff446 100644 --- a/FileBag.php +++ b/FileBag.php @@ -24,7 +24,7 @@ class FileBag extends ParameterBag private static $fileKeys = ['error', 'name', 'size', 'tmp_name', 'type']; /** - * @param array $parameters An array of HTTP files + * @param array|UploadedFile[] $parameters An array of HTTP files */ public function __construct(array $parameters = []) { diff --git a/HeaderBag.php b/HeaderBag.php index ef549f3c3..3d12cb0f6 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -21,9 +21,6 @@ class HeaderBag implements \IteratorAggregate, \Countable protected $headers = []; protected $cacheControl = []; - /** - * @param array $headers An array of HTTP headers - */ public function __construct(array $headers = []) { foreach ($headers as $key => $values) { @@ -85,8 +82,6 @@ public function keys() /** * Replaces the current HTTP headers by a new set. - * - * @param array $headers An array of HTTP headers */ public function replace(array $headers = []) { @@ -96,8 +91,6 @@ public function replace(array $headers = []) /** * Adds new headers the current HTTP headers set. - * - * @param array $headers An array of HTTP headers */ public function add(array $headers) { @@ -204,10 +197,9 @@ public function remove($key) /** * Returns the HTTP header value converted to a date. * - * @param string $key The parameter key - * @param \DateTime $default The default value + * @param string $key The parameter key * - * @return \DateTime|null The parsed DateTime or the default value if the header does not exist + * @return \DateTimeInterface|null The parsed DateTime or the default value if the header does not exist * * @throws \RuntimeException When the HTTP header is not parseable */ diff --git a/ParameterBag.php b/ParameterBag.php index 194ba2c6c..20ca6758b 100644 --- a/ParameterBag.php +++ b/ParameterBag.php @@ -23,9 +23,6 @@ class ParameterBag implements \IteratorAggregate, \Countable */ protected $parameters; - /** - * @param array $parameters An array of parameters - */ public function __construct(array $parameters = []) { $this->parameters = $parameters; @@ -53,8 +50,6 @@ public function keys() /** * Replaces the current parameters by a new set. - * - * @param array $parameters An array of parameters */ public function replace(array $parameters = []) { @@ -63,8 +58,6 @@ public function replace(array $parameters = []) /** * Adds parameters. - * - * @param array $parameters An array of parameters */ public function add(array $parameters = []) { diff --git a/Request.php b/Request.php index 2edc34910..2a980bfa5 100644 --- a/Request.php +++ b/Request.php @@ -632,7 +632,7 @@ public static function getTrustedHosts() */ public static function normalizeQueryString($qs) { - if ('' == $qs) { + if ('' === ($qs ?? '')) { return ''; } @@ -702,7 +702,7 @@ public function get($key, $default = null) /** * Gets the Session. * - * @return SessionInterface|null The session + * @return SessionInterface The session */ public function getSession() { @@ -1591,7 +1591,7 @@ public function getPreferredFormat(?string $default = 'html'): ?string /** * Returns the preferred language. * - * @param array $locales An array of ordered available locales + * @param string[] $locales An array of ordered available locales * * @return string|null The preferred locale */ @@ -1920,7 +1920,7 @@ protected static function initializeFormats() ]; } - private function setPhpDefaultLocale(string $locale) + private function setPhpDefaultLocale(string $locale): void { // if either the class Locale doesn't exist, or an exception is thrown when // setting the default locale, the intl module is not installed, and @@ -1982,7 +1982,7 @@ public function isFromTrustedProxy() return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies); } - private function getTrustedValues(int $type, string $ip = null) + private function getTrustedValues(int $type, string $ip = null): array { $clientValues = []; $forwardedValues = []; @@ -2033,7 +2033,7 @@ private function getTrustedValues(int $type, string $ip = null) throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::$trustedHeaders[self::HEADER_FORWARDED], self::$trustedHeaders[$type])); } - private function normalizeAndFilterClientIps(array $clientIps, string $ip) + private function normalizeAndFilterClientIps(array $clientIps, string $ip): array { if (!$clientIps) { return []; diff --git a/RequestMatcher.php b/RequestMatcher.php index d79c7f2ea..ca90f8b1f 100644 --- a/RequestMatcher.php +++ b/RequestMatcher.php @@ -54,11 +54,8 @@ class RequestMatcher implements RequestMatcherInterface private $schemes = []; /** - * @param string|null $path - * @param string|null $host * @param string|string[]|null $methods * @param string|string[]|null $ips - * @param array $attributes * @param string|string[]|null $schemes */ public function __construct(string $path = null, string $host = null, $methods = null, $ips = null, array $attributes = [], $schemes = null, int $port = null) diff --git a/Response.php b/Response.php index c6a3b32dd..15e1e1bba 100644 --- a/Response.php +++ b/Response.php @@ -1208,7 +1208,7 @@ public function isEmpty(): bool * * @final */ - public static function closeOutputBuffers(int $targetLevel, bool $flush) + public static function closeOutputBuffers(int $targetLevel, bool $flush): void { $status = ob_get_status(true); $level = \count($status); @@ -1230,7 +1230,7 @@ public static function closeOutputBuffers(int $targetLevel, bool $flush) * * @final */ - protected function ensureIEOverSSLCompatibility(Request $request) + protected function ensureIEOverSSLCompatibility(Request $request): void { if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && 1 == preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) && true === $request->isSecure()) { if ((int) preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) { diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index 0cfc6f6ac..79f58eb86 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -298,7 +298,7 @@ protected function computeCacheControlValue() return $header; } - private function initDate() + private function initDate(): void { $now = \DateTime::createFromFormat('U', time()); $now->setTimezone(new \DateTimeZone('UTC')); diff --git a/Session/Attribute/AttributeBagInterface.php b/Session/Attribute/AttributeBagInterface.php index 0d8d17991..6fa229397 100644 --- a/Session/Attribute/AttributeBagInterface.php +++ b/Session/Attribute/AttributeBagInterface.php @@ -50,15 +50,10 @@ public function set($name, $value); /** * Returns attributes. * - * @return array Attributes + * @return array */ public function all(); - /** - * Sets attributes. - * - * @param array $attributes Attributes - */ public function replace(array $attributes); /** diff --git a/Session/Session.php b/Session/Session.php index eb1dc2af9..365ef29cf 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -129,7 +129,7 @@ public function getIterator() /** * Returns the number of attributes. * - * @return int The number of attributes + * @return int */ public function count() { diff --git a/Session/SessionBagProxy.php b/Session/SessionBagProxy.php index 3504bdfe7..2ea1cd5a5 100644 --- a/Session/SessionBagProxy.php +++ b/Session/SessionBagProxy.php @@ -63,7 +63,7 @@ public function getName() /** * {@inheritdoc} */ - public function initialize(array &$array) + public function initialize(array &$array): void { ++$this->usageIndex; $this->data[$this->bag->getStorageKey()] = &$array; diff --git a/Session/SessionInterface.php b/Session/SessionInterface.php index 95fca857e..e758c6bda 100644 --- a/Session/SessionInterface.php +++ b/Session/SessionInterface.php @@ -23,7 +23,7 @@ interface SessionInterface /** * Starts the session storage. * - * @return bool True if session started + * @return bool * * @throws \RuntimeException if session fails to start */ @@ -32,7 +32,7 @@ public function start(); /** * Returns the session ID. * - * @return string The session ID + * @return string */ public function getId(); @@ -46,7 +46,7 @@ public function setId($id); /** * Returns the session name. * - * @return mixed The session name + * @return string */ public function getName(); @@ -68,7 +68,7 @@ public function setName($name); * to expire with browser session. Time is in seconds, and is * not a Unix timestamp. * - * @return bool True if session invalidated, false if error + * @return bool */ public function invalidate($lifetime = null); @@ -82,7 +82,7 @@ public function invalidate($lifetime = null); * to expire with browser session. Time is in seconds, and is * not a Unix timestamp. * - * @return bool True if session migrated, false if error + * @return bool */ public function migrate($destroy = false, $lifetime = null); @@ -100,7 +100,7 @@ public function save(); * * @param string $name The attribute name * - * @return bool true if the attribute is defined, false otherwise + * @return bool */ public function has($name); @@ -125,14 +125,12 @@ public function set($name, $value); /** * Returns attributes. * - * @return array Attributes + * @return array */ public function all(); /** * Sets attributes. - * - * @param array $attributes Attributes */ public function replace(array $attributes); diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index f1bce4a35..3faa336f6 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -40,8 +40,6 @@ class MemcachedSessionHandler extends AbstractSessionHandler * * prefix: The prefix to use for the memcached keys in order to avoid collision * * expiretime: The time to live in seconds. * - * @param \Memcached $memcached A \Memcached instance - * * @throws \InvalidArgumentException When unsupported options are passed */ public function __construct(\Memcached $memcached, array $options = []) diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 666d7e464..f1648adaa 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -423,7 +423,7 @@ public function close() /** * Lazy-connects to the database. */ - private function connect(string $dsn) + private function connect(string $dsn): void { $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); @@ -534,7 +534,7 @@ private function buildDsnFromUrl(string $dsnOrUrl): string * due to https://percona.com/blog/2013/12/12/one-more-innodb-gap-lock-to-avoid/ . * So we change it to READ COMMITTED. */ - private function beginTransaction() + private function beginTransaction(): void { if (!$this->inTransaction) { if ('sqlite' === $this->driver) { @@ -552,7 +552,7 @@ private function beginTransaction() /** * Helper method to commit a transaction. */ - private function commit() + private function commit(): void { if ($this->inTransaction) { try { @@ -574,7 +574,7 @@ private function commit() /** * Helper method to rollback a transaction. */ - private function rollback() + private function rollback(): void { // We only need to rollback if we are in a transaction. Otherwise the resulting // error would hide the real problem why rollback was called. We might not be diff --git a/Session/Storage/MetadataBag.php b/Session/Storage/MetadataBag.php index ece3ff34f..5fe40fc10 100644 --- a/Session/Storage/MetadataBag.php +++ b/Session/Storage/MetadataBag.php @@ -159,7 +159,7 @@ public function setName($name) $this->name = $name; } - private function stampCreated(int $lifetime = null) + private function stampCreated(int $lifetime = null): void { $timeStamp = time(); $this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp; diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index 7916fa819..02fe4dad4 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -121,7 +121,7 @@ public function save() * Deletes a session from persistent storage. * Deliberately leaves session data in memory intact. */ - private function destroy() + private function destroy(): void { if (is_file($this->getFilePath())) { unlink($this->getFilePath()); @@ -139,7 +139,7 @@ private function getFilePath(): string /** * Reads session from storage and loads session. */ - private function read() + private function read(): void { $filePath = $this->getFilePath(); $this->data = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : []; diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 7e177ca50..2a57e6ce8 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -97,7 +97,7 @@ class NativeSessionStorage implements SessionStorageInterface * trans_sid_hosts, $_SERVER['HTTP_HOST'] * trans_sid_tags, "a=href,area=href,frame=src,form=" * - * @param \SessionHandlerInterface|null $handler + * @param AbstractProxy|\SessionHandlerInterface|null $handler */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) { @@ -409,7 +409,7 @@ public function setOptions(array $options) * @see https://php.net/sessionhandler * @see https://github.com/zikula/NativeSession * - * @param \SessionHandlerInterface|null $saveHandler + * @param AbstractProxy|\SessionHandlerInterface|null $saveHandler * * @throws \InvalidArgumentException */ diff --git a/Session/Storage/PhpBridgeSessionStorage.php b/Session/Storage/PhpBridgeSessionStorage.php index f0fac5843..72dbef134 100644 --- a/Session/Storage/PhpBridgeSessionStorage.php +++ b/Session/Storage/PhpBridgeSessionStorage.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; +use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; + /** * Allows session to be started by PHP and managed by Symfony. * @@ -19,7 +21,7 @@ class PhpBridgeSessionStorage extends NativeSessionStorage { /** - * @param \SessionHandlerInterface|null $handler + * @param AbstractProxy|\SessionHandlerInterface|null $handler */ public function __construct($handler = null, MetadataBag $metaBag = null) { diff --git a/StreamedResponse.php b/StreamedResponse.php index 8310ea72d..06d7a47ad 100644 --- a/StreamedResponse.php +++ b/StreamedResponse.php @@ -63,8 +63,6 @@ public static function create($callback = null, $status = 200, $headers = []) /** * Sets the PHP callback associated with this Response. * - * @param callable $callback A valid PHP callback - * * @return $this */ public function setCallback(callable $callback) From e09db04575025b89a1a6f210bd320d9106c87d0b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 11 Aug 2019 11:51:13 +0200 Subject: [PATCH 045/127] [HttpFoundation] fix typo --- HeaderUtils.php | 1 - RequestMatcher.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/HeaderUtils.php b/HeaderUtils.php index 31db1bd0d..5866e3b2b 100644 --- a/HeaderUtils.php +++ b/HeaderUtils.php @@ -36,7 +36,6 @@ private function __construct() * HeaderUtils::split("da, en-gb;q=0.8", ",;") * // => ['da'], ['en-gb', 'q=0.8']] * - * @param string $header HTTP header value * @param string $separators List of characters to split on, ordered by * precedence, e.g. ",", ";=", or ",;=" * diff --git a/RequestMatcher.php b/RequestMatcher.php index d79c7f2ea..0b2da8c06 100644 --- a/RequestMatcher.php +++ b/RequestMatcher.php @@ -100,7 +100,7 @@ public function matchHost($regexp) * * @param int|null $port The port number to connect to */ - public function matchPort(int $port = null) + public function matchPort(?int $port) { $this->port = $port; } From 27f2b785f3feaad6b924ea29d0757a6fbb91b912 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 12 Aug 2019 22:21:04 +0200 Subject: [PATCH 046/127] Fix return statements --- File/MimeType/FileBinaryMimeTypeGuesser.php | 6 +++--- File/MimeType/FileinfoMimeTypeGuesser.php | 4 ++-- File/MimeType/MimeTypeGuesserInterface.php | 2 +- RequestStack.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/File/MimeType/FileBinaryMimeTypeGuesser.php b/File/MimeType/FileBinaryMimeTypeGuesser.php index 34e015ee5..b75242afd 100644 --- a/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -74,7 +74,7 @@ public function guess($path) } if (!self::isSupported()) { - return; + return null; } ob_start(); @@ -84,14 +84,14 @@ public function guess($path) if ($return > 0) { ob_end_clean(); - return; + return null; } $type = trim(ob_get_clean()); if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) { // it's not a type, but an error message - return; + return null; } return $match[1]; diff --git a/File/MimeType/FileinfoMimeTypeGuesser.php b/File/MimeType/FileinfoMimeTypeGuesser.php index 62feda2ee..fc4bc4502 100644 --- a/File/MimeType/FileinfoMimeTypeGuesser.php +++ b/File/MimeType/FileinfoMimeTypeGuesser.php @@ -57,11 +57,11 @@ public function guess($path) } if (!self::isSupported()) { - return; + return null; } if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) { - return; + return null; } return $finfo->file($path); diff --git a/File/MimeType/MimeTypeGuesserInterface.php b/File/MimeType/MimeTypeGuesserInterface.php index 5ac1acb82..e46e78eef 100644 --- a/File/MimeType/MimeTypeGuesserInterface.php +++ b/File/MimeType/MimeTypeGuesserInterface.php @@ -26,7 +26,7 @@ interface MimeTypeGuesserInterface * * @param string $path The path to the file * - * @return string The mime type or NULL, if none could be guessed + * @return string|null The mime type or NULL, if none could be guessed * * @throws FileNotFoundException If the file does not exist * @throws AccessDeniedException If the file could not be read diff --git a/RequestStack.php b/RequestStack.php index 885d78a50..244a77d63 100644 --- a/RequestStack.php +++ b/RequestStack.php @@ -47,7 +47,7 @@ public function push(Request $request) public function pop() { if (!$this->requests) { - return; + return null; } return array_pop($this->requests); @@ -73,7 +73,7 @@ public function getCurrentRequest() public function getMasterRequest() { if (!$this->requests) { - return; + return null; } return $this->requests[0]; @@ -95,7 +95,7 @@ public function getParentRequest() $pos = \count($this->requests) - 2; if (!isset($this->requests[$pos])) { - return; + return null; } return $this->requests[$pos]; From 4f673837a24963334b905e01585ad34c85a30ccc Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Tue, 13 Aug 2019 12:17:15 -0400 Subject: [PATCH 047/127] [HttpFoundation] Fix deprecation message in ::isMethodSafe() --- Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 2a980bfa5..824013ba9 100644 --- a/Request.php +++ b/Request.php @@ -1447,7 +1447,7 @@ public function isMethod($method) public function isMethodSafe() { if (\func_num_args() > 0) { - @trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable() to check if the method is cacheable instead."', __METHOD__, __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable()" to check if the method is cacheable instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED); } return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']); From adc268778aab47e1465fd7ebf90ecfdd9ca6080c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Tue, 13 Aug 2019 19:24:27 +0200 Subject: [PATCH 048/127] Fix getMaxFilesize() returning zero --- File/UploadedFile.php | 2 +- Tests/File/UploadedFileTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/File/UploadedFile.php b/File/UploadedFile.php index 093aaf832..86153ed49 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -217,7 +217,7 @@ public static function getMaxFilesize() $sizePostMax = self::parseFilesize(ini_get('post_max_size')); $sizeUploadMax = self::parseFilesize(ini_get('upload_max_filesize')); - return min([$sizePostMax, $sizeUploadMax]); + return min($sizePostMax ?: PHP_INT_MAX, $sizeUploadMax ?: PHP_INT_MAX); } /** diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 629211052..4186c72a6 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -281,4 +281,18 @@ public function testIsInvalidIfNotHttpUpload() $this->assertFalse($file->isValid()); } + + public function testGetMaxFilesize() + { + $size = UploadedFile::getMaxFilesize(); + + $this->assertIsInt($size); + $this->assertGreaterThan(0, $size); + + if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) { + $this->assertSame(PHP_INT_MAX, $size); + } else { + $this->assertLessThan(PHP_INT_MAX, $size); + } + } } From dacdad8436eab21a518d041dd954813b634ae932 Mon Sep 17 00:00:00 2001 From: Philippe Segatori Date: Tue, 13 Aug 2019 22:27:05 +0200 Subject: [PATCH 049/127] Remove superfluous phpdoc tags --- AcceptHeaderItem.php | 1 - RequestMatcher.php | 1 - 2 files changed, 2 deletions(-) diff --git a/AcceptHeaderItem.php b/AcceptHeaderItem.php index f6e896874..96bb0c443 100644 --- a/AcceptHeaderItem.php +++ b/AcceptHeaderItem.php @@ -25,7 +25,6 @@ class AcceptHeaderItem /** * @param string $value - * @param array $attributes */ public function __construct($value, array $attributes = []) { diff --git a/RequestMatcher.php b/RequestMatcher.php index cadf70c5b..3f5149579 100644 --- a/RequestMatcher.php +++ b/RequestMatcher.php @@ -53,7 +53,6 @@ class RequestMatcher implements RequestMatcherInterface * @param string|null $host * @param string|string[]|null $methods * @param string|string[]|null $ips - * @param array $attributes * @param string|string[]|null $schemes */ public function __construct($path = null, $host = null, $methods = null, $ips = null, array $attributes = [], $schemes = null) From e44dd0c9dc426c64590cca067e2b2025dc8819f7 Mon Sep 17 00:00:00 2001 From: azjezz Date: Wed, 14 Aug 2019 15:53:04 +0100 Subject: [PATCH 050/127] [HttpFoundation] Precalculate session expiry timestamp Co-authored-by: Benjamin Cremer Co-authored-by: Rob Frawley 2nd --- CHANGELOG.md | 5 +- Session/Storage/Handler/PdoSessionHandler.php | 60 ++++++++++++------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62aa6be13..577f27e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ CHANGELOG * passing arguments to `Request::isMethodSafe()` is deprecated. * `ApacheRequest` is deprecated, use the `Request` class instead. * passing a third argument to `HeaderBag::get()` is deprecated, use method `all()` instead - + * `PdoSessionHandler` now precalculates the expiry timestamp in the lifetime column, + make sure to run `CREATE INDEX EXPIRY ON sessions (sess_lifetime)` to update your database + to speed up garbage collection of expired sessions. + 4.3.0 ----- diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index f1648adaa..043252cd3 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -65,6 +65,8 @@ class PdoSessionHandler extends AbstractSessionHandler */ const LOCK_TRANSACTIONAL = 2; + private const MAX_LIFETIME = 315576000; + /** * @var \PDO|null PDO instance or null when not connected yet */ @@ -237,6 +239,7 @@ public function createTable() try { $this->pdo->exec($sql); + $this->pdo->exec("CREATE INDEX EXPIRY ON $this->table ($this->lifetimeCol)"); } catch (\PDOException $e) { $this->rollback(); @@ -368,14 +371,14 @@ protected function doWrite($sessionId, $data) */ public function updateTimestamp($sessionId, $data) { - $maxlifetime = (int) ini_get('session.gc_maxlifetime'); + $expiry = time() + (int) ini_get('session.gc_maxlifetime'); try { $updateStmt = $this->pdo->prepare( - "UPDATE $this->table SET $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id" + "UPDATE $this->table SET $this->lifetimeCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id" ); $updateStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); - $updateStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT); + $updateStmt->bindParam(':expiry', $expiry, \PDO::PARAM_INT); $updateStmt->bindValue(':time', time(), \PDO::PARAM_INT); $updateStmt->execute(); } catch (\PDOException $e) { @@ -402,14 +405,21 @@ public function close() $this->gcCalled = false; // delete the session records that have expired + $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time AND $this->lifetimeCol > :min"; + $stmt = $this->pdo->prepare($sql); + $stmt->bindValue(':time', time(), \PDO::PARAM_INT); + $stmt->bindValue(':min', self::MAX_LIFETIME, \PDO::PARAM_INT); + $stmt->execute(); + // to be removed in 6.0 if ('mysql' === $this->driver) { - $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time"; + $legacySql = "DELETE FROM $this->table WHERE $this->lifetimeCol <= :min AND $this->lifetimeCol + $this->timeCol < :time"; } else { - $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time - $this->timeCol"; + $legacySql = "DELETE FROM $this->table WHERE $this->lifetimeCol <= :min AND $this->lifetimeCol < :time - $this->timeCol"; } - $stmt = $this->pdo->prepare($sql); + $stmt = $this->pdo->prepare($legacySql); $stmt->bindValue(':time', time(), \PDO::PARAM_INT); + $stmt->bindValue(':min', self::MAX_LIFETIME, \PDO::PARAM_INT); $stmt->execute(); } @@ -616,7 +626,12 @@ protected function doRead($sessionId) $sessionRows = $selectStmt->fetchAll(\PDO::FETCH_NUM); if ($sessionRows) { - if ($sessionRows[0][1] + $sessionRows[0][2] < time()) { + $expiry = (int) $sessionRows[0][1]; + if ($expiry <= self::MAX_LIFETIME) { + $expiry += $sessionRows[0][2]; + } + + if ($expiry < time()) { $this->sessionExpired = true; return ''; @@ -747,6 +762,7 @@ private function getSelectSql(): string if (self::LOCK_TRANSACTIONAL === $this->lockMode) { $this->beginTransaction(); + // selecting the time column should be removed in 6.0 switch ($this->driver) { case 'mysql': case 'oci': @@ -775,18 +791,18 @@ private function getInsertStatement(string $sessionId, string $sessionData, int $data = fopen('php://memory', 'r+'); fwrite($data, $sessionData); rewind($data); - $sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, EMPTY_BLOB(), :lifetime, :time) RETURNING $this->dataCol into :data"; + $sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, EMPTY_BLOB(), :expiry, :time) RETURNING $this->dataCol into :data"; break; default: $data = $sessionData; - $sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)"; + $sql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :expiry, :time)"; break; } $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $stmt->bindParam(':data', $data, \PDO::PARAM_LOB); - $stmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT); + $stmt->bindValue(':expiry', time() + $maxlifetime, \PDO::PARAM_INT); $stmt->bindValue(':time', time(), \PDO::PARAM_INT); return $stmt; @@ -802,18 +818,18 @@ private function getUpdateStatement(string $sessionId, string $sessionData, int $data = fopen('php://memory', 'r+'); fwrite($data, $sessionData); rewind($data); - $sql = "UPDATE $this->table SET $this->dataCol = EMPTY_BLOB(), $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id RETURNING $this->dataCol into :data"; + $sql = "UPDATE $this->table SET $this->dataCol = EMPTY_BLOB(), $this->lifetimeCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id RETURNING $this->dataCol into :data"; break; default: $data = $sessionData; - $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id"; + $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id"; break; } $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $stmt->bindParam(':data', $data, \PDO::PARAM_LOB); - $stmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT); + $stmt->bindValue(':expiry', time() + $maxlifetime, \PDO::PARAM_INT); $stmt->bindValue(':time', time(), \PDO::PARAM_INT); return $stmt; @@ -826,7 +842,7 @@ private function getMergeStatement(string $sessionId, string $data, int $maxlife { switch (true) { case 'mysql' === $this->driver: - $mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ". + $mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :expiry, :time) ". "ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)"; break; case 'sqlsrv' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '10', '>='): @@ -837,10 +853,10 @@ private function getMergeStatement(string $sessionId, string $data, int $maxlife "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;"; break; case 'sqlite' === $this->driver: - $mergeSql = "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)"; + $mergeSql = "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :expiry, :time)"; break; case 'pgsql' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '9.5', '>='): - $mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ". + $mergeSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :expiry, :time) ". "ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)"; break; default: @@ -854,15 +870,15 @@ private function getMergeStatement(string $sessionId, string $data, int $maxlife $mergeStmt->bindParam(1, $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB); - $mergeStmt->bindParam(4, $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(5, time(), \PDO::PARAM_INT); - $mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB); - $mergeStmt->bindParam(7, $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(8, time(), \PDO::PARAM_INT); + $mergeStmt->bindValue(4, time() + $maxlifetime, \PDO::PARAM_INT); + $mergeStmt->bindValue(4, time(), \PDO::PARAM_INT); + $mergeStmt->bindParam(5, $data, \PDO::PARAM_LOB); + $mergeStmt->bindValue(6, time() + $maxlifetime, \PDO::PARAM_INT); + $mergeStmt->bindValue(6, time(), \PDO::PARAM_INT); } else { $mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB); - $mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT); + $mergeStmt->bindValue(':expiry', time() + $maxlifetime, \PDO::PARAM_INT); $mergeStmt->bindValue(':time', time(), \PDO::PARAM_INT); } From 9781d8d29ee7279f53720f7c0281e6fb442e96e4 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Aug 2019 23:30:37 +0200 Subject: [PATCH 051/127] Fix inconsistent return points. --- File/MimeType/ExtensionGuesser.php | 2 ++ File/MimeType/MimeTypeGuesser.php | 2 ++ Request.php | 18 ++++++++++-------- Response.php | 6 +++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/File/MimeType/ExtensionGuesser.php b/File/MimeType/ExtensionGuesser.php index 80f4d47f7..f9393df90 100644 --- a/File/MimeType/ExtensionGuesser.php +++ b/File/MimeType/ExtensionGuesser.php @@ -90,5 +90,7 @@ public function guess($mimeType) return $extension; } } + + return null; } } diff --git a/File/MimeType/MimeTypeGuesser.php b/File/MimeType/MimeTypeGuesser.php index 95d1ee267..e05269fc8 100644 --- a/File/MimeType/MimeTypeGuesser.php +++ b/File/MimeType/MimeTypeGuesser.php @@ -129,5 +129,7 @@ public function guess($path) if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) { throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)'); } + + return null; } } diff --git a/Request.php b/Request.php index 9557dac30..3b9bf2f49 100644 --- a/Request.php +++ b/Request.php @@ -97,49 +97,49 @@ class Request /** * Custom parameters. * - * @var \Symfony\Component\HttpFoundation\ParameterBag + * @var ParameterBag */ public $attributes; /** * Request body parameters ($_POST). * - * @var \Symfony\Component\HttpFoundation\ParameterBag + * @var ParameterBag */ public $request; /** * Query string parameters ($_GET). * - * @var \Symfony\Component\HttpFoundation\ParameterBag + * @var ParameterBag */ public $query; /** * Server and execution environment parameters ($_SERVER). * - * @var \Symfony\Component\HttpFoundation\ServerBag + * @var ServerBag */ public $server; /** * Uploaded files ($_FILES). * - * @var \Symfony\Component\HttpFoundation\FileBag + * @var FileBag */ public $files; /** * Cookies ($_COOKIE). * - * @var \Symfony\Component\HttpFoundation\ParameterBag + * @var ParameterBag */ public $cookies; /** * Headers (taken from the $_SERVER). * - * @var \Symfony\Component\HttpFoundation\HeaderBag + * @var HeaderBag */ public $headers; @@ -199,7 +199,7 @@ class Request protected $format; /** - * @var \Symfony\Component\HttpFoundation\Session\SessionInterface + * @var SessionInterface */ protected $session; @@ -1449,6 +1449,8 @@ public function getFormat($mimeType) return $format; } } + + return null; } /** diff --git a/Response.php b/Response.php index 47dae9534..eae9b7841 100644 --- a/Response.php +++ b/Response.php @@ -88,7 +88,7 @@ class Response const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 /** - * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag + * @var ResponseHeaderBag */ public $headers; @@ -790,6 +790,8 @@ public function getMaxAge() if (null !== $this->getExpires()) { return (int) $this->getExpires()->format('U') - (int) $this->getDate()->format('U'); } + + return null; } /** @@ -846,6 +848,8 @@ public function getTtl() if (null !== $maxAge = $this->getMaxAge()) { return $maxAge - $this->getAge(); } + + return null; } /** From 69d2f9152849120ba5c91fc2bd4f1823ba5f9fce Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Aug 2019 23:30:37 +0200 Subject: [PATCH 052/127] Fix inconsistent return points. --- Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Response.php b/Response.php index 2ee8dcbf8..3bece1494 100644 --- a/Response.php +++ b/Response.php @@ -88,7 +88,7 @@ class Response const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 /** - * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag + * @var ResponseHeaderBag */ public $headers; From d43988f8b46f937fc1fcacb4930a6060c25bddd9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 20 Aug 2019 13:52:38 +0200 Subject: [PATCH 053/127] Add return types to internal|final|private methods --- Session/Session.php | 4 +--- Session/SessionBagProxy.php | 14 ++++---------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Session/Session.php b/Session/Session.php index 365ef29cf..0c7e9cc5c 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -147,11 +147,9 @@ public function getUsageIndex() } /** - * @return bool - * * @internal */ - public function isEmpty() + public function isEmpty(): bool { if ($this->isStarted()) { ++$this->usageIndex; diff --git a/Session/SessionBagProxy.php b/Session/SessionBagProxy.php index 2ea1cd5a5..09df1426e 100644 --- a/Session/SessionBagProxy.php +++ b/Session/SessionBagProxy.php @@ -29,20 +29,14 @@ public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex $this->usageIndex = &$usageIndex; } - /** - * @return SessionBagInterface - */ - public function getBag() + public function getBag(): SessionBagInterface { ++$this->usageIndex; return $this->bag; } - /** - * @return bool - */ - public function isEmpty() + public function isEmpty(): bool { if (!isset($this->data[$this->bag->getStorageKey()])) { return true; @@ -55,7 +49,7 @@ public function isEmpty() /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return $this->bag->getName(); } @@ -74,7 +68,7 @@ public function initialize(array &$array): void /** * {@inheritdoc} */ - public function getStorageKey() + public function getStorageKey(): string { return $this->bag->getStorageKey(); } From 491b8349828ffde8ecceb871528289cd2033cc26 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Aug 2019 15:30:43 +0200 Subject: [PATCH 054/127] Add return types to tests and final|internal|private methods --- Tests/Session/Storage/NativeSessionStorageTest.php | 5 +---- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 17f46bef5..b04e06112 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -53,10 +53,7 @@ protected function tearDown(): void $this->savePath = null; } - /** - * @return NativeSessionStorage - */ - protected function getStorage(array $options = []) + protected function getStorage(array $options = []): NativeSessionStorage { $storage = new NativeSessionStorage($options); $storage->registerBag(new AttributeBag()); diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 7d6827079..206ff4877 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -49,10 +49,7 @@ protected function tearDown(): void $this->savePath = null; } - /** - * @return PhpBridgeSessionStorage - */ - protected function getStorage() + protected function getStorage(): PhpBridgeSessionStorage { $storage = new PhpBridgeSessionStorage(); $storage->registerBag(new AttributeBag()); From 0004510f52c38ae240a8a417ae544a28a159d95f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 22 Aug 2019 15:01:48 +0200 Subject: [PATCH 055/127] Add return types to internal & magic methods when possible --- .../Storage/Handler/AbstractSessionHandler.php | 10 +++++----- .../Storage/Handler/MemcachedSessionHandler.php | 6 +++--- .../Storage/Handler/MigratingSessionHandler.php | 16 ++++++++-------- .../Storage/Handler/MongoDbSessionHandler.php | 6 +++--- Session/Storage/Handler/NullSessionHandler.php | 8 ++++---- Session/Storage/Handler/PdoSessionHandler.php | 10 +++++----- Session/Storage/Handler/RedisSessionHandler.php | 2 +- Session/Storage/Handler/StrictSessionHandler.php | 10 +++++----- Session/Storage/Proxy/SessionHandlerProxy.php | 16 ++++++++-------- Tests/ResponseTest.php | 2 +- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index 78340efbd..bcde59ee6 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -29,7 +29,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess private $igbinaryEmptyData; /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -64,7 +64,7 @@ abstract protected function doWrite($sessionId, $data); abstract protected function doDestroy($sessionId); /** - * {@inheritdoc} + * @return bool */ public function validateId($sessionId) { @@ -75,7 +75,7 @@ public function validateId($sessionId) } /** - * {@inheritdoc} + * @return string */ public function read($sessionId) { @@ -98,7 +98,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function write($sessionId, $data) { @@ -115,7 +115,7 @@ public function write($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function destroy($sessionId) { diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 3faa336f6..7a528e655 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -55,7 +55,7 @@ public function __construct(\Memcached $memcached, array $options = []) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -71,7 +71,7 @@ protected function doRead($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -99,7 +99,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/MigratingSessionHandler.php b/Session/Storage/Handler/MigratingSessionHandler.php index 5293d2448..ccf23de7e 100644 --- a/Session/Storage/Handler/MigratingSessionHandler.php +++ b/Session/Storage/Handler/MigratingSessionHandler.php @@ -39,7 +39,7 @@ public function __construct(\SessionHandlerInterface $currentHandler, \SessionHa } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -50,7 +50,7 @@ public function close() } /** - * {@inheritdoc} + * @return bool */ public function destroy($sessionId) { @@ -61,7 +61,7 @@ public function destroy($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { @@ -72,7 +72,7 @@ public function gc($maxlifetime) } /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -83,7 +83,7 @@ public function open($savePath, $sessionName) } /** - * {@inheritdoc} + * @return string */ public function read($sessionId) { @@ -92,7 +92,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function write($sessionId, $sessionData) { @@ -103,7 +103,7 @@ public function write($sessionId, $sessionData) } /** - * {@inheritdoc} + * @return bool */ public function validateId($sessionId) { @@ -112,7 +112,7 @@ public function validateId($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $sessionData) { diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index 53d9369e8..ad1bd24d4 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -80,7 +80,7 @@ public function __construct(\MongoDB\Client $mongo, array $options) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -100,7 +100,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { @@ -134,7 +134,7 @@ protected function doWrite($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { diff --git a/Session/Storage/Handler/NullSessionHandler.php b/Session/Storage/Handler/NullSessionHandler.php index 8d193155b..ba0639604 100644 --- a/Session/Storage/Handler/NullSessionHandler.php +++ b/Session/Storage/Handler/NullSessionHandler.php @@ -19,7 +19,7 @@ class NullSessionHandler extends AbstractSessionHandler { /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -27,7 +27,7 @@ public function close() } /** - * {@inheritdoc} + * @return bool */ public function validateId($sessionId) { @@ -43,7 +43,7 @@ protected function doRead($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -67,7 +67,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 043252cd3..0cd1296c0 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -260,7 +260,7 @@ public function isSessionExpired() } /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -274,7 +274,7 @@ public function open($savePath, $sessionName) } /** - * {@inheritdoc} + * @return string */ public function read($sessionId) { @@ -288,7 +288,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { @@ -367,7 +367,7 @@ protected function doWrite($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -391,7 +391,7 @@ public function updateTimestamp($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function close() { diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index c2e7d34dc..752e58f73 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -104,7 +104,7 @@ public function gc($maxlifetime): bool } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { diff --git a/Session/Storage/Handler/StrictSessionHandler.php b/Session/Storage/Handler/StrictSessionHandler.php index 83a1f2c06..31a39a697 100644 --- a/Session/Storage/Handler/StrictSessionHandler.php +++ b/Session/Storage/Handler/StrictSessionHandler.php @@ -31,7 +31,7 @@ public function __construct(\SessionHandlerInterface $handler) } /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -49,7 +49,7 @@ protected function doRead($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -65,7 +65,7 @@ protected function doWrite($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function destroy($sessionId) { @@ -86,7 +86,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -94,7 +94,7 @@ public function close() } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { diff --git a/Session/Storage/Proxy/SessionHandlerProxy.php b/Session/Storage/Proxy/SessionHandlerProxy.php index b11cc397a..8034b7a46 100644 --- a/Session/Storage/Proxy/SessionHandlerProxy.php +++ b/Session/Storage/Proxy/SessionHandlerProxy.php @@ -36,7 +36,7 @@ public function getHandler() // \SessionHandlerInterface /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -44,7 +44,7 @@ public function open($savePath, $sessionName) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -52,7 +52,7 @@ public function close() } /** - * {@inheritdoc} + * @return string */ public function read($sessionId) { @@ -60,7 +60,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function write($sessionId, $data) { @@ -68,7 +68,7 @@ public function write($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function destroy($sessionId) { @@ -76,7 +76,7 @@ public function destroy($sessionId) } /** - * {@inheritdoc} + * @return int */ public function gc($maxlifetime) { @@ -84,7 +84,7 @@ public function gc($maxlifetime) } /** - * {@inheritdoc} + * @return bool */ public function validateId($sessionId) { @@ -92,7 +92,7 @@ public function validateId($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 03b29653e..edce7dbf4 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -1054,7 +1054,7 @@ public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase) class StringableObject { - public function __toString() + public function __toString(): string { return 'Foo'; } From 39869c96a715e509d1f1a2d4980d1971adecc2ab Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 23 Aug 2019 14:04:07 +0200 Subject: [PATCH 056/127] Add more return types after fixing a typo in my script --- Session/Session.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Session/Session.php b/Session/Session.php index 0c7e9cc5c..9738189b4 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -137,11 +137,9 @@ public function count() } /** - * @return int - * * @internal */ - public function getUsageIndex() + public function getUsageIndex(): int { return $this->usageIndex; } From b3d57a1c325f39f703b249bed7998ce8c64236b4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Aug 2019 18:20:57 +0200 Subject: [PATCH 057/127] [HttpFoundation] fix return type declarations --- BinaryFileResponse.php | 4 ++-- FileBag.php | 8 +++----- HeaderBag.php | 2 +- Request.php | 6 +++++- Response.php | 2 +- Session/Attribute/NamespacedAttributeBag.php | 2 +- Session/Storage/Handler/MemcachedSessionHandler.php | 9 +++------ Session/Storage/Handler/NullSessionHandler.php | 2 +- Session/Storage/Handler/PdoSessionHandler.php | 2 +- Session/Storage/Handler/StrictSessionHandler.php | 2 +- Session/Storage/Proxy/AbstractProxy.php | 2 +- Session/Storage/Proxy/SessionHandlerProxy.php | 2 +- StreamedResponse.php | 2 -- Tests/BinaryFileResponseTest.php | 2 +- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 3 ++- 15 files changed, 24 insertions(+), 26 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 6c9a995e9..f43114111 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -327,12 +327,12 @@ public function setContent($content) if (null !== $content) { throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.'); } + + return $this; } /** * {@inheritdoc} - * - * @return false */ public function getContent() { diff --git a/FileBag.php b/FileBag.php index ca849b3d7..024fadf20 100644 --- a/FileBag.php +++ b/FileBag.php @@ -75,8 +75,8 @@ protected function convertFileInformation($file) return $file; } - $file = $this->fixPhpFilesArray($file); if (\is_array($file)) { + $file = $this->fixPhpFilesArray($file); $keys = array_keys($file); sort($keys); @@ -109,14 +109,12 @@ protected function convertFileInformation($file) * It's safe to pass an already converted array, in which case this method * just returns the original array unmodified. * + * @param array $data + * * @return array */ protected function fixPhpFilesArray($data) { - if (!\is_array($data)) { - return $data; - } - $keys = array_keys($data); sort($keys); diff --git a/HeaderBag.php b/HeaderBag.php index 9798173e6..08299977c 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -121,7 +121,7 @@ public function get($key, $default = null, $first = true) } if ($first) { - return \count($headers[$key]) ? $headers[$key][0] : $default; + return \count($headers[$key]) ? (string) $headers[$key][0] : $default; } return $headers[$key]; diff --git a/Request.php b/Request.php index 3b9bf2f49..3fc7b71e6 100644 --- a/Request.php +++ b/Request.php @@ -528,6 +528,10 @@ public function __toString() try { $content = $this->getContent(); } catch (\LogicException $e) { + if (\PHP_VERSION_ID >= 70400) { + throw $e; + } + return trigger_error($e, E_USER_ERROR); } @@ -912,7 +916,7 @@ public function getClientIps() * ("Client-Ip" for instance), configure it via the $trustedHeaderSet * argument of the Request::setTrustedProxies() method instead. * - * @return string The client IP address + * @return string|null The client IP address * * @see getClientIps() * @see https://wikipedia.org/wiki/X-Forwarded-For diff --git a/Response.php b/Response.php index eae9b7841..8a17acdd5 100644 --- a/Response.php +++ b/Response.php @@ -407,7 +407,7 @@ public function setContent($content) /** * Gets the current response content. * - * @return string Content + * @return string|false */ public function getContent() { diff --git a/Session/Attribute/NamespacedAttributeBag.php b/Session/Attribute/NamespacedAttributeBag.php index bbf2e39c8..07885e7fb 100644 --- a/Session/Attribute/NamespacedAttributeBag.php +++ b/Session/Attribute/NamespacedAttributeBag.php @@ -97,7 +97,7 @@ public function remove($name) * @param string $name Key name * @param bool $writeContext Write context, default false * - * @return array + * @return array|null */ protected function &resolveAttributePath($name, $writeContext = false) { diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index 8965c089c..a399be5fd 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -40,9 +40,6 @@ class MemcachedSessionHandler extends AbstractSessionHandler * * prefix: The prefix to use for the memcached keys in order to avoid collision * * expiretime: The time to live in seconds. * - * @param \Memcached $memcached A \Memcached instance - * @param array $options An associative array of Memcached options - * * @throws \InvalidArgumentException When unsupported options are passed */ public function __construct(\Memcached $memcached, array $options = []) @@ -58,7 +55,7 @@ public function __construct(\Memcached $memcached, array $options = []) } /** - * {@inheritdoc} + * @return bool */ public function close() { @@ -74,7 +71,7 @@ protected function doRead($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function updateTimestamp($sessionId, $data) { @@ -102,7 +99,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/NullSessionHandler.php b/Session/Storage/Handler/NullSessionHandler.php index 8d193155b..3ba9378ca 100644 --- a/Session/Storage/Handler/NullSessionHandler.php +++ b/Session/Storage/Handler/NullSessionHandler.php @@ -67,7 +67,7 @@ protected function doDestroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 9a50377bc..f9e5d1e8f 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -286,7 +286,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Handler/StrictSessionHandler.php b/Session/Storage/Handler/StrictSessionHandler.php index 83a1f2c06..fab8e9a16 100644 --- a/Session/Storage/Handler/StrictSessionHandler.php +++ b/Session/Storage/Handler/StrictSessionHandler.php @@ -94,7 +94,7 @@ public function close() } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Session/Storage/Proxy/AbstractProxy.php b/Session/Storage/Proxy/AbstractProxy.php index 09c92483c..0303729e7 100644 --- a/Session/Storage/Proxy/AbstractProxy.php +++ b/Session/Storage/Proxy/AbstractProxy.php @@ -31,7 +31,7 @@ abstract class AbstractProxy /** * Gets the session.save_handler name. * - * @return string + * @return string|null */ public function getSaveHandlerName() { diff --git a/Session/Storage/Proxy/SessionHandlerProxy.php b/Session/Storage/Proxy/SessionHandlerProxy.php index b11cc397a..e40712d93 100644 --- a/Session/Storage/Proxy/SessionHandlerProxy.php +++ b/Session/Storage/Proxy/SessionHandlerProxy.php @@ -76,7 +76,7 @@ public function destroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/StreamedResponse.php b/StreamedResponse.php index 8bc5fc91a..b9148ea87 100644 --- a/StreamedResponse.php +++ b/StreamedResponse.php @@ -136,8 +136,6 @@ public function setContent($content) /** * {@inheritdoc} - * - * @return false */ public function getContent() { diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 3df96f393..fcad11def 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -107,7 +107,7 @@ public function testRequests($requestRange, $offset, $length, $responseRange) $this->assertEquals(206, $response->getStatusCode()); $this->assertEquals($responseRange, $response->headers->get('Content-Range')); - $this->assertSame($length, $response->headers->get('Content-Length')); + $this->assertSame((string) $length, $response->headers->get('Content-Length')); } /** diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index ec9029c7d..1457ebd70 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -144,7 +144,8 @@ public function testUpdateTimestamp() { $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); $mock->expects($this->once()) - ->method('updateTimestamp'); + ->method('updateTimestamp') + ->willReturn(false); $proxy = new SessionHandlerProxy($mock); $proxy->updateTimestamp('id', 'data'); From d804bea118ff340a12e22a79f9c7e7eb56b35adc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Aug 2019 10:55:16 +0200 Subject: [PATCH 058/127] fix merge --- .../Handler/MigratingSessionHandler.php | 2 +- .../Storage/Handler/Fixtures/common.inc | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Session/Storage/Handler/MigratingSessionHandler.php b/Session/Storage/Handler/MigratingSessionHandler.php index 5293d2448..253d8cb68 100644 --- a/Session/Storage/Handler/MigratingSessionHandler.php +++ b/Session/Storage/Handler/MigratingSessionHandler.php @@ -61,7 +61,7 @@ public function destroy($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function gc($maxlifetime) { diff --git a/Tests/Session/Storage/Handler/Fixtures/common.inc b/Tests/Session/Storage/Handler/Fixtures/common.inc index 7a064c7f3..a887f607e 100644 --- a/Tests/Session/Storage/Handler/Fixtures/common.inc +++ b/Tests/Session/Storage/Handler/Fixtures/common.inc @@ -60,14 +60,14 @@ class TestSessionHandler extends AbstractSessionHandler $this->data = $data; } - public function open($path, $name) + public function open($path, $name): bool { echo __FUNCTION__, "\n"; return parent::open($path, $name); } - public function validateId($sessionId) + public function validateId($sessionId): bool { echo __FUNCTION__, "\n"; @@ -77,7 +77,7 @@ class TestSessionHandler extends AbstractSessionHandler /** * {@inheritdoc} */ - public function read($sessionId) + public function read($sessionId): string { echo __FUNCTION__, "\n"; @@ -87,7 +87,7 @@ class TestSessionHandler extends AbstractSessionHandler /** * {@inheritdoc} */ - public function updateTimestamp($sessionId, $data) + public function updateTimestamp($sessionId, $data): bool { echo __FUNCTION__, "\n"; @@ -97,7 +97,7 @@ class TestSessionHandler extends AbstractSessionHandler /** * {@inheritdoc} */ - public function write($sessionId, $data) + public function write($sessionId, $data): bool { echo __FUNCTION__, "\n"; @@ -107,42 +107,42 @@ class TestSessionHandler extends AbstractSessionHandler /** * {@inheritdoc} */ - public function destroy($sessionId) + public function destroy($sessionId): bool { echo __FUNCTION__, "\n"; return parent::destroy($sessionId); } - public function close() + public function close(): bool { echo __FUNCTION__, "\n"; return true; } - public function gc($maxLifetime) + public function gc($maxLifetime): bool { echo __FUNCTION__, "\n"; return true; } - protected function doRead($sessionId) + protected function doRead($sessionId): string { echo __FUNCTION__.': ', $this->data, "\n"; return $this->data; } - protected function doWrite($sessionId, $data) + protected function doWrite($sessionId, $data): bool { echo __FUNCTION__.': ', $data, "\n"; return true; } - protected function doDestroy($sessionId) + protected function doDestroy($sessionId): bool { echo __FUNCTION__, "\n"; From 5b4bb0d2930d8826adc3e638e273735926a030c3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 23 Aug 2019 15:32:15 +0200 Subject: [PATCH 059/127] Add return-types with help from DebugClassLoader in the CI --- Session/Storage/Handler/MongoDbSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index ad1bd24d4..27e080021 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -100,7 +100,7 @@ protected function doDestroy($sessionId) } /** - * @return int + * @return bool */ public function gc($maxlifetime) { From 4bd8415d6c3e8f1e2656e76fbad0b9fdddc82b25 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Aug 2019 17:52:30 +0200 Subject: [PATCH 060/127] [ErrorHandler] make DebugClassLoader turn multi-types declarations to "object" --- .../Session/Storage/Handler/RedisArraySessionHandlerTest.php | 5 ++++- .../Storage/Handler/RedisClusterSessionHandlerTest.php | 5 ++++- Tests/Session/Storage/Handler/RedisSessionHandlerTest.php | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php index b03a37236..3ef6cb694 100644 --- a/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php @@ -13,7 +13,10 @@ class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase { - protected function createRedisClient(string $host): \RedisArray + /** + * @return \RedisArray|object + */ + protected function createRedisClient(string $host) { return new \RedisArray([$host]); } diff --git a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php index c1ba70dcb..8b4cd1cdd 100644 --- a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php @@ -24,7 +24,10 @@ public static function setUpBeforeClass(): void } } - protected function createRedisClient(string $host): \RedisCluster + /** + * @return \RedisCluster|object + */ + protected function createRedisClient(string $host) { return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS'))); } diff --git a/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php index afdb6c503..71658f072 100644 --- a/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php @@ -13,7 +13,10 @@ class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { - protected function createRedisClient(string $host): \Redis + /** + * @return \Redis|object + */ + protected function createRedisClient(string $host) { $client = new \Redis(); $client->connect($host); From 089da40dfa1e5f0a89f29619a1337a64d88e08f9 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 27 Aug 2019 10:31:03 +0200 Subject: [PATCH 061/127] Return null as Expire header if it was set to null --- HeaderBag.php | 10 +++++++++- Tests/HeaderBagTest.php | 10 ++++++++++ Tests/ResponseTest.php | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/HeaderBag.php b/HeaderBag.php index 08299977c..35bd6ad8f 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -121,7 +121,15 @@ public function get($key, $default = null, $first = true) } if ($first) { - return \count($headers[$key]) ? (string) $headers[$key][0] : $default; + if (!$headers[$key]) { + return $default; + } + + if (null === $headers[$key][0]) { + return null; + } + + return (string) $headers[$key][0]; } return $headers[$key]; diff --git a/Tests/HeaderBagTest.php b/Tests/HeaderBagTest.php index a5876f9e3..dcc266f69 100644 --- a/Tests/HeaderBagTest.php +++ b/Tests/HeaderBagTest.php @@ -48,6 +48,13 @@ public function testGetDate() $this->assertInstanceOf('DateTime', $headerDate); } + public function testGetDateNull() + { + $bag = new HeaderBag(['foo' => null]); + $headerDate = $bag->getDate('foo'); + $this->assertNull($headerDate); + } + public function testGetDateException() { $this->expectException('RuntimeException'); @@ -96,6 +103,9 @@ public function testGet() $bag->set('foo', 'bor', false); $this->assertEquals('bar', $bag->get('foo'), '->get return first value'); $this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array'); + + $bag->set('baz', null); + $this->assertNull($bag->get('baz', 'nope'), '->get return null although different default value is given'); } public function testSetAssociativeArray() diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index c61dbacdd..b846cdad3 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -369,6 +369,12 @@ public function testExpire() $this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh'); } + public function testNullExpireHeader() + { + $response = new Response(null, 200, ['Expires' => null]); + $this->assertNull($response->getExpires()); + } + public function testGetTtl() { $response = new Response(); From df7421ae2eb01af58afc98087e3984cef4f323ec Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 1 Sep 2019 18:05:42 +0200 Subject: [PATCH 062/127] [HttpFoundation] Add types to private/final/internal methods and constructors. --- Request.php | 16 +++++++--------- Session/SessionBagProxy.php | 2 +- Test/Constraint/RequestAttributeValueSame.php | 1 + Test/Constraint/ResponseHasCookie.php | 2 +- Tests/RequestTest.php | 4 ++-- Tests/ResponseHeaderBagTest.php | 2 +- .../Handler/MongoDbSessionHandlerTest.php | 2 +- .../Storage/Handler/PdoSessionHandlerTest.php | 5 ++++- .../Storage/MockFileSessionStorageTest.php | 2 +- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Request.php b/Request.php index 866fea4fb..4510f7c52 100644 --- a/Request.php +++ b/Request.php @@ -1817,12 +1817,12 @@ protected function prepareBaseUrl() $requestUri = '/'.$requestUri; } - if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) { + if ($baseUrl && null !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) { // full $baseUrl matches return $prefix; } - if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(\dirname($baseUrl), '/'.\DIRECTORY_SEPARATOR).'/')) { + if ($baseUrl && null !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(\dirname($baseUrl), '/'.\DIRECTORY_SEPARATOR).'/')) { // directory portion of $baseUrl matches return rtrim($prefix, '/'.\DIRECTORY_SEPARATOR); } @@ -1941,14 +1941,12 @@ private function setPhpDefaultLocale(string $locale): void /** * Returns the prefix as encoded in the string when the string starts with - * the given prefix, false otherwise. - * - * @return string|false The prefix as it is encoded in $string, or false + * the given prefix, null otherwise. */ - private function getUrlencodedPrefix(string $string, string $prefix) + private function getUrlencodedPrefix(string $string, string $prefix): ?string { if (0 !== strpos(rawurldecode($string), $prefix)) { - return false; + return null; } $len = \strlen($prefix); @@ -1957,10 +1955,10 @@ private function getUrlencodedPrefix(string $string, string $prefix) return $match[0]; } - return false; + return null; } - private static function createRequestFromFactory(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null) + private static function createRequestFromFactory(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null): self { if (self::$requestFactory) { $request = (self::$requestFactory)($query, $request, $attributes, $cookies, $files, $server, $content); diff --git a/Session/SessionBagProxy.php b/Session/SessionBagProxy.php index 09df1426e..0ae8231ef 100644 --- a/Session/SessionBagProxy.php +++ b/Session/SessionBagProxy.php @@ -22,7 +22,7 @@ final class SessionBagProxy implements SessionBagInterface private $data; private $usageIndex; - public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex) + public function __construct(SessionBagInterface $bag, array &$data, ?int &$usageIndex) { $this->bag = $bag; $this->data = &$data; diff --git a/Test/Constraint/RequestAttributeValueSame.php b/Test/Constraint/RequestAttributeValueSame.php index 2d1056278..cb216ea12 100644 --- a/Test/Constraint/RequestAttributeValueSame.php +++ b/Test/Constraint/RequestAttributeValueSame.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Test\Constraint; use PHPUnit\Framework\Constraint\Constraint; +use Symfony\Component\HttpFoundation\Request; final class RequestAttributeValueSame extends Constraint { diff --git a/Test/Constraint/ResponseHasCookie.php b/Test/Constraint/ResponseHasCookie.php index bd792b0d8..eae9e271b 100644 --- a/Test/Constraint/ResponseHasCookie.php +++ b/Test/Constraint/ResponseHasCookie.php @@ -64,7 +64,7 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - protected function getCookie(Response $response): ?Cookie + private function getCookie(Response $response): ?Cookie { $cookies = $response->headers->getCookies(); diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index f13582deb..8febdf629 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -1803,7 +1803,7 @@ private function disableHttpMethodParameterOverride() $property->setValue(false); } - private function getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies) + private function getRequestInstanceForClientIpTests(string $remoteAddr, ?string $httpForwardedFor, ?array $trustedProxies): Request { $request = new Request(); @@ -1821,7 +1821,7 @@ private function getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedF return $request; } - private function getRequestInstanceForClientIpsForwardedTests($remoteAddr, $httpForwarded, $trustedProxies) + private function getRequestInstanceForClientIpsForwardedTests(string $remoteAddr, ?string $httpForwarded, ?array $trustedProxies): Request { $request = new Request(); diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index d9e73499a..1a3817333 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -299,7 +299,7 @@ public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced() $this->assertTrue($bag->has('Date')); } - private function assertSetCookieHeader($expected, ResponseHeaderBag $actual) + private function assertSetCookieHeader(string $expected, ResponseHeaderBag $actual) { $this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual)); } diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index f956fa276..0adabc02c 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -197,7 +197,7 @@ public function testGetConnection() $this->assertInstanceOf(\MongoDB\Client::class, $method->invoke($this->storage)); } - private function createMongoCollectionMock() + private function createMongoCollectionMock(): \MongoDB\Collection { $collection = $this->getMockBuilder(\MongoDB\Collection::class) ->disableOriginalConstructor() diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index d080ce3ca..b8c097763 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -346,6 +346,9 @@ public function provideUrlDsnPairs() yield ['mssql://localhost:56/test', 'sqlsrv:server=localhost,56;Database=test']; } + /** + * @return resource + */ private function createStream($content) { $stream = tmpfile(); @@ -362,7 +365,7 @@ class MockPdo extends \PDO private $driverName; private $errorMode; - public function __construct($driverName = null, $errorMode = null) + public function __construct(string $driverName = null, int $errorMode = null) { $this->driverName = $driverName; $this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION; diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index d9314075a..2231bda85 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -114,7 +114,7 @@ public function testSaveWithoutStart() $storage1->save(); } - private function getStorage() + private function getStorage(): MockFileSessionStorage { $storage = new MockFileSessionStorage($this->sessionDir); $storage->registerBag(new FlashBag()); From b90f3d5f9c3397e8b693d7c8acdeff8de0aef4cc Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 5 Sep 2019 17:26:55 +0200 Subject: [PATCH 063/127] Adding .gitattributes to remove Tests directory from "dist" --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..aa02dc651 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore From ec2a74a7c858640acaebd11a9ebc2a8f6662f7aa Mon Sep 17 00:00:00 2001 From: mmokhi Date: Wed, 11 Sep 2019 11:18:08 +0200 Subject: [PATCH 064/127] Call AssertEquals with proper parameters Since `$response->getContent()` returns string and our first parameter is already string as well, in some cases (with different precisions) it may "compare strings" as "strings" and this is not what the test wants. By changing the first parameter to actual number we force `AssertEquals` to compare them numerically rather than literally by string content. --- Tests/JsonResponseTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/JsonResponseTest.php b/Tests/JsonResponseTest.php index fd045fb9c..9642dc28d 100644 --- a/Tests/JsonResponseTest.php +++ b/Tests/JsonResponseTest.php @@ -52,7 +52,7 @@ public function testConstructorWithSimpleTypes() $this->assertSame('0', $response->getContent()); $response = new JsonResponse(0.1); - $this->assertEquals('0.1', $response->getContent()); + $this->assertEquals(0.1, $response->getContent()); $this->assertIsString($response->getContent()); $response = new JsonResponse(true); @@ -141,7 +141,7 @@ public function testStaticCreateWithSimpleTypes() $response = JsonResponse::create(0.1); $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); - $this->assertEquals('0.1', $response->getContent()); + $this->assertEquals(0.1, $response->getContent()); $this->assertIsString($response->getContent()); $response = JsonResponse::create(true); From 876ee3475faa4a3ad38686e2d92ddfa922ed64ba Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Fri, 13 Sep 2019 17:45:08 +0300 Subject: [PATCH 065/127] Replace REMOTE_ADDR in trusted proxies with the current REMOTE_ADDR --- Request.php | 12 ++++++++++-- Tests/RequestTest.php | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Request.php b/Request.php index 4510f7c52..4fae46cb6 100644 --- a/Request.php +++ b/Request.php @@ -567,14 +567,22 @@ public function overrideGlobals() * * You should only list the reverse proxies that you manage directly. * - * @param array $proxies A list of trusted proxies + * @param array $proxies A list of trusted proxies, the string 'REMOTE_ADDR' will be replaced with $_SERVER['REMOTE_ADDR'] * @param int $trustedHeaderSet A bit field of Request::HEADER_*, to set which headers to trust from your proxies * * @throws \InvalidArgumentException When $trustedHeaderSet is invalid */ public static function setTrustedProxies(array $proxies, int $trustedHeaderSet) { - self::$trustedProxies = $proxies; + self::$trustedProxies = array_reduce($proxies, function ($proxies, $proxy) { + if ('REMOTE_ADDR' !== $proxy) { + $proxies[] = $proxy; + } elseif (isset($_SERVER['REMOTE_ADDR'])) { + $proxies[] = $_SERVER['REMOTE_ADDR']; + } + + return $proxies; + }, []); self::$trustedHeaderSet = $trustedHeaderSet; } diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 8febdf629..1d0164725 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2324,6 +2324,26 @@ public function testTrustedPortDoesNotDefaultToZero() $this->assertSame(80, $request->getPort()); } + + /** + * @dataProvider trustedProxiesRemoteAddr + */ + public function testTrustedProxiesRemoteAddr($serverRemoteAddr, $trustedProxies, $result) + { + $_SERVER['REMOTE_ADDR'] = $serverRemoteAddr; + Request::setTrustedProxies($trustedProxies, Request::HEADER_X_FORWARDED_ALL); + $this->assertSame($result, Request::getTrustedProxies()); + } + + public function trustedProxiesRemoteAddr() + { + return [ + ['1.1.1.1', ['REMOTE_ADDR'], ['1.1.1.1']], + ['1.1.1.1', ['REMOTE_ADDR', '2.2.2.2'], ['1.1.1.1', '2.2.2.2']], + [null, ['REMOTE_ADDR'], []], + [null, ['REMOTE_ADDR', '2.2.2.2'], ['2.2.2.2']], + ]; + } } class RequestContentProxy extends Request From 4b0a75e9155bb5fe5cfcc52d9e90fc1920b8cae2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 30 Jul 2018 18:06:05 +0200 Subject: [PATCH 066/127] [Security] Make stateful firewalls turn responses private only when needed --- Session/Session.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Session/Session.php b/Session/Session.php index 9738189b4..2192c629e 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -136,10 +136,7 @@ public function count() return \count($this->getAttributeBag()->all()); } - /** - * @internal - */ - public function getUsageIndex(): int + public function &getUsageIndex(): int { return $this->usageIndex; } From b93f93694cf554eccdb1daaa40796485933ebf71 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 26 Sep 2019 19:03:18 +0200 Subject: [PATCH 067/127] [HttpFoundation] optimize normalization of headers --- HeaderBag.php | 13 +++++++------ Request.php | 2 +- ResponseHeaderBag.php | 8 ++++---- ServerBag.php | 5 +---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/HeaderBag.php b/HeaderBag.php index 5cfa5313a..9ffe6f4fe 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -18,6 +18,9 @@ */ class HeaderBag implements \IteratorAggregate, \Countable { + protected const UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + protected const LOWER = '-abcdefghijklmnopqrstuvwxyz'; + protected $headers = []; protected $cacheControl = []; @@ -62,9 +65,7 @@ public function __toString() public function all(/*string $key = null*/) { if (1 <= \func_num_args() && null !== $key = func_get_arg(0)) { - $key = str_replace('_', '-', strtolower($key)); - - return $this->headers[$key] ?? []; + return $this->headers[strtr($key, self::UPPER, self::LOWER)] ?? []; } return $this->headers; @@ -138,7 +139,7 @@ public function get($key, $default = null) */ public function set($key, $values, $replace = true) { - $key = str_replace('_', '-', strtolower($key)); + $key = strtr($key, self::UPPER, self::LOWER); if (\is_array($values)) { $values = array_values($values); @@ -170,7 +171,7 @@ public function set($key, $values, $replace = true) */ public function has($key) { - return \array_key_exists(str_replace('_', '-', strtolower($key)), $this->all()); + return \array_key_exists(strtr($key, self::UPPER, self::LOWER), $this->all()); } /** @@ -193,7 +194,7 @@ public function contains($key, $value) */ public function remove($key) { - $key = str_replace('_', '-', strtolower($key)); + $key = strtr($key, self::UPPER, self::LOWER); unset($this->headers[$key]); diff --git a/Request.php b/Request.php index 4510f7c52..fe0f6de23 100644 --- a/Request.php +++ b/Request.php @@ -541,7 +541,7 @@ public function overrideGlobals() foreach ($this->headers->all() as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); - if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { + if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true)) { $_SERVER[$key] = implode(', ', $value); } else { $_SERVER['HTTP_'.$key] = implode(', ', $value); diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index 79f58eb86..f5b7a27fd 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -51,7 +51,7 @@ public function allPreserveCase() { $headers = []; foreach ($this->all() as $name => $value) { - $headers[isset($this->headerNames[$name]) ? $this->headerNames[$name] : $name] = $value; + $headers[$this->headerNames[$name] ?? $name] = $value; } return $headers; @@ -95,7 +95,7 @@ public function all(/*string $key = null*/) $headers = parent::all(); if (1 <= \func_num_args() && null !== $key = func_get_arg(0)) { - $key = str_replace('_', '-', strtolower($key)); + $key = strtr($key, self::UPPER, self::LOWER); return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies()); } @@ -112,7 +112,7 @@ public function all(/*string $key = null*/) */ public function set($key, $values, $replace = true) { - $uniqueKey = str_replace('_', '-', strtolower($key)); + $uniqueKey = strtr($key, self::UPPER, self::LOWER); if ('set-cookie' === $uniqueKey) { if ($replace) { @@ -143,7 +143,7 @@ public function set($key, $values, $replace = true) */ public function remove($key) { - $uniqueKey = str_replace('_', '-', strtolower($key)); + $uniqueKey = strtr($key, self::UPPER, self::LOWER); unset($this->headerNames[$uniqueKey]); if ('set-cookie' === $uniqueKey) { diff --git a/ServerBag.php b/ServerBag.php index 4c82b1774..25da35ec5 100644 --- a/ServerBag.php +++ b/ServerBag.php @@ -28,13 +28,10 @@ class ServerBag extends ParameterBag public function getHeaders() { $headers = []; - $contentHeaders = ['CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true]; foreach ($this->parameters as $key => $value) { if (0 === strpos($key, 'HTTP_')) { $headers[substr($key, 5)] = $value; - } - // CONTENT_* are not prefixed with HTTP_ - elseif (isset($contentHeaders[$key])) { + } elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true)) { $headers[$key] = $value; } } From 35ffbbfa73e46e28a9433692cd6c404de70e6c4c Mon Sep 17 00:00:00 2001 From: marie <15118505+marie@users.noreply.github.com> Date: Fri, 20 Sep 2019 15:03:12 +0500 Subject: [PATCH 068/127] [HttpFoundation] allow additinal characters in not raw cookies --- Cookie.php | 21 +++++++++++++---- Response.php | 2 +- Tests/CookieTest.php | 23 +++++++++++++++---- .../cookie_urlencode.expected | 3 ++- .../response-functional/cookie_urlencode.php | 9 +++++--- .../invalid_cookie_name.php | 2 +- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Cookie.php b/Cookie.php index 83a97087f..98a5ef00a 100644 --- a/Cookie.php +++ b/Cookie.php @@ -18,6 +18,10 @@ */ class Cookie { + const SAMESITE_NONE = 'none'; + const SAMESITE_LAX = 'lax'; + const SAMESITE_STRICT = 'strict'; + protected $name; protected $value; protected $domain; @@ -25,12 +29,13 @@ class Cookie protected $path; protected $secure; protected $httpOnly; + private $raw; private $sameSite; - const SAMESITE_NONE = 'none'; - const SAMESITE_LAX = 'lax'; - const SAMESITE_STRICT = 'strict'; + private static $reservedCharsList = "=,; \t\r\n\v\f"; + private static $reservedCharsFrom = ['=', ',', ';', ' ', "\t", "\r", "\n", "\v", "\f"]; + private static $reservedCharsTo = ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C']; /** * Creates cookie from raw header string. @@ -97,7 +102,7 @@ public static function fromString($cookie, $decode = false) public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true, $raw = false, $sameSite = null) { // from PHP source code - if (preg_match("/[=,; \t\r\n\013\014]/", $name)) { + if ($raw && false !== strpbrk($name, self::$reservedCharsList)) { throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name)); } @@ -143,7 +148,13 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom */ public function __toString() { - $str = ($this->isRaw() ? $this->getName() : urlencode($this->getName())).'='; + if ($this->isRaw()) { + $str = $this->getName(); + } else { + $str = str_replace(self::$reservedCharsFrom, self::$reservedCharsTo, $this->getName()); + } + + $str .= '='; if ('' === (string) $this->getValue()) { $str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0'; diff --git a/Response.php b/Response.php index 8a17acdd5..26e3a3378 100644 --- a/Response.php +++ b/Response.php @@ -342,7 +342,7 @@ public function sendHeaders() // cookies foreach ($this->headers->getCookies() as $cookie) { - header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='), false, $this->statusCode); + header('Set-Cookie: '.$cookie, false, $this->statusCode); } // status diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index 38c195df3..169f91787 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -24,10 +24,9 @@ */ class CookieTest extends TestCase { - public function invalidNames() + public function namesWithSpecialCharacters() { return [ - [''], [',MyName'], [';MyName'], [' MyName'], @@ -40,12 +39,26 @@ public function invalidNames() } /** - * @dataProvider invalidNames + * @dataProvider namesWithSpecialCharacters */ - public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name) + public function testInstantiationThrowsExceptionIfRawCookieNameContainsSpecialCharacters($name) { $this->expectException('InvalidArgumentException'); - new Cookie($name); + new Cookie($name, null, 0, null, null, null, false, true); + } + + /** + * @dataProvider namesWithSpecialCharacters + */ + public function testInstantiationSucceedNonRawCookieNameContainsSpecialCharacters($name) + { + $this->assertInstanceOf(Cookie::class, new Cookie($name)); + } + + public function testInstantiationThrowsExceptionIfCookieNameIsEmpty() + { + $this->expectException('InvalidArgumentException'); + new Cookie(''); } public function testInvalidExpiration() diff --git a/Tests/Fixtures/response-functional/cookie_urlencode.expected b/Tests/Fixtures/response-functional/cookie_urlencode.expected index 14e44a398..17a9efc66 100644 --- a/Tests/Fixtures/response-functional/cookie_urlencode.expected +++ b/Tests/Fixtures/response-functional/cookie_urlencode.expected @@ -4,7 +4,8 @@ Array [0] => Content-Type: text/plain; charset=utf-8 [1] => Cache-Control: no-cache, private [2] => Date: Sat, 12 Nov 1955 20:04:00 GMT - [3] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/ + [3] => Set-Cookie: %3D%2C%3B%20%09%0D%0A%0B%0C=%3D%2C%3B%20%09%0D%0A%0B%0C; path=/ [4] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/ + [5] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/ ) shutdown diff --git a/Tests/Fixtures/response-functional/cookie_urlencode.php b/Tests/Fixtures/response-functional/cookie_urlencode.php index 05b9af30d..9ffb0dfec 100644 --- a/Tests/Fixtures/response-functional/cookie_urlencode.php +++ b/Tests/Fixtures/response-functional/cookie_urlencode.php @@ -4,9 +4,12 @@ $r = require __DIR__.'/common.inc'; -$str = '?*():@&+$/%#[]'; +$str1 = "=,; \t\r\n\v\f"; +$r->headers->setCookie(new Cookie($str1, $str1, 0, '', null, false, false, false, null)); -$r->headers->setCookie(new Cookie($str, $str, 0, '', null, false, false)); +$str2 = '?*():@&+$/%#[]'; + +$r->headers->setCookie(new Cookie($str2, $str2, 0, '', null, false, false, false, null)); $r->sendHeaders(); -setcookie($str, $str, 0, '/'); +setcookie($str2, $str2, 0, '/'); diff --git a/Tests/Fixtures/response-functional/invalid_cookie_name.php b/Tests/Fixtures/response-functional/invalid_cookie_name.php index 3fe157184..3acf86039 100644 --- a/Tests/Fixtures/response-functional/invalid_cookie_name.php +++ b/Tests/Fixtures/response-functional/invalid_cookie_name.php @@ -5,7 +5,7 @@ $r = require __DIR__.'/common.inc'; try { - $r->headers->setCookie(new Cookie('Hello + world', 'hodor')); + $r->headers->setCookie(new Cookie('Hello + world', 'hodor', 0, null, null, null, false, true)); } catch (\InvalidArgumentException $e) { echo $e->getMessage(); } From 233f40cbebd595ffd91ddf291355f8a930a13777 Mon Sep 17 00:00:00 2001 From: bogdan Date: Wed, 2 Oct 2019 18:28:34 +0300 Subject: [PATCH 069/127] [HttpFoundation] Check if data passed to SessionBagProxy::initialize is an array --- Session/Storage/NativeSessionStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 4f1c30ef5..4c5873728 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -430,7 +430,7 @@ protected function loadSession(array &$session = null) foreach ($bags as $bag) { $key = $bag->getStorageKey(); - $session[$key] = isset($session[$key]) ? $session[$key] : []; + $session[$key] = isset($session[$key]) && \is_array($session[$key]) ? $session[$key] : []; $bag->initialize($session[$key]); } From 3daf488b5833a9bd7cfb4b34bcdaba1b0f0b398d Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 12 Oct 2019 01:27:05 +0100 Subject: [PATCH 070/127] Add .gitignore to .gitattributes --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index aa02dc651..ebb928704 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ /Tests export-ignore /phpunit.xml.dist export-ignore +/.gitignore export-ignore From 4db558c7c6777aac02293efbfe7c7c5d4c1385c3 Mon Sep 17 00:00:00 2001 From: Ilia Lazarev Date: Sat, 12 Oct 2019 10:36:35 +0300 Subject: [PATCH 071/127] Add plus character `+` to legal mime subtype For example, the following mime type (used for epub) is not recognized given the current regexp: `application/epub+zip` --- File/MimeType/FileBinaryMimeTypeGuesser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/File/MimeType/FileBinaryMimeTypeGuesser.php b/File/MimeType/FileBinaryMimeTypeGuesser.php index b75242afd..cfa76843c 100644 --- a/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -89,7 +89,7 @@ public function guess($path) $type = trim(ob_get_clean()); - if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) { + if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) { // it's not a type, but an error message return null; } From 7b4626ab40d8562707e6d1c9a6fab977a86c2037 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 24 Oct 2019 14:44:17 +0200 Subject: [PATCH 072/127] Remove unused local variables in tests --- Tests/File/UploadedFileTest.php | 2 +- Tests/HeaderBagTest.php | 2 +- Tests/RedirectResponseTest.php | 4 ++-- .../Storage/Handler/NativeFileSessionHandlerTest.php | 6 +++--- Tests/Session/Storage/Handler/NullSessionHandlerTest.php | 2 +- Tests/Session/Storage/Handler/PdoSessionHandlerTest.php | 2 +- Tests/Session/Storage/NativeSessionStorageTest.php | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 4186c72a6..2ea924bac 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -153,7 +153,7 @@ public function testMoveLocalFileIsNotAllowed() UPLOAD_ERR_OK ); - $movedFile = $file->move(__DIR__.'/Fixtures/directory'); + $file->move(__DIR__.'/Fixtures/directory'); } public function testMoveLocalFileIsAllowedInTestMode() diff --git a/Tests/HeaderBagTest.php b/Tests/HeaderBagTest.php index dcc266f69..cabe038bd 100644 --- a/Tests/HeaderBagTest.php +++ b/Tests/HeaderBagTest.php @@ -59,7 +59,7 @@ public function testGetDateException() { $this->expectException('RuntimeException'); $bag = new HeaderBag(['foo' => 'Tue']); - $headerDate = $bag->getDate('foo'); + $bag->getDate('foo'); } public function testGetCacheControlHeader() diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index 92f4876da..e1ff3bf2b 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -29,13 +29,13 @@ public function testGenerateMetaRedirect() public function testRedirectResponseConstructorNullUrl() { $this->expectException('InvalidArgumentException'); - $response = new RedirectResponse(null); + new RedirectResponse(null); } public function testRedirectResponseConstructorWrongStatusCode() { $this->expectException('InvalidArgumentException'); - $response = new RedirectResponse('foo.bar', 404); + new RedirectResponse('foo.bar', 404); } public function testGenerateLocationHeader() diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 9daf1a0ee..7de55798a 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -41,7 +41,7 @@ public function testConstruct() */ public function testConstructSavePath($savePath, $expectedSavePath, $path) { - $handler = new NativeFileSessionHandler($savePath); + new NativeFileSessionHandler($savePath); $this->assertEquals($expectedSavePath, ini_get('session.save_path')); $this->assertDirectoryExists(realpath($path)); @@ -62,13 +62,13 @@ public function savePathDataProvider() public function testConstructException() { $this->expectException('InvalidArgumentException'); - $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args'); + new NativeFileSessionHandler('something;invalid;with;too-many-args'); } public function testConstructDefault() { $path = ini_get('session.save_path'); - $storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler()); + new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler()); $this->assertEquals($path, ini_get('session.save_path')); } diff --git a/Tests/Session/Storage/Handler/NullSessionHandlerTest.php b/Tests/Session/Storage/Handler/NullSessionHandlerTest.php index 0d246e1aa..f793db144 100644 --- a/Tests/Session/Storage/Handler/NullSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NullSessionHandlerTest.php @@ -28,7 +28,7 @@ class NullSessionHandlerTest extends TestCase { public function testSaveHandlers() { - $storage = $this->getStorage(); + $this->getStorage(); $this->assertEquals('user', ini_get('session.save_handler')); } diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 123b605d2..e710dca92 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -54,7 +54,7 @@ public function testWrongPdoErrMode() $pdo = $this->getMemorySqlitePdo(); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); - $storage = new PdoSessionHandler($pdo); + new PdoSessionHandler($pdo); } public function testInexistentTable() diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index fa170d17d..9ce8108da 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -145,7 +145,7 @@ public function testDefaultSessionCacheLimiter() { $this->iniSet('session.cache_limiter', 'nocache'); - $storage = new NativeSessionStorage(); + new NativeSessionStorage(); $this->assertEquals('', ini_get('session.cache_limiter')); } @@ -153,7 +153,7 @@ public function testExplicitSessionCacheLimiter() { $this->iniSet('session.cache_limiter', 'nocache'); - $storage = new NativeSessionStorage(['cache_limiter' => 'public']); + new NativeSessionStorage(['cache_limiter' => 'public']); $this->assertEquals('public', ini_get('session.cache_limiter')); } From 9a98f1393ea8f7c42296c55e86b03ee683ed47cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 29 Oct 2019 14:42:59 +0100 Subject: [PATCH 073/127] [HttpFoundation] Allow to not pass a parameter to Request::isMethodSafe() --- Request.php | 7 ++----- Tests/RequestTest.php | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Request.php b/Request.php index 9af2c2825..db82ffce8 100644 --- a/Request.php +++ b/Request.php @@ -1447,14 +1447,11 @@ public function isMethod($method) * * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 * - * @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default. - * * @return bool */ - public function isMethodSafe(/* $andCacheable = true */) + public function isMethodSafe() { - if (!\func_num_args() || func_get_arg(0)) { - // setting $andCacheable to false should be deprecated in 4.1 + if (\func_num_args() > 0 && func_get_arg(0)) { throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.'); } diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index d56ef3147..03493b532 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -2132,7 +2132,7 @@ public function testMethodSafeChecksCacheable() $this->expectException('BadMethodCallException'); $request = new Request(); $request->setMethod('OPTIONS'); - $request->isMethodSafe(); + $request->isMethodSafe(true); } /** From e601eebb39e8a727d03873695b52a874835f46b5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 29 Oct 2019 19:32:01 +0100 Subject: [PATCH 074/127] [HttpFoundation][FrameworkBundle] allow configuring the session handler with a DSN --- CHANGELOG.md | 1 + .../Storage/Handler/SessionHandlerFactory.php | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Session/Storage/Handler/SessionHandlerFactory.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 577f27e6c..10eaa0ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * `PdoSessionHandler` now precalculates the expiry timestamp in the lifetime column, make sure to run `CREATE INDEX EXPIRY ON sessions (sess_lifetime)` to update your database to speed up garbage collection of expired sessions. + * added `SessionHandlerFactory` to create session handlers with a DSN 4.3.0 ----- diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php new file mode 100644 index 000000000..41dba3a2b --- /dev/null +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -0,0 +1,84 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; + +use Doctrine\DBAL\DriverManager; +use Symfony\Component\Cache\Adapter\AbstractAdapter; +use Symfony\Component\Cache\Traits\RedisClusterProxy; +use Symfony\Component\Cache\Traits\RedisProxy; + +/** + * @author Nicolas Grekas + */ +class SessionHandlerFactory +{ + /** + * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy|\Memcached|\PDO|string $connection Connection or DSN + */ + public static function createHandler($connection): AbstractSessionHandler + { + if (!\is_string($connection) && !\is_object($connection)) { + throw new \TypeError(sprintf('Argument 1 passed to %s() must be a string or a connection object, %s given.', __METHOD__, \gettype($connection))); + } + + switch (true) { + case $connection instanceof \Redis: + case $connection instanceof \RedisArray: + case $connection instanceof \RedisCluster: + case $connection instanceof \Predis\ClientInterface: + case $connection instanceof RedisProxy: + case $connection instanceof RedisClusterProxy: + return new RedisSessionHandler($connection); + + case $connection instanceof \Memcached: + return new MemcachedSessionHandler($connection); + + case $connection instanceof \PDO: + return new PdoSessionHandler($connection); + + case !\is_string($connection): + throw new \InvalidArgumentException(sprintf('Unsupported Connection: %s.', \get_class($connection))); + case 0 === strpos($connection, 'file://'): + return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7))); + + case 0 === strpos($connection, 'redis://'): + case 0 === strpos($connection, 'rediss://'): + case 0 === strpos($connection, 'memcached://'): + if (!class_exists(AbstractAdapter::class)) { + throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $this->dsn)); + } + $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); + + return 0 === strpos($connection, 'memcached://') ? new MemcachedSessionHandler($connection) : new RedisSessionHandler($connection); + + case 0 === strpos($connection, 'pdo_oci://'): + if (!class_exists(DriverManager::class)) { + throw new \InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require doctrine/dbal".', $connection)); + } + $connection = DriverManager::getConnection(['url' => $connection])->getWrappedConnection(); + // no break; + + case 0 === strpos($connection, 'mssql://'): + case 0 === strpos($connection, 'mysql://'): + case 0 === strpos($connection, 'mysql2://'): + case 0 === strpos($connection, 'pgsql://'): + case 0 === strpos($connection, 'postgres://'): + case 0 === strpos($connection, 'postgresql://'): + case 0 === strpos($connection, 'sqlsrv://'): + case 0 === strpos($connection, 'sqlite://'): + case 0 === strpos($connection, 'sqlite3://'): + return new PdoSessionHandler($connection); + } + + throw new \InvalidArgumentException(sprintf('Unsupported Connection: %s.', $connection)); + } +} From 38f63e471cda9d37ac06e76d14c5ea2ec5887051 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Tue, 29 Oct 2019 19:32:45 +0100 Subject: [PATCH 075/127] [4.3] Remove unused local variables --- Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 347619e96..368af6a3e 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -27,7 +27,7 @@ class NativeFileSessionHandlerTest extends TestCase { public function testConstruct() { - $storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir())); + new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir())); $this->assertEquals('user', ini_get('session.save_handler')); From 6590972d2a2642070bf34f814b9be11eef3f04f7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Oct 2019 14:14:20 +0100 Subject: [PATCH 076/127] [Lock][HttpFoundation] Hot fix --- Session/Storage/Handler/SessionHandlerFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index 41dba3a2b..e7acf5173 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -56,9 +56,10 @@ public static function createHandler($connection): AbstractSessionHandler if (!class_exists(AbstractAdapter::class)) { throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $this->dsn)); } + $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); - return 0 === strpos($connection, 'memcached://') ? new MemcachedSessionHandler($connection) : new RedisSessionHandler($connection); + return new $handlerClass($connection); case 0 === strpos($connection, 'pdo_oci://'): if (!class_exists(DriverManager::class)) { From a5d46a33e8649ba802cebe520d188b04385572a2 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Sun, 3 Nov 2019 03:12:45 +0100 Subject: [PATCH 077/127] Fix MockFileSessionStorageTest::sessionDir being used after it's unset --- Tests/Session/Storage/MockFileSessionStorageTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Session/Storage/MockFileSessionStorageTest.php b/Tests/Session/Storage/MockFileSessionStorageTest.php index b316c83e6..d6bd1823f 100644 --- a/Tests/Session/Storage/MockFileSessionStorageTest.php +++ b/Tests/Session/Storage/MockFileSessionStorageTest.php @@ -41,12 +41,12 @@ protected function setUp() protected function tearDown() { - $this->sessionDir = null; - $this->storage = null; - array_map('unlink', glob($this->sessionDir.'/*.session')); + array_map('unlink', glob($this->sessionDir.'/*')); if (is_dir($this->sessionDir)) { rmdir($this->sessionDir); } + $this->sessionDir = null; + $this->storage = null; } public function testStart() From 2c367a65b40f034830cb4bb1603926c3c46fbd82 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 26 Jun 2019 16:20:24 +0200 Subject: [PATCH 078/127] [HttpFoundation] Add a way to anonymize IPs --- CHANGELOG.md | 3 ++- IpUtils.php | 32 ++++++++++++++++++++++++++++++++ Tests/IpUtilsTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10eaa0ac5..e33b33ccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ CHANGELOG make sure to run `CREATE INDEX EXPIRY ON sessions (sess_lifetime)` to update your database to speed up garbage collection of expired sessions. * added `SessionHandlerFactory` to create session handlers with a DSN - + * added `IpUtils::anonymize()` to help with GDPR compliance. + 4.3.0 ----- diff --git a/IpUtils.php b/IpUtils.php index 67d13e57a..72c53a471 100644 --- a/IpUtils.php +++ b/IpUtils.php @@ -153,4 +153,36 @@ public static function checkIp6($requestIp, $ip) return self::$checkedIps[$cacheKey] = true; } + + /** + * Anonymizes an IP/IPv6. + * + * Removes the last byte for v4 and the last 8 bytes for v6 IPs + */ + public static function anonymize(string $ip): string + { + $wrappedIPv6 = false; + if ('[' === substr($ip, 0, 1) && ']' === substr($ip, -1, 1)) { + $wrappedIPv6 = true; + $ip = substr($ip, 1, -1); + } + + $packedAddress = inet_pton($ip); + if (4 === \strlen($packedAddress)) { + $mask = '255.255.255.0'; + } elseif ($ip === inet_ntop($packedAddress & inet_pton('::ffff:ffff:ffff'))) { + $mask = '::ffff:ffff:ff00'; + } elseif ($ip === inet_ntop($packedAddress & inet_pton('::ffff:ffff'))) { + $mask = '::ffff:ff00'; + } else { + $mask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000'; + } + $ip = inet_ntop($packedAddress & inet_pton($mask)); + + if ($wrappedIPv6) { + $ip = '['.$ip.']'; + } + + return $ip; + } } diff --git a/Tests/IpUtilsTest.php b/Tests/IpUtilsTest.php index d3b262e04..13b574379 100644 --- a/Tests/IpUtilsTest.php +++ b/Tests/IpUtilsTest.php @@ -101,4 +101,30 @@ public function invalidIpAddressData() 'invalid request IP with invalid proxy wildcard' => ['0.0.0.0', '*'], ]; } + + /** + * @dataProvider anonymizedIpData + */ + public function testAnonymize($ip, $expected) + { + $this->assertSame($expected, IpUtils::anonymize($ip)); + } + + public function anonymizedIpData() + { + return [ + ['192.168.1.1', '192.168.1.0'], + ['1.2.3.4', '1.2.3.0'], + ['2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603::'], + ['2a01:198:603:10:396e:4789:8e99:890f', '2a01:198:603:10::'], + ['::1', '::'], + ['0:0:0:0:0:0:0:1', '::'], + ['1:0:0:0:0:0:0:1', '1::'], + ['0:0:603:50:396e:4789:8e99:0001', '0:0:603:50::'], + ['[0:0:603:50:396e:4789:8e99:0001]', '[0:0:603:50::]'], + ['[2a01:198::3]', '[2a01:198::]'], + ['::ffff:123.234.235.236', '::ffff:123.234.235.0'], // IPv4-mapped IPv6 addresses + ['::123.234.235.236', '::123.234.235.0'], // deprecated IPv4-compatible IPv6 address + ]; + } } From 9e4b3ac8fa3348b4811674d23de32d201de225ce Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 19 Apr 2019 14:48:43 +0200 Subject: [PATCH 079/127] [HttpFoundation] fix guessing mime-types of files with leading dash --- File/MimeType/FileBinaryMimeTypeGuesser.php | 4 ++-- Tests/File/Fixtures/-test | Bin 0 -> 35 bytes Tests/File/MimeType/MimeTypeTest.php | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 Tests/File/Fixtures/-test diff --git a/File/MimeType/FileBinaryMimeTypeGuesser.php b/File/MimeType/FileBinaryMimeTypeGuesser.php index cfa76843c..7045e94df 100644 --- a/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -31,7 +31,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface * * @param string $cmd The command to run to get the mime type of a file */ - public function __construct($cmd = 'file -b --mime %s 2>/dev/null') + public function __construct($cmd = 'file -b --mime -- %s 2>/dev/null') { $this->cmd = $cmd; } @@ -80,7 +80,7 @@ public function guess($path) ob_start(); // need to use --mime instead of -i. see #6641 - passthru(sprintf($this->cmd, escapeshellarg($path)), $return); + passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return); if ($return > 0) { ob_end_clean(); diff --git a/Tests/File/Fixtures/-test b/Tests/File/Fixtures/-test new file mode 100644 index 0000000000000000000000000000000000000000..b636f4b8df536b0a85e7cea1a6cf3f0bd3179b96 GIT binary patch literal 35 jcmZ?wbh9u|WMp7uXkcLY4+c66KmZb9U}AD%WUvMRyAlZ1 literal 0 HcmV?d00001 diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index 3960988a6..0418726b5 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -20,7 +20,16 @@ */ class MimeTypeTest extends TestCase { - protected $path; + public function testGuessWithLeadingDash() + { + $cwd = getcwd(); + chdir(__DIR__.'/../Fixtures'); + try { + $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test')); + } finally { + chdir($cwd); + } + } public function testGuessImageWithoutExtension() { From e27325f5b25338ce222bbf4dabaae110da626601 Mon Sep 17 00:00:00 2001 From: wimg Date: Mon, 11 Nov 2019 17:54:27 +0900 Subject: [PATCH 080/127] [HttpFoundation][Lock] Connection parameter corrected --- Session/Storage/Handler/SessionHandlerFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index e7acf5173..00cf1521a 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -54,7 +54,7 @@ public static function createHandler($connection): AbstractSessionHandler case 0 === strpos($connection, 'rediss://'): case 0 === strpos($connection, 'memcached://'): if (!class_exists(AbstractAdapter::class)) { - throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $this->dsn)); + throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $storage)); } $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); From 55b22cc56de073a9a93f5ebd0ebb4d01d346c5f1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 11 Nov 2019 14:11:43 +0100 Subject: [PATCH 081/127] [HttpFoundation] fix typo --- Session/Storage/Handler/SessionHandlerFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index 00cf1521a..f4feeac09 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -54,7 +54,7 @@ public static function createHandler($connection): AbstractSessionHandler case 0 === strpos($connection, 'rediss://'): case 0 === strpos($connection, 'memcached://'): if (!class_exists(AbstractAdapter::class)) { - throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $storage)); + throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection)); } $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); From c9425bae96ae95449d59f8286529cf144bb228ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Broutier?= Date: Sat, 16 Nov 2019 12:20:14 +0100 Subject: [PATCH 082/127] Fix MySQL column type definition. Fix wrong MySQL column type definition causing Numeric value out of range exception. Ref #34409 --- Session/Storage/Handler/PdoSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index f9e5d1e8f..c9d47b6ed 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -218,7 +218,7 @@ public function createTable() // - trailing space removal // - case-insensitivity // - language processing like é == e - $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol MEDIUMINT NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB"; + $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB"; break; case 'sqlite': $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)"; From 9088e3f338e443869737d53af064fad9614ecc7d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 16 Nov 2019 16:17:02 +0100 Subject: [PATCH 083/127] [HttpFoundation] fix docblock --- Session/Storage/Handler/RedisSessionHandler.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index 46ca6796d..8ebc5bd8e 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -34,8 +34,7 @@ class RedisSessionHandler extends AbstractSessionHandler * List of available options: * * prefix: The prefix to use for the keys in order to avoid collision on the Redis server. * - * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy $redis - * @param array $options An associative array of options + * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis * * @throws \InvalidArgumentException When unsupported client or options are passed */ From ef5fed4469fb079c0b188ab0401cd1b28752865b Mon Sep 17 00:00:00 2001 From: Mark Beech Date: Wed, 13 Nov 2019 20:07:22 +0000 Subject: [PATCH 084/127] [HttpFoundation] Allow redirecting to URLs that contain a semicolon --- RedirectResponse.php | 2 +- Tests/RedirectResponseTest.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/RedirectResponse.php b/RedirectResponse.php index 4e3cb4f77..a19efba3e 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -93,7 +93,7 @@ public function setTargetUrl($url) - + Redirecting to %1$s diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index e1ff3bf2b..2bbf5aa1a 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -20,10 +20,7 @@ public function testGenerateMetaRedirect() { $response = new RedirectResponse('foo.bar'); - $this->assertEquals(1, preg_match( - '##', - preg_replace(['/\s+/', '/\'/'], [' ', '"'], $response->getContent()) - )); + $this->assertRegExp('##', preg_replace('/\s+/', ' ', $response->getContent())); } public function testRedirectResponseConstructorNullUrl() From 0c5217a9050712a1e66f851d04962abf8f2c6fc4 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 16 Nov 2019 03:22:35 +0600 Subject: [PATCH 085/127] [HttpFoundation] Added possibility to configure expiration time in redis session handler --- .../Storage/Handler/RedisSessionHandler.php | 15 +++++++--- .../AbstractRedisSessionHandlerTestCase.php | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index 40c209341..f11c8c4d6 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -30,9 +30,15 @@ class RedisSessionHandler extends AbstractSessionHandler */ private $prefix; + /** + * @var int Time to live in seconds + */ + private $ttl; + /** * List of available options: - * * prefix: The prefix to use for the keys in order to avoid collision on the Redis server. + * * prefix: The prefix to use for the keys in order to avoid collision on the Redis server + * * ttl: The time to live in seconds. * * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy $redis * @@ -51,12 +57,13 @@ public function __construct($redis, array $options = []) throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); } - if ($diff = array_diff(array_keys($options), ['prefix'])) { + if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) { throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff))); } $this->redis = $redis; $this->prefix = $options['prefix'] ?? 'sf_s'; + $this->ttl = $options['ttl'] ?? (int) ini_get('session.gc_maxlifetime'); } /** @@ -72,7 +79,7 @@ protected function doRead($sessionId): string */ protected function doWrite($sessionId, $data): bool { - $result = $this->redis->setEx($this->prefix.$sessionId, (int) ini_get('session.gc_maxlifetime'), $data); + $result = $this->redis->setEx($this->prefix.$sessionId, $this->ttl, $data); return $result && !$result instanceof ErrorInterface; } @@ -108,6 +115,6 @@ public function gc($maxlifetime): bool */ public function updateTimestamp($sessionId, $data) { - return (bool) $this->redis->expire($this->prefix.$sessionId, (int) ini_get('session.gc_maxlifetime')); + return (bool) $this->redis->expire($this->prefix.$sessionId, $this->ttl); } } diff --git a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php index 6a15a0687..8828be666 100644 --- a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php +++ b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php @@ -139,7 +139,37 @@ public function getOptionFixtures(): array { return [ [['prefix' => 'session'], true], + [['ttl' => 1000], true], + [['prefix' => 'sfs', 'ttl' => 1000], true], [['prefix' => 'sfs', 'foo' => 'bar'], false], + [['ttl' => 'sfs', 'foo' => 'bar'], false], + ]; + } + + /** + * @dataProvider getTtlFixtures + */ + public function testUseTtlOption(int $ttl) + { + $options = [ + 'prefix' => self::PREFIX, + 'ttl' => $ttl, + ]; + + $handler = new RedisSessionHandler($this->redisClient, $options); + $handler->write('id', 'data'); + $redisTtl = $this->redisClient->ttl(self::PREFIX.'id'); + + $this->assertLessThan($redisTtl, $ttl - 5); + $this->assertGreaterThan($redisTtl, $ttl + 5); + } + + public function getTtlFixtures(): array + { + return [ + ['ttl' => 5000], + ['ttl' => 120], + ['ttl' => 60], ]; } } From f7efd0b387b7bdbfe0fd1e38fe6b7d4a812b4e39 Mon Sep 17 00:00:00 2001 From: Roy-Orbison Date: Wed, 20 Nov 2019 15:04:29 +1030 Subject: [PATCH 086/127] Simpler example for Apache basic auth workaround Uses a simpler regex and existing back-reference instead of reading header twice. --- ServerBag.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ServerBag.php b/ServerBag.php index 4c82b1774..f3b640234 100644 --- a/ServerBag.php +++ b/ServerBag.php @@ -46,13 +46,13 @@ public function getHeaders() /* * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default * For this workaround to work, add these lines to your .htaccess file: - * RewriteCond %{HTTP:Authorization} ^(.+)$ - * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + * RewriteCond %{HTTP:Authorization} .+ + * RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0] * * A sample .htaccess file: * RewriteEngine On - * RewriteCond %{HTTP:Authorization} ^(.+)$ - * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + * RewriteCond %{HTTP:Authorization} .+ + * RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0] * RewriteCond %{REQUEST_FILENAME} !-f * RewriteRule ^(.*)$ app.php [QSA,L] */ From cc09809aa4182d5d062cde2c5836c5281f4e96eb Mon Sep 17 00:00:00 2001 From: Quentin Favrie Date: Mon, 25 Nov 2019 11:31:45 +0100 Subject: [PATCH 087/127] [HttpFoundation] Update CHANGELOG for PdoSessionHandler BC BREAK in 4.4 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e33b33ccb..3fa73a26a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ CHANGELOG * passing arguments to `Request::isMethodSafe()` is deprecated. * `ApacheRequest` is deprecated, use the `Request` class instead. * passing a third argument to `HeaderBag::get()` is deprecated, use method `all()` instead + * [BC BREAK] `PdoSessionHandler` with MySQL changed the type of the lifetime column, + make sure to run `ALTER TABLE sessions MODIFY sess_lifetime INTEGER UNSIGNED NOT NULL` to + update your database. * `PdoSessionHandler` now precalculates the expiry timestamp in the lifetime column, make sure to run `CREATE INDEX EXPIRY ON sessions (sess_lifetime)` to update your database to speed up garbage collection of expired sessions. From d2d0cfe8e319d9df44c4cca570710fcf221d4593 Mon Sep 17 00:00:00 2001 From: Thomas Bisignani Date: Thu, 28 Nov 2019 13:52:59 +0100 Subject: [PATCH 088/127] [HttpFoundation] Fixed typo --- BinaryFileResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index f43114111..ea7ac8469 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -348,7 +348,7 @@ public static function trustXSendfileTypeHeader() } /** - * If this is set to true, the file will be unlinked after the request is send + * If this is set to true, the file will be unlinked after the request is sent * Note: If the X-Sendfile header is used, the deleteFileAfterSend setting will not be used. * * @param bool $shouldDelete From 1f70ac41f1711f0ddc969736c71cc85d860a94b9 Mon Sep 17 00:00:00 2001 From: Rafael Tovar Date: Thu, 5 Dec 2019 08:36:17 +0100 Subject: [PATCH 089/127] [HttpFoundation] get currently session.gc_maxlifetime if ttl doesnt exists --- Session/Storage/Handler/RedisSessionHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index d8c1f8cb9..e5be90d5f 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -63,7 +63,7 @@ public function __construct($redis, array $options = []) $this->redis = $redis; $this->prefix = $options['prefix'] ?? 'sf_s'; - $this->ttl = $options['ttl'] ?? (int) ini_get('session.gc_maxlifetime'); + $this->ttl = $options['ttl'] ?? null; } /** @@ -79,7 +79,7 @@ protected function doRead($sessionId): string */ protected function doWrite($sessionId, $data): bool { - $result = $this->redis->setEx($this->prefix.$sessionId, $this->ttl, $data); + $result = $this->redis->setEx($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')), $data); return $result && !$result instanceof ErrorInterface; } @@ -115,6 +115,6 @@ public function gc($maxlifetime): bool */ public function updateTimestamp($sessionId, $data) { - return (bool) $this->redis->expire($this->prefix.$sessionId, $this->ttl); + return (bool) $this->redis->expire($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime'))); } } From 723b5ca3de95db0ae0e9148bd0db5afbbad973ef Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 18 Nov 2019 13:24:53 +0000 Subject: [PATCH 090/127] [HttpFoundation] Use `Cache-Control: must-revalidate` only if explicit lifetime has been given --- ResponseHeaderBag.php | 10 +++++----- Tests/ResponseHeaderBagTest.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index 1dc8dc2c5..e11b98a10 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -309,13 +309,13 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '') */ protected function computeCacheControlValue() { - if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) { - return 'no-cache, private'; - } - if (!$this->cacheControl) { + if ($this->has('Last-Modified') || $this->has('Expires')) { + return 'private, must-revalidate'; // allows for heuristic expiration (RFC 7234 Section 4.2.2) in the case of "Last-Modified" + } + // conservative by default - return 'private, must-revalidate'; + return 'no-cache, private'; } $header = $this->getCacheControlHeader(); diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index d85f6e112..4e3a6c82b 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -51,9 +51,9 @@ public function testCacheControlHeader() $this->assertTrue($bag->hasCacheControlDirective('public')); $bag = new ResponseHeaderBag(['ETag' => 'abcde']); - $this->assertEquals('private, must-revalidate', $bag->get('Cache-Control')); + $this->assertEquals('no-cache, private', $bag->get('Cache-Control')); $this->assertTrue($bag->hasCacheControlDirective('private')); - $this->assertTrue($bag->hasCacheControlDirective('must-revalidate')); + $this->assertTrue($bag->hasCacheControlDirective('no-cache')); $this->assertFalse($bag->hasCacheControlDirective('max-age')); $bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']); From da246f427905248a690142b56dfaf00b18b77e30 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 10 Dec 2019 09:58:16 -0500 Subject: [PATCH 091/127] Removed request header "Content-Type" from the preferred format guessing mechanism --- Request.php | 13 +++++-------- Tests/RequestTest.php | 2 -- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Request.php b/Request.php index bb5409123..6690b9b22 100644 --- a/Request.php +++ b/Request.php @@ -1586,20 +1586,17 @@ public function isNoCache() */ public function getPreferredFormat(?string $default = 'html'): ?string { - if (null !== $this->preferredFormat) { + if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) { return $this->preferredFormat; } - $preferredFormat = null; - foreach ($this->getAcceptableContentTypes() as $contentType) { - if ($preferredFormat = $this->getFormat($contentType)) { - break; + foreach ($this->getAcceptableContentTypes() as $mimeType) { + if ($this->preferredFormat = $this->getFormat($mimeType)) { + return $this->preferredFormat; } } - $this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType()); - - return $this->preferredFormat ?: $default; + return $default; } /** diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 1d0164725..7c53ec2d5 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -408,12 +408,10 @@ public function testGetPreferredFormat() $request->setRequestFormat('atom'); $request->headers->set('Accept', 'application/ld+json'); - $request->headers->set('Content-Type', 'application/merge-patch+json'); $this->assertSame('atom', $request->getPreferredFormat()); $request = new Request(); $request->headers->set('Accept', 'application/xml'); - $request->headers->set('Content-Type', 'application/json'); $this->assertSame('xml', $request->getPreferredFormat()); $request = new Request(); From 5a5c3b31482ffc655a74de3e55d87ec81291f3b5 Mon Sep 17 00:00:00 2001 From: Jan Christoph Beyer Date: Fri, 13 Dec 2019 12:27:55 +0100 Subject: [PATCH 092/127] fix redis multi host dsn not recognized --- Session/Storage/Handler/SessionHandlerFactory.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index f4feeac09..1f017c8af 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -50,13 +50,13 @@ public static function createHandler($connection): AbstractSessionHandler case 0 === strpos($connection, 'file://'): return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7))); - case 0 === strpos($connection, 'redis://'): - case 0 === strpos($connection, 'rediss://'): - case 0 === strpos($connection, 'memcached://'): + case 0 === strpos($connection, 'redis:'): + case 0 === strpos($connection, 'rediss:'): + case 0 === strpos($connection, 'memcached:'): if (!class_exists(AbstractAdapter::class)) { throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection)); } - $handlerClass = 0 === strpos($connection, 'memcached://') ? MemcachedSessionHandler::class : RedisSessionHandler::class; + $handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); return new $handlerClass($connection); From 7d2f82af89da0490e2ca88a7f309cc9d32c4494c Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Wed, 18 Dec 2019 10:25:03 +0000 Subject: [PATCH 093/127] use utf8mb4_bin to align code with documentation --- Session/Storage/Handler/PdoSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index c9d47b6ed..653ca6917 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -218,7 +218,7 @@ public function createTable() // - trailing space removal // - case-insensitivity // - language processing like é == e - $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB"; + $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8mb4_bin, ENGINE = InnoDB"; break; case 'sqlite': $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)"; From 760e8fb0b9d8c764ec10ccf7dd949b69bc59bd26 Mon Sep 17 00:00:00 2001 From: Saif Eddin G <29315886+azjezz@users.noreply.github.com> Date: Wed, 18 Dec 2019 16:15:58 +0100 Subject: [PATCH 094/127] [HttpFoundation] fix pdo session handler for sqlsrv --- Session/Storage/Handler/PdoSessionHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index b212236df..034c02e5c 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -871,10 +871,10 @@ private function getMergeStatement(string $sessionId, string $data, int $maxlife $mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB); $mergeStmt->bindValue(4, time() + $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(4, time(), \PDO::PARAM_INT); - $mergeStmt->bindParam(5, $data, \PDO::PARAM_LOB); - $mergeStmt->bindValue(6, time() + $maxlifetime, \PDO::PARAM_INT); - $mergeStmt->bindValue(6, time(), \PDO::PARAM_INT); + $mergeStmt->bindValue(5, time(), \PDO::PARAM_INT); + $mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB); + $mergeStmt->bindValue(7, time() + $maxlifetime, \PDO::PARAM_INT); + $mergeStmt->bindValue(8, time(), \PDO::PARAM_INT); } else { $mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB); From 5b932eed42c1f5172bd4ba46eef0525fce190502 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 19 Dec 2019 10:47:05 +0100 Subject: [PATCH 095/127] Fix typo --- Session/Storage/NativeSessionStorage.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 4c5873728..df7da3c72 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -375,13 +375,11 @@ public function setOptions(array $options) * ini_set('session.save_path', '/tmp'); * * or pass in a \SessionHandler instance which configures session.save_handler in the - * constructor, for a template see NativeFileSessionHandler or use handlers in - * composer package drak/native-session + * constructor, for a template see NativeFileSessionHandler. * * @see https://php.net/session-set-save-handler * @see https://php.net/sessionhandlerinterface * @see https://php.net/sessionhandler - * @see https://github.com/zikula/NativeSession * * @param \SessionHandlerInterface|null $saveHandler * From de7e6cd4b701a6d70c5dacf80d8f7cd49fdfdbbe Mon Sep 17 00:00:00 2001 From: Shaharia Azam Date: Sat, 21 Dec 2019 04:43:02 +0600 Subject: [PATCH 096/127] X-Accel Nginx URL updated Obsolete URL has been updated --- BinaryFileResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index ea7ac8469..c2f66d695 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -217,7 +217,7 @@ public function prepare(Request $request) } if ('x-accel-redirect' === strtolower($type)) { // Do X-Accel-Mapping substitutions. - // @link http://wiki.nginx.org/X-accel#X-Accel-Redirect + // @link https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) { $mapping = explode('=', $mapping, 2); From 45285abd8ddab3d30a22194c46ca48529cc90ee1 Mon Sep 17 00:00:00 2001 From: Jan Rosier Date: Wed, 1 Jan 2020 12:03:25 +0100 Subject: [PATCH 097/127] Update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a677f4376..9e936ec04 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2019 Fabien Potencier +Copyright (c) 2004-2020 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From f3abd07a56111ebe6a1ad6f1cbc23e4f8983f8f5 Mon Sep 17 00:00:00 2001 From: Shaharia Azam Date: Sat, 21 Dec 2019 04:13:14 +0600 Subject: [PATCH 098/127] Update links to documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8907f0b96..ac98f9b80 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ specification. Resources --------- - * [Documentation](https://symfony.com/doc/current/components/http_foundation/index.html) + * [Documentation](https://symfony.com/doc/current/components/http_foundation.html) * [Contributing](https://symfony.com/doc/current/contributing/index.html) * [Report issues](https://github.com/symfony/symfony/issues) and [send Pull Requests](https://github.com/symfony/symfony/pulls) From 3bdf327219a57aaa1910a6edfd4ef70c30bb85fa Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 10 Jan 2020 23:18:38 +0000 Subject: [PATCH 099/127] =?UTF-8?q?[HttpKernel]=C2=A0Fix=20stale-if-error?= =?UTF-8?q?=20behavior,=20add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Response.php b/Response.php index 26e3a3378..0f361bac3 100644 --- a/Response.php +++ b/Response.php @@ -649,7 +649,7 @@ public function isImmutable() } /** - * Returns true if the response must be revalidated by caches. + * Returns true if the response must be revalidated by shared caches once it has become stale. * * This method indicates that the response must not be served stale by a * cache in any circumstance without first revalidating with the origin. From 96c1a438acb4de840dac08f39018035a728a380c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Feb 2020 08:35:15 +0100 Subject: [PATCH 100/127] Add missing use statements --- Session/Storage/Handler/SessionHandlerFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index 1f017c8af..b92bd0ffd 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -54,7 +54,7 @@ public static function createHandler($connection): AbstractSessionHandler case 0 === strpos($connection, 'rediss:'): case 0 === strpos($connection, 'memcached:'): if (!class_exists(AbstractAdapter::class)) { - throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection)); + throw new \InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection)); } $handlerClass = 0 === strpos($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class; $connection = AbstractAdapter::createConnection($connection, ['lazy' => true]); From 7a2ab8cb09df0c3a0ab5fbe61a089f4b51487814 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Feb 2020 09:03:00 +0100 Subject: [PATCH 101/127] Fix CS --- RedirectResponse.php | 2 +- Session/Storage/Handler/AbstractSessionHandler.php | 2 +- Session/Storage/NativeSessionStorage.php | 8 ++++---- Session/Storage/Proxy/AbstractProxy.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/RedirectResponse.php b/RedirectResponse.php index a19efba3e..71ba9f825 100644 --- a/RedirectResponse.php +++ b/RedirectResponse.php @@ -42,7 +42,7 @@ public function __construct($url, $status = 302, $headers = []) throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status)); } - if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) { + if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, CASE_LOWER))) { $this->headers->remove('cache-control'); } } diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index eb09c0b54..84ba0ebba 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -133,7 +133,7 @@ public function destroy($sessionId) } if (!headers_sent() && filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN)) { if (!$this->sessionName) { - throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this))); + throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class)); } $sessionCookie = sprintf(' %s=', urlencode($this->sessionName)); $sessionCookieWithId = sprintf('%s%s;', $sessionCookie, urlencode($sessionId)); diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index df7da3c72..cbf7cadc7 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -137,7 +137,7 @@ public function start() return true; } - if (\PHP_SESSION_ACTIVE === session_status()) { + if (PHP_SESSION_ACTIVE === session_status()) { throw new \RuntimeException('Failed to start the session: already started by PHP.'); } @@ -193,7 +193,7 @@ public function setName($name) public function regenerate($destroy = false, $lifetime = null) { // Cannot regenerate the session ID for non-active sessions. - if (\PHP_SESSION_ACTIVE !== session_status()) { + if (PHP_SESSION_ACTIVE !== session_status()) { return false; } @@ -341,7 +341,7 @@ public function isStarted() */ public function setOptions(array $options) { - if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) { + if (headers_sent() || PHP_SESSION_ACTIVE === session_status()) { return; } @@ -401,7 +401,7 @@ public function setSaveHandler($saveHandler = null) } $this->saveHandler = $saveHandler; - if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) { + if (headers_sent() || PHP_SESSION_ACTIVE === session_status()) { return; } diff --git a/Session/Storage/Proxy/AbstractProxy.php b/Session/Storage/Proxy/AbstractProxy.php index 0303729e7..cd0635a16 100644 --- a/Session/Storage/Proxy/AbstractProxy.php +++ b/Session/Storage/Proxy/AbstractProxy.php @@ -65,7 +65,7 @@ public function isWrapper() */ public function isActive() { - return \PHP_SESSION_ACTIVE === session_status(); + return PHP_SESSION_ACTIVE === session_status(); } /** From 2292c5c4d47ee4c478464f45d9981b37f0abff14 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Feb 2020 10:29:10 +0100 Subject: [PATCH 102/127] Fix CS --- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 206ff4877..b4fad7688 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -61,12 +61,12 @@ public function testPhpSession() { $storage = $this->getStorage(); - $this->assertNotSame(\PHP_SESSION_ACTIVE, session_status()); + $this->assertNotSame(PHP_SESSION_ACTIVE, session_status()); $this->assertFalse($storage->isStarted()); session_start(); $this->assertTrue(isset($_SESSION)); - $this->assertSame(\PHP_SESSION_ACTIVE, session_status()); + $this->assertSame(PHP_SESSION_ACTIVE, session_status()); // PHP session might have started, but the storage driver has not, so false is correct here $this->assertFalse($storage->isStarted()); From 4d440be93adcfd5e4ee0bdc7acd1c3260625728f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Sep 2018 10:27:39 +0200 Subject: [PATCH 103/127] [HttpFoundation][FrameworkBundle] fix support for samesite in session cookies --- Session/SessionUtils.php | 59 +++++++++++++++++++ .../Handler/AbstractSessionHandler.php | 50 +++++++--------- Session/Storage/NativeSessionStorage.php | 42 +++++++++++-- .../Storage/Handler/Fixtures/storage.expected | 3 +- .../Fixtures/with_cookie_and_session.expected | 1 + .../Handler/Fixtures/with_samesite.expected | 16 +++++ .../Handler/Fixtures/with_samesite.php | 13 ++++ .../with_samesite_and_migration.expected | 23 ++++++++ .../Fixtures/with_samesite_and_migration.php | 15 +++++ .../Storage/NativeSessionStorageTest.php | 8 ++- 10 files changed, 192 insertions(+), 38 deletions(-) create mode 100644 Session/SessionUtils.php create mode 100644 Tests/Session/Storage/Handler/Fixtures/with_samesite.expected create mode 100644 Tests/Session/Storage/Handler/Fixtures/with_samesite.php create mode 100644 Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected create mode 100644 Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.php diff --git a/Session/SessionUtils.php b/Session/SessionUtils.php new file mode 100644 index 000000000..04a25f716 --- /dev/null +++ b/Session/SessionUtils.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\Session; + +/** + * Session utility functions. + * + * @author Nicolas Grekas + * @author Rémon van de Kamp + * + * @internal + */ +final class SessionUtils +{ + /** + * Find the session header amongst the headers that are to be sent, remove it, and return + * it so the caller can process it further. + */ + public static function popSessionCookie($sessionName, $sessionId) + { + $sessionCookie = null; + $sessionCookiePrefix = sprintf(' %s=', urlencode($sessionName)); + $sessionCookieWithId = sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId)); + $otherCookies = []; + foreach (headers_list() as $h) { + if (0 !== stripos($h, 'Set-Cookie:')) { + continue; + } + if (11 === strpos($h, $sessionCookiePrefix, 11)) { + $sessionCookie = $h; + + if (11 !== strpos($h, $sessionCookieWithId, 11)) { + $otherCookies[] = $h; + } + } else { + $otherCookies[] = $h; + } + } + if (null === $sessionCookie) { + return null; + } + + header_remove('Set-Cookie'); + foreach ($otherCookies as $h) { + header($h, false); + } + + return $sessionCookie; + } +} diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index 84ba0ebba..ec59d895c 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; +use Symfony\Component\HttpFoundation\Session\SessionUtils; + /** * This abstract session handler provides a generic implementation * of the PHP 7.0 SessionUpdateTimestampHandlerInterface, @@ -27,7 +29,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess private $igbinaryEmptyData; /** - * {@inheritdoc} + * @return bool */ public function open($savePath, $sessionName) { @@ -62,7 +64,7 @@ abstract protected function doWrite($sessionId, $data); abstract protected function doDestroy($sessionId); /** - * {@inheritdoc} + * @return bool */ public function validateId($sessionId) { @@ -73,7 +75,7 @@ public function validateId($sessionId) } /** - * {@inheritdoc} + * @return string */ public function read($sessionId) { @@ -99,7 +101,7 @@ public function read($sessionId) } /** - * {@inheritdoc} + * @return bool */ public function write($sessionId, $data) { @@ -124,7 +126,7 @@ public function write($sessionId, $data) } /** - * {@inheritdoc} + * @return bool */ public function destroy($sessionId) { @@ -135,31 +137,23 @@ public function destroy($sessionId) if (!$this->sessionName) { throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class)); } - $sessionCookie = sprintf(' %s=', urlencode($this->sessionName)); - $sessionCookieWithId = sprintf('%s%s;', $sessionCookie, urlencode($sessionId)); - $sessionCookieFound = false; - $otherCookies = []; - foreach (headers_list() as $h) { - if (0 !== stripos($h, 'Set-Cookie:')) { - continue; - } - if (11 === strpos($h, $sessionCookie, 11)) { - $sessionCookieFound = true; - - if (11 !== strpos($h, $sessionCookieWithId, 11)) { - $otherCookies[] = $h; - } + $cookie = SessionUtils::popSessionCookie($this->sessionName, $sessionId); + + /* + * We send an invalidation Set-Cookie header (zero lifetime) + * when either the session was started or a cookie with + * the session name was sent by the client (in which case + * we know it's invalid as a valid session cookie would've + * started the session). + */ + if (null === $cookie || isset($_COOKIE[$this->sessionName])) { + if (\PHP_VERSION_ID < 70300) { + setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN)); } else { - $otherCookies[] = $h; - } - } - if ($sessionCookieFound) { - header_remove('Set-Cookie'); - foreach ($otherCookies as $h) { - header($h, false); + $params = session_get_cookie_params(); + unset($params['lifetime']); + setcookie($this->sessionName, '', $params); } - } else { - setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN)); } } diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index cbf7cadc7..7502897a4 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; +use Symfony\Component\HttpFoundation\Session\SessionUtils; use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; @@ -48,6 +49,11 @@ class NativeSessionStorage implements SessionStorageInterface */ protected $metadataBag; + /** + * @var string|null + */ + private $emulateSameSite; + /** * Depending on how you want the storage driver to behave you probably * want to override this constructor entirely. @@ -67,6 +73,7 @@ class NativeSessionStorage implements SessionStorageInterface * cookie_lifetime, "0" * cookie_path, "/" * cookie_secure, "" + * cookie_samesite, null * entropy_file, "" * entropy_length, "0" * gc_divisor, "100" @@ -94,9 +101,7 @@ class NativeSessionStorage implements SessionStorageInterface * trans_sid_hosts, $_SERVER['HTTP_HOST'] * trans_sid_tags, "a=href,area=href,frame=src,form=" * - * @param array $options Session configuration options - * @param \SessionHandlerInterface|null $handler - * @param MetadataBag $metaBag MetadataBag + * @param AbstractProxy|\SessionHandlerInterface|null $handler */ public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null) { @@ -150,6 +155,13 @@ public function start() throw new \RuntimeException('Failed to start the session'); } + if (null !== $this->emulateSameSite) { + $originalCookie = SessionUtils::popSessionCookie(session_name(), session_id()); + if (null !== $originalCookie) { + header(sprintf('%s; SameSite=%s', $originalCookie, $this->emulateSameSite), false); + } + } + $this->loadSession(); return true; @@ -215,6 +227,13 @@ public function regenerate($destroy = false, $lifetime = null) // @see https://bugs.php.net/70013 $this->loadSession(); + if (null !== $this->emulateSameSite) { + $originalCookie = SessionUtils::popSessionCookie(session_name(), session_id()); + if (null !== $originalCookie) { + header(sprintf('%s; SameSite=%s', $originalCookie, $this->emulateSameSite), false); + } + } + return $isRegenerated; } @@ -223,6 +242,7 @@ public function regenerate($destroy = false, $lifetime = null) */ public function save() { + // Store a copy so we can restore the bags in case the session was not left empty $session = $_SESSION; foreach ($this->bags as $bag) { @@ -248,7 +268,11 @@ public function save() session_write_close(); } finally { restore_error_handler(); - $_SESSION = $session; + + // Restore only if not empty + if ($_SESSION) { + $_SESSION = $session; + } } $this->closed = true; @@ -347,7 +371,7 @@ public function setOptions(array $options) $validOptions = array_flip([ 'cache_expire', 'cache_limiter', 'cookie_domain', 'cookie_httponly', - 'cookie_lifetime', 'cookie_path', 'cookie_secure', + 'cookie_lifetime', 'cookie_path', 'cookie_secure', 'cookie_samesite', 'entropy_file', 'entropy_length', 'gc_divisor', 'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character', 'hash_function', 'lazy_write', 'name', 'referer_check', @@ -360,6 +384,12 @@ public function setOptions(array $options) foreach ($options as $key => $value) { if (isset($validOptions[$key])) { + if ('cookie_samesite' === $key && \PHP_VERSION_ID < 70300) { + // PHP < 7.3 does not support same_site cookies. We will emulate it in + // the start() method instead. + $this->emulateSameSite = $value; + continue; + } ini_set('url_rewriter.tags' !== $key ? 'session.'.$key : $key, $value); } } @@ -381,7 +411,7 @@ public function setOptions(array $options) * @see https://php.net/sessionhandlerinterface * @see https://php.net/sessionhandler * - * @param \SessionHandlerInterface|null $saveHandler + * @param AbstractProxy|\SessionHandlerInterface|null $saveHandler * * @throws \InvalidArgumentException */ diff --git a/Tests/Session/Storage/Handler/Fixtures/storage.expected b/Tests/Session/Storage/Handler/Fixtures/storage.expected index 4533a10a1..05a5d5d0b 100644 --- a/Tests/Session/Storage/Handler/Fixtures/storage.expected +++ b/Tests/Session/Storage/Handler/Fixtures/storage.expected @@ -11,10 +11,11 @@ $_SESSION is not empty write destroy close -$_SESSION is not empty +$_SESSION is empty Array ( [0] => Content-Type: text/plain; charset=utf-8 [1] => Cache-Control: max-age=0, private, must-revalidate + [2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly ) shutdown diff --git a/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected b/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected index 5de2d9e39..63078228d 100644 --- a/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected +++ b/Tests/Session/Storage/Handler/Fixtures/with_cookie_and_session.expected @@ -20,5 +20,6 @@ Array [0] => Content-Type: text/plain; charset=utf-8 [1] => Cache-Control: max-age=10800, private, must-revalidate [2] => Set-Cookie: abc=def + [3] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly ) shutdown diff --git a/Tests/Session/Storage/Handler/Fixtures/with_samesite.expected b/Tests/Session/Storage/Handler/Fixtures/with_samesite.expected new file mode 100644 index 000000000..d20fb88ec --- /dev/null +++ b/Tests/Session/Storage/Handler/Fixtures/with_samesite.expected @@ -0,0 +1,16 @@ +open +validateId +read +doRead: +read + +write +doWrite: foo|s:3:"bar"; +close +Array +( + [0] => Content-Type: text/plain; charset=utf-8 + [1] => Cache-Control: max-age=0, private, must-revalidate + [2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax +) +shutdown diff --git a/Tests/Session/Storage/Handler/Fixtures/with_samesite.php b/Tests/Session/Storage/Handler/Fixtures/with_samesite.php new file mode 100644 index 000000000..fc2c41828 --- /dev/null +++ b/Tests/Session/Storage/Handler/Fixtures/with_samesite.php @@ -0,0 +1,13 @@ + 'lax']); +$storage->setSaveHandler(new TestSessionHandler()); +$storage->start(); + +$_SESSION = ['foo' => 'bar']; + +ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); }); diff --git a/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected new file mode 100644 index 000000000..8b5fc08bd --- /dev/null +++ b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.expected @@ -0,0 +1,23 @@ +open +validateId +read +doRead: +read +destroy +close +open +validateId +read +doRead: +read + +write +doWrite: foo|s:3:"bar"; +close +Array +( + [0] => Content-Type: text/plain; charset=utf-8 + [1] => Cache-Control: max-age=0, private, must-revalidate + [2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax +) +shutdown diff --git a/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.php b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.php new file mode 100644 index 000000000..a28b6fedf --- /dev/null +++ b/Tests/Session/Storage/Handler/Fixtures/with_samesite_and_migration.php @@ -0,0 +1,15 @@ + 'lax']); +$storage->setSaveHandler(new TestSessionHandler()); +$storage->start(); + +$_SESSION = ['foo' => 'bar']; + +$storage->regenerate(true); + +ob_start(function ($buffer) { return preg_replace('~_sf2_meta.*$~m', '', str_replace(session_id(), 'random_session_id', $buffer)); }); diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 9ce8108da..d2cf32452 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -36,7 +36,7 @@ class NativeSessionStorageTest extends TestCase protected function setUp() { $this->iniSet('session.save_handler', 'files'); - $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test'); + $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); if (!is_dir($this->savePath)) { mkdir($this->savePath); } @@ -167,6 +167,10 @@ public function testCookieOptions() 'cookie_httponly' => false, ]; + if (\PHP_VERSION_ID >= 70300) { + $options['cookie_samesite'] = 'lax'; + } + $this->getStorage($options); $temp = session_get_cookie_params(); $gco = []; @@ -175,8 +179,6 @@ public function testCookieOptions() $gco['cookie_'.$key] = $value; } - unset($gco['cookie_samesite']); - $this->assertEquals($options, $gco); } From 7e41b4fcad4619535f45f8bfa7744c4f384e1648 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 13 Feb 2020 19:35:54 +0100 Subject: [PATCH 104/127] [HttpFoundation] fix not sending Content-Type header for 204 responses --- Response.php | 4 +++- Tests/ResponseTest.php | 12 ++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Response.php b/Response.php index 05f740b6a..b267cd8ce 100644 --- a/Response.php +++ b/Response.php @@ -267,10 +267,12 @@ public function prepare(Request $request) $this->setContent(null); $headers->remove('Content-Type'); $headers->remove('Content-Length'); + // prevent PHP from sending the Content-Type header based on default_mimetype + ini_set('default_mimetype', ''); } else { // Content-type based on the Request if (!$headers->has('Content-Type')) { - $format = $request->getPreferredFormat(); + $format = $request->getPreferredFormat(null); if (null !== $format && $mimeType = $request->getMimeType($format)) { $headers->set('Content-Type', $mimeType); } diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index a2a5574f2..d5da59ad7 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -461,18 +461,10 @@ public function testSetVary() public function testDefaultContentType() { - $headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock(); - $headerMock->expects($this->at(0)) - ->method('set') - ->with('Content-Type', 'text/html'); - $headerMock->expects($this->at(1)) - ->method('set') - ->with('Content-Type', 'text/html; charset=UTF-8'); - $response = new Response('foo'); - $response->headers = $headerMock; - $response->prepare(new Request()); + + $this->assertSame('text/html; charset=UTF-8', $response->headers->get('Content-Type')); } public function testContentTypeCharset() From 1791cbfce69e9440f5e01b389ddca92b163561fa Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 15 Mar 2020 10:01:00 +0100 Subject: [PATCH 105/127] Add missing dots at the end of exception messages --- File/File.php | 6 +++--- File/MimeType/MimeTypeGuesser.php | 2 +- File/UploadedFile.php | 2 +- Session/Storage/Handler/MemcacheSessionHandler.php | 2 +- Session/Storage/Handler/MemcachedSessionHandler.php | 2 +- Session/Storage/Handler/MongoDbSessionHandler.php | 4 ++-- Session/Storage/Handler/NativeFileSessionHandler.php | 4 ++-- Session/Storage/Handler/PdoSessionHandler.php | 4 ++-- Session/Storage/MockArraySessionStorage.php | 2 +- Session/Storage/MockFileSessionStorage.php | 4 ++-- Session/Storage/NativeSessionStorage.php | 2 +- Session/Storage/Proxy/AbstractProxy.php | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/File/File.php b/File/File.php index 34220588a..309339e5c 100644 --- a/File/File.php +++ b/File/File.php @@ -97,7 +97,7 @@ public function move($directory, $name = null) $renamed = rename($this->getPathname(), $target); restore_error_handler(); if (!$renamed) { - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error))); + throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); } @chmod($target, 0666 & ~umask()); @@ -109,10 +109,10 @@ protected function getTargetFile($directory, $name = null) { if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) { - throw new FileException(sprintf('Unable to create the "%s" directory', $directory)); + throw new FileException(sprintf('Unable to create the "%s" directory.', $directory)); } } elseif (!is_writable($directory)) { - throw new FileException(sprintf('Unable to write in the "%s" directory', $directory)); + throw new FileException(sprintf('Unable to write in the "%s" directory.', $directory)); } $target = rtrim($directory, '/\\').\DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); diff --git a/File/MimeType/MimeTypeGuesser.php b/File/MimeType/MimeTypeGuesser.php index e05269fc8..8d971ed67 100644 --- a/File/MimeType/MimeTypeGuesser.php +++ b/File/MimeType/MimeTypeGuesser.php @@ -127,7 +127,7 @@ public function guess($path) } if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) { - throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)'); + throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?).'); } return null; diff --git a/File/UploadedFile.php b/File/UploadedFile.php index 86153ed49..5b75dd84f 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -196,7 +196,7 @@ public function move($directory, $name = null) $moved = move_uploaded_file($this->getPathname(), $target); restore_error_handler(); if (!$moved) { - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error))); + throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error))); } @chmod($target, 0666 & ~umask()); diff --git a/Session/Storage/Handler/MemcacheSessionHandler.php b/Session/Storage/Handler/MemcacheSessionHandler.php index 3abc33caa..d4b68ae8b 100644 --- a/Session/Storage/Handler/MemcacheSessionHandler.php +++ b/Session/Storage/Handler/MemcacheSessionHandler.php @@ -47,7 +47,7 @@ class MemcacheSessionHandler implements \SessionHandlerInterface public function __construct(\Memcache $memcache, array $options = []) { if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime'])) { - throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff))); + throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff))); } $this->memcache = $memcache; diff --git a/Session/Storage/Handler/MemcachedSessionHandler.php b/Session/Storage/Handler/MemcachedSessionHandler.php index a399be5fd..6711e0a55 100644 --- a/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/Session/Storage/Handler/MemcachedSessionHandler.php @@ -47,7 +47,7 @@ public function __construct(\Memcached $memcached, array $options = []) $this->memcached = $memcached; if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime'])) { - throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff))); + throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff))); } $this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400; diff --git a/Session/Storage/Handler/MongoDbSessionHandler.php b/Session/Storage/Handler/MongoDbSessionHandler.php index 1dd724066..d84f2e9d0 100644 --- a/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/Session/Storage/Handler/MongoDbSessionHandler.php @@ -74,11 +74,11 @@ public function __construct($mongo, array $options) } if (!($mongo instanceof \MongoDB\Client || $mongo instanceof \MongoClient || $mongo instanceof \Mongo)) { - throw new \InvalidArgumentException('MongoClient or Mongo instance required'); + throw new \InvalidArgumentException('MongoClient or Mongo instance required.'); } if (!isset($options['database']) || !isset($options['collection'])) { - throw new \InvalidArgumentException('You must provide the "database" and "collection" option for MongoDBSessionHandler'); + throw new \InvalidArgumentException('You must provide the "database" and "collection" option for MongoDBSessionHandler.'); } $this->mongo = $mongo; diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index 8b7615ec1..f24271fbf 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -38,7 +38,7 @@ public function __construct($savePath = null) if ($count = substr_count($savePath, ';')) { if ($count > 2) { - throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath)); + throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'.', $savePath)); } // characters after last ';' are the path @@ -46,7 +46,7 @@ public function __construct($savePath = null) } if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) { - throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir)); + throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir)); } ini_set('session.save_path', $savePath); diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 653ca6917..d1cf622bd 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -173,7 +173,7 @@ public function __construct($pdoOrDsn = null, array $options = []) { if ($pdoOrDsn instanceof \PDO) { if (\PDO::ERRMODE_EXCEPTION !== $pdoOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) { - throw new \InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __CLASS__)); + throw new \InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__)); } $this->pdo = $pdoOrDsn; @@ -465,7 +465,7 @@ private function buildDsnFromUrl($dsnOrUrl) } if (!isset($params['scheme'])) { - throw new \InvalidArgumentException('URLs without scheme are not supported to configure the PdoSessionHandler'); + throw new \InvalidArgumentException('URLs without scheme are not supported to configure the PdoSessionHandler.'); } $driverAliasMap = [ diff --git a/Session/Storage/MockArraySessionStorage.php b/Session/Storage/MockArraySessionStorage.php index c1e7523c5..969f272fb 100644 --- a/Session/Storage/MockArraySessionStorage.php +++ b/Session/Storage/MockArraySessionStorage.php @@ -152,7 +152,7 @@ public function setName($name) public function save() { if (!$this->started || $this->closed) { - throw new \RuntimeException('Trying to save a session that was not started yet or was already closed'); + throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.'); } // nothing to do since we don't persist the session data $this->closed = false; diff --git a/Session/Storage/MockFileSessionStorage.php b/Session/Storage/MockFileSessionStorage.php index 9bbd1baf2..c5b1d1a36 100644 --- a/Session/Storage/MockFileSessionStorage.php +++ b/Session/Storage/MockFileSessionStorage.php @@ -38,7 +38,7 @@ public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag } if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) { - throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $savePath)); + throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath)); } $this->savePath = $savePath; @@ -88,7 +88,7 @@ public function regenerate($destroy = false, $lifetime = null) public function save() { if (!$this->started) { - throw new \RuntimeException('Trying to save a session that was not started yet or was already closed'); + throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.'); } $data = $this->data; diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 7502897a4..33a146553 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -152,7 +152,7 @@ public function start() // ok to try and start the session if (!session_start()) { - throw new \RuntimeException('Failed to start the session'); + throw new \RuntimeException('Failed to start the session.'); } if (null !== $this->emulateSameSite) { diff --git a/Session/Storage/Proxy/AbstractProxy.php b/Session/Storage/Proxy/AbstractProxy.php index cd0635a16..b9c2682b3 100644 --- a/Session/Storage/Proxy/AbstractProxy.php +++ b/Session/Storage/Proxy/AbstractProxy.php @@ -88,7 +88,7 @@ public function getId() public function setId($id) { if ($this->isActive()) { - throw new \LogicException('Cannot change the ID of an active session'); + throw new \LogicException('Cannot change the ID of an active session.'); } session_id($id); @@ -114,7 +114,7 @@ public function getName() public function setName($name) { if ($this->isActive()) { - throw new \LogicException('Cannot change the name of an active session'); + throw new \LogicException('Cannot change the name of an active session.'); } session_name($name); From 01887e8604ffa17e5078c7815279282796711689 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 15 Mar 2020 11:08:38 +0100 Subject: [PATCH 106/127] Add missing dots at the end of exception messages --- Request.php | 2 +- Session/Storage/Handler/RedisSessionHandler.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Request.php b/Request.php index 6690b9b22..bff1c0cbf 100644 --- a/Request.php +++ b/Request.php @@ -725,7 +725,7 @@ public function getSession() if (null === $session) { @trigger_error(sprintf('Calling "%s()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.', __METHOD__), E_USER_DEPRECATED); - // throw new \BadMethodCallException('Session has not been set'); + // throw new \BadMethodCallException('Session has not been set.'); } return $session; diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index e5be90d5f..1b83de09b 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -54,11 +54,11 @@ public function __construct($redis, array $options = []) !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy ) { - throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); + throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); } if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) { - throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff))); + throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff))); } $this->redis = $redis; From 13f9b084cddc2dd0a77836c703594ad970f09291 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 16 Mar 2020 08:32:23 +0100 Subject: [PATCH 107/127] Fix quotes in exception messages --- HeaderBag.php | 2 +- Session/Storage/MockArraySessionStorage.php | 2 +- Session/Storage/NativeSessionStorage.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HeaderBag.php b/HeaderBag.php index 35bd6ad8f..0b19faec5 100644 --- a/HeaderBag.php +++ b/HeaderBag.php @@ -225,7 +225,7 @@ public function getDate($key, \DateTime $default = null) } if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) { - throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value)); + throw new \RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value)); } return $date; diff --git a/Session/Storage/MockArraySessionStorage.php b/Session/Storage/MockArraySessionStorage.php index 969f272fb..5474d92e3 100644 --- a/Session/Storage/MockArraySessionStorage.php +++ b/Session/Storage/MockArraySessionStorage.php @@ -190,7 +190,7 @@ public function registerBag(SessionBagInterface $bag) public function getBag($name) { if (!isset($this->bags[$name])) { - throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); + throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name)); } if (!$this->started) { diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 33a146553..5165b5d0d 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -314,7 +314,7 @@ public function registerBag(SessionBagInterface $bag) public function getBag($name) { if (!isset($this->bags[$name])) { - throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); + throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name)); } if (!$this->started && $this->saveHandler->isActive()) { From f4dc52b1eb2b19ebf7c697d0017027aef6996c9c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 16 Mar 2020 11:25:47 +0100 Subject: [PATCH 108/127] Fix quotes in exception messages --- Session/Storage/Handler/RedisSessionHandler.php | 2 +- Session/Storage/Handler/SessionHandlerFactory.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index 1b83de09b..8fc19c6bc 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -54,7 +54,7 @@ public function __construct($redis, array $options = []) !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy ) { - throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); + throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); } if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) { diff --git a/Session/Storage/Handler/SessionHandlerFactory.php b/Session/Storage/Handler/SessionHandlerFactory.php index b92bd0ffd..a5ebd29eb 100644 --- a/Session/Storage/Handler/SessionHandlerFactory.php +++ b/Session/Storage/Handler/SessionHandlerFactory.php @@ -27,7 +27,7 @@ class SessionHandlerFactory public static function createHandler($connection): AbstractSessionHandler { if (!\is_string($connection) && !\is_object($connection)) { - throw new \TypeError(sprintf('Argument 1 passed to %s() must be a string or a connection object, %s given.', __METHOD__, \gettype($connection))); + throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, \gettype($connection))); } switch (true) { @@ -46,7 +46,7 @@ public static function createHandler($connection): AbstractSessionHandler return new PdoSessionHandler($connection); case !\is_string($connection): - throw new \InvalidArgumentException(sprintf('Unsupported Connection: %s.', \get_class($connection))); + throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', \get_class($connection))); case 0 === strpos($connection, 'file://'): return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7))); @@ -80,6 +80,6 @@ public static function createHandler($connection): AbstractSessionHandler return new PdoSessionHandler($connection); } - throw new \InvalidArgumentException(sprintf('Unsupported Connection: %s.', $connection)); + throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection)); } } From ff006c7736a22ffac6c9e76db451db026e414325 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 16 Mar 2020 17:13:17 +0100 Subject: [PATCH 109/127] Fix more quotes in exception messages --- Session/Storage/Handler/RedisSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Storage/Handler/RedisSessionHandler.php b/Session/Storage/Handler/RedisSessionHandler.php index 8fc19c6bc..699d6da6f 100644 --- a/Session/Storage/Handler/RedisSessionHandler.php +++ b/Session/Storage/Handler/RedisSessionHandler.php @@ -54,7 +54,7 @@ public function __construct($redis, array $options = []) !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy ) { - throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); + throw new \InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); } if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) { From 109ac257dfc057f3301034947e22c823f3f6d6e8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 Sep 2019 13:01:54 +0200 Subject: [PATCH 110/127] [DI] fix preloading script generation --- AcceptHeader.php | 3 +++ Request.php | 8 ++++++++ Response.php | 3 +++ Session/Session.php | 5 +++++ Session/Storage/NativeSessionStorage.php | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/AcceptHeader.php b/AcceptHeader.php index bbbd62a6d..c3c8d0c35 100644 --- a/AcceptHeader.php +++ b/AcceptHeader.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpFoundation; +// Help opcache.preload discover always-needed symbols +class_exists(AcceptHeaderItem::class); + /** * Represents an Accept-* header. * diff --git a/Request.php b/Request.php index bff1c0cbf..a5e50eb79 100644 --- a/Request.php +++ b/Request.php @@ -15,6 +15,14 @@ use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; use Symfony\Component\HttpFoundation\Session\SessionInterface; +// Help opcache.preload discover always-needed symbols +class_exists(AcceptHeader::class); +class_exists(FileBag::class); +class_exists(HeaderBag::class); +class_exists(HeaderUtils::class); +class_exists(ParameterBag::class); +class_exists(ServerBag::class); + /** * Request represents an HTTP request. * diff --git a/Response.php b/Response.php index b267cd8ce..714109d53 100644 --- a/Response.php +++ b/Response.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpFoundation; +// Help opcache.preload discover always-needed symbols +class_exists(ResponseHeaderBag::class); + /** * Response represents an HTTP response. * diff --git a/Session/Session.php b/Session/Session.php index 2192c629e..b6973aaab 100644 --- a/Session/Session.php +++ b/Session/Session.php @@ -18,6 +18,11 @@ use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; +// Help opcache.preload discover always-needed symbols +class_exists(AttributeBag::class); +class_exists(FlashBag::class); +class_exists(SessionBagProxy::class); + /** * @author Fabien Potencier * @author Drak diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 93a5d54e4..54933d953 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -17,6 +17,11 @@ use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy; use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; +// Help opcache.preload discover always-needed symbols +class_exists(MetadataBag::class); +class_exists(StrictSessionHandler::class); +class_exists(SessionHandlerProxy::class); + /** * This provides a base class for session attribute storage. * From a8833c56f6a4abcf17a319d830d71fdb0ba93675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20P=C3=A9delagrabe?= Date: Mon, 23 Mar 2020 11:02:50 +0100 Subject: [PATCH 111/127] [Http Foundation] Fix clear cookie samesite --- ResponseHeaderBag.php | 7 +++++-- Tests/ResponseHeaderBagTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ResponseHeaderBag.php b/ResponseHeaderBag.php index e11b98a10..9a6f87648 100644 --- a/ResponseHeaderBag.php +++ b/ResponseHeaderBag.php @@ -244,10 +244,13 @@ public function getCookies($format = self::COOKIES_FLAT) * @param string $domain * @param bool $secure * @param bool $httpOnly + * @param string $sameSite */ - public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true) + public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true/*, $sameSite = null*/) { - $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly)); + $sameSite = \func_num_args() > 5 ? func_get_arg(5) : null; + + $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, $sameSite)); } /** diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index 4e3a6c82b..632c96df5 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -128,6 +128,14 @@ public function testClearCookieSecureNotHttpOnly() $this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag); } + public function testClearCookieSamesite() + { + $bag = new ResponseHeaderBag([]); + + $bag->clearCookie('foo', '/', null, true, false, 'none'); + $this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure; samesite=none', $bag); + } + public function testReplace() { $bag = new ResponseHeaderBag([]); From 67d01969b7cd2c62b3399bfce0a601d5225071dc Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 25 Mar 2020 22:25:16 +0100 Subject: [PATCH 112/127] add missing gitattributes for phpunit-bridge --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index ebb928704..84c7add05 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ /Tests export-ignore /phpunit.xml.dist export-ignore +/.gitattributes export-ignore /.gitignore export-ignore From 62f92509c9abfd1f73e17b8cf1b72c0bdac6611b Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 11 Feb 2020 09:34:35 -0500 Subject: [PATCH 113/127] [HttpFoundation] Do not set the default Content-Type based on the Accept header --- Request.php | 4 +++- Response.php | 2 +- Tests/ResponseTest.php | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Request.php b/Request.php index a5e50eb79..33f4efb5e 100644 --- a/Request.php +++ b/Request.php @@ -1590,7 +1590,9 @@ public function isNoCache() * Gets the preferred format for the response by inspecting, in the following order: * * the request format set using setRequestFormat * * the values of the Accept HTTP header - * * the content type of the body of the request. + * + * Note that if you use this method, you should send the "Vary: Accept" header + * in the response to prevent any issues with intermediary HTTP caches. */ public function getPreferredFormat(?string $default = 'html'): ?string { diff --git a/Response.php b/Response.php index 714109d53..b9177934a 100644 --- a/Response.php +++ b/Response.php @@ -275,7 +275,7 @@ public function prepare(Request $request) } else { // Content-type based on the Request if (!$headers->has('Content-Type')) { - $format = $request->getPreferredFormat(null); + $format = $request->getRequestFormat(null); if (null !== $format && $mimeType = $request->getMimeType($format)) { $headers->set('Content-Type', $mimeType); } diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index d5da59ad7..c766f88a2 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -497,12 +497,25 @@ public function testPrepareDoesNothingIfRequestFormatIsNotDefined() $this->assertEquals('text/html; charset=UTF-8', $response->headers->get('content-type')); } + /** + * Same URL cannot produce different Content-Type based on the value of the Accept header, + * unless explicitly stated in the response object. + */ + public function testPrepareDoesNotSetContentTypeBasedOnRequestAcceptHeader() + { + $response = new Response('foo'); + $request = Request::create('/'); + $request->headers->set('Accept', 'application/json'); + $response->prepare($request); + + $this->assertSame('text/html; charset=UTF-8', $response->headers->get('content-type')); + } + public function testPrepareSetContentType() { $response = new Response('foo'); $request = Request::create('/'); $request->setRequestFormat('json'); - $request->headers->remove('accept'); $response->prepare($request); From 7fd8435d110a5ff27b5c61d7151497c59b89a9ed Mon Sep 17 00:00:00 2001 From: rosier Date: Mon, 30 Mar 2020 19:57:25 +0200 Subject: [PATCH 114/127] No need to reconnect the bags to the session Bug https://bugs.php.net/70013 was fixed before the release of PHP v7.0 --- Session/Storage/NativeSessionStorage.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 5165b5d0d..d6ce2a79d 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -223,10 +223,6 @@ public function regenerate($destroy = false, $lifetime = null) $isRegenerated = session_regenerate_id($destroy); - // The reference to $_SESSION in session bags is lost in PHP7 and we need to re-create it. - // @see https://bugs.php.net/70013 - $this->loadSession(); - if (null !== $this->emulateSameSite) { $originalCookie = SessionUtils::popSessionCookie(session_name(), session_id()); if (null !== $originalCookie) { From 9a692b69b244685bcb420c346736f6628bb79ace Mon Sep 17 00:00:00 2001 From: Guite Date: Sun, 9 Feb 2020 17:51:23 +0100 Subject: [PATCH 115/127] [HttpFoundation] Fixed session migration with custom cookie lifetime --- Session/Storage/NativeSessionStorage.php | 8 +++++--- Tests/Session/Storage/NativeSessionStorageTest.php | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 7502897a4..66343cd31 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -152,7 +152,7 @@ public function start() // ok to try and start the session if (!session_start()) { - throw new \RuntimeException('Failed to start the session'); + throw new \RuntimeException('Failed to start the session.'); } if (null !== $this->emulateSameSite) { @@ -213,8 +213,10 @@ public function regenerate($destroy = false, $lifetime = null) return false; } - if (null !== $lifetime) { + if (null !== $lifetime && $lifetime != ini_get('session.cookie_lifetime')) { + $this->save(); ini_set('session.cookie_lifetime', $lifetime); + $this->start(); } if ($destroy) { @@ -314,7 +316,7 @@ public function registerBag(SessionBagInterface $bag) public function getBag($name) { if (!isset($this->bags[$name])) { - throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); + throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name)); } if (!$this->started && $this->saveHandler->isActive()) { diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index d2cf32452..7cfcd223e 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -123,6 +123,19 @@ public function testRegenerateDestroy() $this->assertEquals(11, $storage->getBag('attributes')->get('legs')); } + public function testRegenerateWithCustomLifetime() + { + $storage = $this->getStorage(); + $storage->start(); + $id = $storage->getId(); + $lifetime = 999999; + $storage->getBag('attributes')->set('legs', 11); + $storage->regenerate(false, $lifetime); + $this->assertNotEquals($id, $storage->getId()); + $this->assertEquals(11, $storage->getBag('attributes')->get('legs')); + $this->assertEquals($lifetime, ini_get('session.cookie_lifetime')); + } + public function testSessionGlobalIsUpToDateAfterIdRegeneration() { $storage = $this->getStorage(); From eded33daef1147be7ff1249706be9a49fe2c7a44 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 18 Apr 2020 22:23:17 +0200 Subject: [PATCH 116/127] [HttpFoundation] workaround PHP bug in the session module --- Session/Storage/Handler/AbstractSessionHandler.php | 9 +++++++++ .../Session/Storage/Handler/Fixtures/regenerate.expected | 1 + 2 files changed, 10 insertions(+) diff --git a/Session/Storage/Handler/AbstractSessionHandler.php b/Session/Storage/Handler/AbstractSessionHandler.php index ec59d895c..c80da2046 100644 --- a/Session/Storage/Handler/AbstractSessionHandler.php +++ b/Session/Storage/Handler/AbstractSessionHandler.php @@ -71,6 +71,15 @@ public function validateId($sessionId) $this->prefetchData = $this->read($sessionId); $this->prefetchId = $sessionId; + if (\PHP_VERSION_ID < 70317 || (70400 <= \PHP_VERSION_ID && \PHP_VERSION_ID < 70405)) { + // work around https://bugs.php.net/79413 + foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { + if (!isset($frame['class']) && isset($frame['function']) && \in_array($frame['function'], ['session_regenerate_id', 'session_create_id'], true)) { + return '' === $this->prefetchData; + } + } + } + return '' !== $this->prefetchData; } diff --git a/Tests/Session/Storage/Handler/Fixtures/regenerate.expected b/Tests/Session/Storage/Handler/Fixtures/regenerate.expected index baa5f2f6f..d825f44f7 100644 --- a/Tests/Session/Storage/Handler/Fixtures/regenerate.expected +++ b/Tests/Session/Storage/Handler/Fixtures/regenerate.expected @@ -11,6 +11,7 @@ validateId read doRead: abc|i:123; read +doRead: abc|i:123; write doWrite: abc|i:123; From c880e630a37b7a3760eeaa7fffa073629fa6e101 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Fri, 1 May 2020 13:33:43 +0100 Subject: [PATCH 117/127] Execute docker dependent tests with github actions --- .../Storage/Handler/AbstractRedisSessionHandlerTestCase.php | 5 +++++ .../Storage/Handler/PredisClusterSessionHandlerTest.php | 3 +++ Tests/Session/Storage/Handler/PredisSessionHandlerTest.php | 3 +++ .../Session/Storage/Handler/RedisArraySessionHandlerTest.php | 3 +++ .../Storage/Handler/RedisClusterSessionHandlerTest.php | 3 +++ Tests/Session/Storage/Handler/RedisSessionHandlerTest.php | 3 +++ 6 files changed, 20 insertions(+) diff --git a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php index 8828be666..3f3982ff4 100644 --- a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php +++ b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php @@ -44,6 +44,11 @@ protected function setUp(): void if (!\extension_loaded('redis')) { self::markTestSkipped('Extension redis required.'); } + try { + (new \Redis())->connect(getenv('REDIS_HOST')); + } catch (\Exception $e) { + self::markTestSkipped($e->getMessage()); + } $host = getenv('REDIS_HOST') ?: 'localhost'; diff --git a/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php b/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php index 622b42da1..8926fb1a9 100644 --- a/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php @@ -13,6 +13,9 @@ use Predis\Client; +/** + * @group integration + */ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { protected function createRedisClient(string $host): Client diff --git a/Tests/Session/Storage/Handler/PredisSessionHandlerTest.php b/Tests/Session/Storage/Handler/PredisSessionHandlerTest.php index 5ecab116f..bb33a3d9a 100644 --- a/Tests/Session/Storage/Handler/PredisSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PredisSessionHandlerTest.php @@ -13,6 +13,9 @@ use Predis\Client; +/** + * @group integration + */ class PredisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { protected function createRedisClient(string $host): Client diff --git a/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php index 3ef6cb694..c2647c35b 100644 --- a/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisArraySessionHandlerTest.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; +/** + * @group integration + */ class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase { /** diff --git a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php index 8b4cd1cdd..278b3c876 100644 --- a/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisClusterSessionHandlerTest.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; +/** + * @group integration + */ class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { public static function setUpBeforeClass(): void diff --git a/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php b/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php index 71658f072..e7fb1ca19 100644 --- a/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/RedisSessionHandlerTest.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; +/** + * @group integration + */ class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase { /** From fbd216d2304b1a3fe38d6392b04729c8dd356359 Mon Sep 17 00:00:00 2001 From: vudaltsov Date: Sat, 16 May 2020 16:15:54 +0300 Subject: [PATCH 118/127] Properties $originalName and $mimeType are never null in UploadedFile --- File/UploadedFile.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/File/UploadedFile.php b/File/UploadedFile.php index 5b75dd84f..520615603 100644 --- a/File/UploadedFile.php +++ b/File/UploadedFile.php @@ -24,7 +24,7 @@ */ class UploadedFile extends File { - private $test = false; + private $test; private $originalName; private $mimeType; private $size; @@ -72,7 +72,7 @@ public function __construct($path, $originalName, $mimeType = null, $size = null * It is extracted from the request from which the file has been uploaded. * Then it should not be considered as a safe value. * - * @return string|null The original name + * @return string The original name */ public function getClientOriginalName() { @@ -101,7 +101,7 @@ public function getClientOriginalExtension() * For a trusted mime type, use getMimeType() instead (which guesses the mime * type based on the file content). * - * @return string|null The mime type + * @return string The mime type * * @see getMimeType() */ From 7c4bb04524fe8f5d328a70ed3d143253514cc4bf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 May 2020 10:37:50 +0200 Subject: [PATCH 119/127] Use ">=" for the "php" requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index efc4b9425..a8c7c24c4 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^7.1.3", + "php": ">=7.1.3", "symfony/mime": "^4.3|^5.0", "symfony/polyfill-mbstring": "~1.1" }, From 13edce22c862800f2b89cf8724c94e9b28afbc7e Mon Sep 17 00:00:00 2001 From: YaFou <33806646+YaFou@users.noreply.github.com> Date: Tue, 23 Jun 2020 08:49:14 +0200 Subject: [PATCH 120/127] [HttpFondation] Change file extension of "audio/mpeg" from "mpga" to "mp3" --- File/MimeType/MimeTypeExtensionGuesser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/File/MimeType/MimeTypeExtensionGuesser.php b/File/MimeType/MimeTypeExtensionGuesser.php index c0f9140c8..5a809a248 100644 --- a/File/MimeType/MimeTypeExtensionGuesser.php +++ b/File/MimeType/MimeTypeExtensionGuesser.php @@ -619,7 +619,7 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface 'audio/basic' => 'au', 'audio/midi' => 'mid', 'audio/mp4' => 'm4a', - 'audio/mpeg' => 'mpga', + 'audio/mpeg' => 'mp3', 'audio/ogg' => 'oga', 'audio/s3m' => 's3m', 'audio/silk' => 'sil', From cd70a529aeb658f6b71bc3f6f6cdf1a6e197c45e Mon Sep 17 00:00:00 2001 From: Juan Mrad Date: Tue, 23 Jun 2020 11:04:58 -0500 Subject: [PATCH 121/127] [MimeType] Duplicated MimeType due to PHP Bug --- File/MimeType/FileinfoMimeTypeGuesser.php | 8 +++++++- Tests/File/Fixtures/test.docx | Bin 0 -> 6062 bytes Tests/File/MimeType/MimeTypeTest.php | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Tests/File/Fixtures/test.docx diff --git a/File/MimeType/FileinfoMimeTypeGuesser.php b/File/MimeType/FileinfoMimeTypeGuesser.php index fc4bc4502..fa4c962d7 100644 --- a/File/MimeType/FileinfoMimeTypeGuesser.php +++ b/File/MimeType/FileinfoMimeTypeGuesser.php @@ -63,7 +63,13 @@ public function guess($path) if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) { return null; } + $mimeType = $finfo->file($path); - return $finfo->file($path); + if ($mimeType && 0 === (\strlen($mimeType) % 2)) { + $mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1); + $mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType; + } + + return $mimeType; } } diff --git a/Tests/File/Fixtures/test.docx b/Tests/File/Fixtures/test.docx new file mode 100644 index 0000000000000000000000000000000000000000..2e86b6fcea03c679370c996ba200ccb39d1dd83b GIT binary patch literal 6062 zcma)A2Q*x3*B)Z@=q=Gj38IH6K@bcvdMC>0WiUF4PK+91h#o{2(OdN1d$iG_iy9?L zw4dDXem6J&fA9MDS!>qJS+mbRXTSS7&+|UY&u*cS05CBz0i7xn%79;j==!^xy`w3Y zoeLCV=4fSS!RZdQ&58jlwsI2$DK$|u>`pV1(vk3Q`(q1i`QECIjM1(T9iNn2--abM zsxl&8X)K4&A9pOReLs5EowjNTTt~F^!qN2kx&k>>_fPjq-5LB`)GgHgS6PJ|pH(K+ zy2Px@ZwvkK@{_epx*r!kA`}ytZpNhbnX}npJ4`4oV}Pp!leAsRj0_i%uDBIMvP1DP zWBrXY1xPMP_$vVp6NP`!ObR2`a*a{l*&%lF;XOBT6J{!Qw!_i(VbosE$xlu<5C=@s7iwBrx8w{ zKty4bY)u~#*&~$fW@v&w{4NYlRC@Jo@|F%;O@dBqj7p;%cX{%k7QShRYh%BPD9v~D z0;T7N8Vg?rV)C)<66}9)V9#}a8y=EAGm(}Fjj!}$-pTSXA*RcDO|!`8{%!Lx*|zP; z8YRa`RIb`9%lF(B;{}5OFb4Cl;pj(jR)`|jgpd>yYJ4*Hg~N<*_6+;G7q&90kqD%Ec@ium-qTM*?x5xew5stfD=))kKf)z@6su8-{#A+ zh&Z?%!kv2?E|__wc4Zqk7v9@|0=`#xDUMWnuS?zO<%Pf9PZ%7;-<1gVy#fj?va}@-Yp*N^ihX$1c4kzKR|O zl)3^uB%m^l4xP5?*HLRtc>F^k(4x;BH=w}sez?ORaF+Ap~r?x&owhi50ea(3Fm&Efo}BX}i4 z(Zs?JE+nEMI`W*KWQ)>R8)Un0?aSaSHBy-nu^sw$jE#Is&0ZUkEZL#2Z4@XO%{QDt zvf2S9C`^$PNGXYc0 z1gjZ|Bx}T~^yv&kCZJgzmRfnm#eLNP(tCwJXtzU(OH5{pR)-oc{0cS?0B=R{#e|$9g>^mRguxL z?|vf~ges+CrBSgVkhhUtQR^FE0@vuQw8iN8=soa=F_w2n0GA>I&{)A&2I8|M#~A;IzXy2tV(s0+1(B z@69+vF*JyQD&W&HD&J_$GA}wb(b24v&X5@9=l$cfd`u9QH3_PJkeM@Syh=d3v#7oRBPkj=oLo=1kS!Iz@KTIy|2xEUX} zB#@z0q1@78E2D5ANy#ZiFVrHRu~p3t^Wh$E8o^QPa;zuxlB?r|j7B~7sF|*JDG&`BXs(jO9BO0k zBC)DIVE5arY1MXjYSj8EfR$_}@mV~z@!_+{8J3m2U=+A15h61fc_Ca8+OZp$2w+Sk zFU^RWB`wv{FMZJhS})}OifX#SMVOVZGx6HNPBhEAZ=8BHVU?|if)5U>p^C%rv9ZX5 zdfdhdJ70dZZ}F0bdw#_mYJ?2Ix(MwnG0x$Uz%Rv!uG5IBL@+B*brmpdIn~*5n=||%t zI*sx<^3wH$8pY#k?{l$t&P|C_z)c~YbwvY>&V)A}J9OqOFJp@oW?kO9Bq2B5clYt? z++wdje;2<&7JNV&m--d}Fn`UQ{|{OPY(4XyPHwHBLmP@Su?K?1)wq zq5;}n88hP??u%6x(Gy%!HOA!Qtyoasm@if<4CSsT*UMeI(Yv2d=$8z%d89#(;A}6`#?N@+7H^?Y`T%$MMPH5eZG4_jJLHjq9ZRLy z^tM$vxovySlu~K6)DuoMC-CWHq2Iccz_1^I^N3*LY|$YZ0@?oOWq5hqdHT zIW(nJN)uz*Ommy+$ml28hvqakq#YLZ%wFU#oYgYxaB6`)Kqo-~pXyx|&m_Q_(6~|a zhiJXCmMC03#AT-Oyj;hf zy4;)O*F;N(@o!T__2>KA(9z7+iR;(d;=DOi7!9`mDX)h_;8PQ&qqOoN$zV)Vy_sA0 z_fLX#@6m(hz0N`rjCg3HL2q|MJP!K9$CGG9;P$vBZkcIajs&2NG0_Tav4YtpN_bbI zwWy#Z@Se;h0)G>q>S0deuzBi7~i^hsc*-$yV3~ z4b9@spLoQu9#!}k7vT_$t?!9XeYEln(6fjn3)wA?O19L9(``M|8K@q$bZd~*)#16q-BH&(M0_zbV zy^Hh;KxHwTuwP2f{qV@t2+-DKd3J13vrXg5{3yKJy)!M(nr=N)tHTO?ZJ~M&MNUVM z$$U4e*&j=|!CFZ$Oy70HRFVM*3u#6;O{yg>2Wn>aU^tuc{;-thH2eGz(}VEt*X)l~ z4;v_(#1%%^(Mz;$M;T+Cyx#5{20eE7s94{BO>7v#5SGisSACY7>se9Ig1W+S;r`|i zQs=N7WGK0Q4z_Dz|K}$q{c}j1EzO{2Tt7c~ZeBmzI?wE<1*jVFC*A0r?aih%H_%){ zCrhRa!IX@4!8BGOag)j!Pe$ZkQX-dpQCdG42a`@hgN^n4$R@MS9!?3{QV$gsH`2th zCJnp?SK$@n3&>qu?qbND?#H&m)4doNS76hQoZ}CkLSCOe#6ym6OI%6zN~$hQc7}Im zLc#Fzj~{$an$7C6C5Z^p4omb~q3r5xI%UwW&Af5s9+D7ufklQE>}-Z&FF$-=`?f95 z!b*s2d5%c#=w@tnRFxD61dQQ+&4=Ug$lYNpyggK|F0PhAt9oW)mg zL@gZzpa`jxLA2T2hbpb7I!h}sL@;+i+$42!jN*xX{(k2qVSl!6#kMT3C`#y>3bUq%4Wt#d|UTI?qsxbyl= zRo3kN5uU*L&Ve^T)lpa4u@0op^SBO6yXtIqCFfB2nK%P_pe|%jbL!@>KzWikUjPhP=4MDOH->qxeRNh^$NZ8+@B2# zHcZ%4?Yz1iwP?Kfk##56`O85O?bY7l-hsW?)j@DD`pK&%DQdAa!Z+*8LQg~S$z0 zzmTncXbl?9-pqS2i?bxijYDoiT@|p`Am{4F*-#Hdtx*6!sHM-#t?8#*7Np}*x$o6+ zjL8!`lDI)T-+c6RD0)o2@MTdG6nA`yXTwhH3stWV`;!AMn2TuRKU>69P>y--Xxhc|$8)va{C2yuF#s)U9sNtk3#P62SOiCCMWlh}6 zozp`DHq2_{yV$hj``&s=VPwgiGnz5%cqzrPbvhJ140pHg?y=Qc^mEzU^~=!g zhXcbT$FuxQ{rZCM1kSfc&}yrj?)MK@wg+JgIj1vb8W=V;yz54-CqPK&6G6V>tgCC4 zif`%(y{_v9rX$l)h)9G}uz~c``Naol=8DhfX>!6t#nkfIW6s?`M_81ZW3|yp`*a5+ z7+cn~`ZR4Sd*d$pMb*idk(XH!7RF3TBpcU#xT)ZeJ#Vr<7AXd&+D8VJK0L9`UTL>Oy<&nC%dU83EC$0F7Pb`M}j zdy59MQy-frcJ@A2l0W-AzC%A{yYTwHSRF>`qXkbs^V3iTqd5FZY4dMUXEBg2(>WqX zSp_}eFt;vDl`Dt4<3g{=t_~4Nr;40(74?j^$qL$EERsNS`r--InelUb@{3z!7LX?M zXs4GnE2YwLsgS+R>MfF+bEBWONc=p3Z}VE0o@=`I2r$tIsiV5(_&k@mM3y0* zUt!!3E4^+;;DhUp|1|Z#(GBr6-RMbOZ~U)CuA#bzgPGIw8?vd00o%3QIDJDRPvMicGh2a?7^tCCbApKVP49kZmk-r z;n&=Te5H{kMqczDLxVsnx4GRn7I`o4bj$qHBul1b;w=s9{$!d8<}w+4^^QOZ1hYB* zgU-4UtUmG&%JUJO$H=xO3ir0c;6(7d62FM0#jg(Yx?0$(j^hBFw`6=8bz4s#8&z6d zgf&2O2aRN8qj=wMT3bSiXHzlY^3axA1?K6yS0sc<9d|#xpK`ZiZ8Z6)7Kt8WnmZR8 z*jFl&?fqo+(KkrJw7i#U@6x?si7)l7Hh>fX%a`{IaI}T%6oz^OBm*N1A#oRGa042W z46VnL4tFxSPG#}pUVECIq&RD{jNO23M)8!`D; zMB)BTTK=B+D~xWm* Inm-Hw4?2y0ApigX literal 0 HcmV?d00001 diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index 0418726b5..e38816687 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -60,6 +60,14 @@ public function testGuessFileWithUnknownExtension() $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension')); } + /** + * @requires PHP 7.0 + */ + public function testGuessWithDuplicatedFileType() + { + $this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')); + } + public function testGuessWithIncorrectPath() { $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException'); From b454f04ff65a7a51beccb7eb187a2e82a17942ad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 28 Jun 2020 17:22:27 +0200 Subject: [PATCH 122/127] Fix test that fails on old distros --- Tests/File/MimeType/MimeTypeTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/File/MimeType/MimeTypeTest.php b/Tests/File/MimeType/MimeTypeTest.php index e38816687..aca05f2d9 100644 --- a/Tests/File/MimeType/MimeTypeTest.php +++ b/Tests/File/MimeType/MimeTypeTest.php @@ -65,7 +65,13 @@ public function testGuessFileWithUnknownExtension() */ public function testGuessWithDuplicatedFileType() { - $this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')); + if ('application/zip' === MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')) { + $this->addToAssertionCount(1); + + return; + } + + $this->assertSame('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')); } public function testGuessWithIncorrectPath() From 3f65b22535283bf34a666b590e6aeead043223ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 30 Jun 2020 14:50:28 +0200 Subject: [PATCH 123/127] Removed comments and requirements relative to php <5.5 (not supported anymore) --- Tests/CookieTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index 169f91787..637cff0d0 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -115,9 +115,6 @@ public function testConstructorWithDateTime() $this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); } - /** - * @requires PHP 5.5 - */ public function testConstructorWithDateTimeImmutable() { $expire = new \DateTimeImmutable(); From b11fb1a8a2e65c392e233810ab34a00a747ae55e Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 16 Jul 2020 11:17:05 +0200 Subject: [PATCH 124/127] [SCA] Minor fixes on tests --- Tests/ResponseTest.php | 8 ++++---- .../Session/Storage/Handler/MongoDbSessionHandlerTest.php | 2 +- Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index b846cdad3..43dfa8a8b 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -592,20 +592,20 @@ public function testSetCache() $options = ['etag' => '"whatever"']; $response->setCache($options); - $this->assertEquals($response->getEtag(), '"whatever"'); + $this->assertEquals('"whatever"', $response->getEtag()); $now = $this->createDateTimeNow(); $options = ['last_modified' => $now]; $response->setCache($options); - $this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp()); + $this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp()); $options = ['max_age' => 100]; $response->setCache($options); - $this->assertEquals($response->getMaxAge(), 100); + $this->assertEquals(100, $response->getMaxAge()); $options = ['s_maxage' => 200]; $response->setCache($options); - $this->assertEquals($response->getMaxAge(), 200); + $this->assertEquals(200, $response->getMaxAge()); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index f0f43d05b..cbfda8e74 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -102,7 +102,7 @@ public function testRead() ->method('findOne') ->willReturnCallback(function ($criteria) use ($testTimeout) { $this->assertArrayHasKey($this->options['id_field'], $criteria); - $this->assertEquals($criteria[$this->options['id_field']], 'foo'); + $this->assertEquals('foo', $criteria[$this->options['id_field']]); $this->assertArrayHasKey($this->options['expiry_field'], $criteria); $this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]); diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 752be618b..700764840 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -87,10 +87,10 @@ public function testClear() $_SESSION['drak'] = 'loves symfony'; $storage->getBag('attributes')->set('symfony', 'greatness'); $key = $storage->getBag('attributes')->getStorageKey(); - $this->assertEquals($_SESSION[$key], ['symfony' => 'greatness']); - $this->assertEquals($_SESSION['drak'], 'loves symfony'); + $this->assertEquals(['symfony' => 'greatness'], $_SESSION[$key]); + $this->assertEquals('loves symfony', $_SESSION['drak']); $storage->clear(); - $this->assertEquals($_SESSION[$key], []); - $this->assertEquals($_SESSION['drak'], 'loves symfony'); + $this->assertEquals([], $_SESSION[$key]); + $this->assertEquals('loves symfony', $_SESSION['drak']); } } From 5219dba1253aa07ed3ad82f73c08146fb3f517d0 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 13 Jul 2020 00:27:19 +0200 Subject: [PATCH 125/127] Fix PHPUnit 8.5 deprecations. --- Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index 1457ebd70..3310cf9cb 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -127,7 +127,7 @@ public function testGc() */ public function testValidateId() { - $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); + $mock = $this->getMockBuilder(TestSessionHandler::class)->getMock(); $mock->expects($this->once()) ->method('validateId'); @@ -142,7 +142,7 @@ public function testValidateId() */ public function testUpdateTimestamp() { - $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); + $mock = $this->getMockBuilder(TestSessionHandler::class)->getMock(); $mock->expects($this->once()) ->method('updateTimestamp') ->willReturn(false); @@ -156,3 +156,7 @@ public function testUpdateTimestamp() $this->proxy->updateTimestamp('id', 'data'); } } + +abstract class TestSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface +{ +} From 91bdbf8c8824aa5a5fa44f79c05371c9bb524aae Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 8 Aug 2020 16:41:28 +0200 Subject: [PATCH 126/127] Modernized deprecated PHPUnit assertion calls --- Tests/BinaryFileResponseTest.php | 2 +- Tests/File/FileTest.php | 8 ++++---- Tests/File/UploadedFileTest.php | 2 +- Tests/RedirectResponseTest.php | 2 +- Tests/ResponseHeaderBagTest.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index fcad11def..31916fc7d 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -309,7 +309,7 @@ public function testDeleteFileAfterSend() $response->prepare($request); $response->sendContent(); - $this->assertFileNotExists($path); + $this->assertFileDoesNotExist($path); } public function testAcceptRangeOnUnsafeMethods() diff --git a/Tests/File/FileTest.php b/Tests/File/FileTest.php index b463aadf8..06a4ad8b1 100644 --- a/Tests/File/FileTest.php +++ b/Tests/File/FileTest.php @@ -83,7 +83,7 @@ public function testMove() $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile); $this->assertFileExists($targetPath); - $this->assertFileNotExists($path); + $this->assertFileDoesNotExist($path); $this->assertEquals(realpath($targetPath), $movedFile->getRealPath()); @unlink($targetPath); @@ -102,7 +102,7 @@ public function testMoveWithNewName() $movedFile = $file->move($targetDir, 'test.newname.gif'); $this->assertFileExists($targetPath); - $this->assertFileNotExists($path); + $this->assertFileDoesNotExist($path); $this->assertEquals(realpath($targetPath), $movedFile->getRealPath()); @unlink($targetPath); @@ -137,7 +137,7 @@ public function testMoveWithNonLatinName($filename, $sanitizedFilename) $this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile); $this->assertFileExists($targetPath); - $this->assertFileNotExists($path); + $this->assertFileDoesNotExist($path); $this->assertEquals(realpath($targetPath), $movedFile->getRealPath()); @unlink($targetPath); @@ -157,7 +157,7 @@ public function testMoveToAnUnexistentDirectory() $movedFile = $file->move($targetDir); $this->assertFileExists($targetPath); - $this->assertFileNotExists($sourcePath); + $this->assertFileDoesNotExist($sourcePath); $this->assertEquals(realpath($targetPath), $movedFile->getRealPath()); @unlink($sourcePath); diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 2ea924bac..4a8d2bb14 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -177,7 +177,7 @@ public function testMoveLocalFileIsAllowedInTestMode() $movedFile = $file->move(__DIR__.'/Fixtures/directory'); $this->assertFileExists($targetPath); - $this->assertFileNotExists($path); + $this->assertFileDoesNotExist($path); $this->assertEquals(realpath($targetPath), $movedFile->getRealPath()); @unlink($targetPath); diff --git a/Tests/RedirectResponseTest.php b/Tests/RedirectResponseTest.php index 2bbf5aa1a..47e5f8c64 100644 --- a/Tests/RedirectResponseTest.php +++ b/Tests/RedirectResponseTest.php @@ -20,7 +20,7 @@ public function testGenerateMetaRedirect() { $response = new RedirectResponse('foo.bar'); - $this->assertRegExp('##', preg_replace('/\s+/', ' ', $response->getContent())); + $this->assertMatchesRegularExpression('##', preg_replace('/\s+/', ' ', $response->getContent())); } public function testRedirectResponseConstructorNullUrl() diff --git a/Tests/ResponseHeaderBagTest.php b/Tests/ResponseHeaderBagTest.php index 632c96df5..028593a12 100644 --- a/Tests/ResponseHeaderBagTest.php +++ b/Tests/ResponseHeaderBagTest.php @@ -362,6 +362,6 @@ public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced() private function assertSetCookieHeader($expected, ResponseHeaderBag $actual) { - $this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual)); + $this->assertMatchesRegularExpression('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual)); } } From e3e5a62a6631a461954d471e7206e3750dbe8ee1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 17 Aug 2020 09:39:58 +0200 Subject: [PATCH 127/127] Fix CS --- Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 33f4efb5e..9f51e3b93 100644 --- a/Request.php +++ b/Request.php @@ -1589,7 +1589,7 @@ public function isNoCache() /** * Gets the preferred format for the response by inspecting, in the following order: * * the request format set using setRequestFormat - * * the values of the Accept HTTP header + * * the values of the Accept HTTP header. * * Note that if you use this method, you should send the "Vary: Accept" header * in the response to prevent any issues with intermediary HTTP caches. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy