From b2f319547d7c4240bd7adc798bfefc4340536c91 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 01/14] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 008370457..0138f8f07 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present 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 89d95d29043a7f65dc02351301b972aa51ebc9d2 Mon Sep 17 00:00:00 2001 From: pkruithof Date: Thu, 5 Jan 2023 11:56:58 +0100 Subject: [PATCH 02/14] [Response] `getMaxAge()` returns non-negative integer --- Response.php | 10 ++++++---- Tests/ResponseTest.php | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Response.php b/Response.php index d5c8cb45c..59e974d62 100644 --- a/Response.php +++ b/Response.php @@ -774,8 +774,10 @@ public function getMaxAge(): ?int return (int) $this->headers->getCacheControlDirective('max-age'); } - if (null !== $this->getExpires()) { - return (int) $this->getExpires()->format('U') - (int) $this->getDate()->format('U'); + if (null !== $expires = $this->getExpires()) { + $maxAge = (int) $expires->format('U') - (int) $this->getDate()->format('U'); + + return max($maxAge, 0); } return null; @@ -819,7 +821,7 @@ public function setSharedMaxAge(int $value): object * * It returns null when no freshness information is present in the response. * - * When the responses TTL is <= 0, the response may not be served from cache without first + * When the response's TTL is 0, the response may not be served from cache without first * revalidating with the origin. * * @final @@ -828,7 +830,7 @@ public function getTtl(): ?int { $maxAge = $this->getMaxAge(); - return null !== $maxAge ? $maxAge - $this->getAge() : null; + return null !== $maxAge ? max($maxAge - $this->getAge(), 0) : null; } /** diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 5885ab4b1..580099903 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -353,9 +353,8 @@ public function testGetMaxAge() $this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present'); $response = new Response(); - $response->headers->set('Cache-Control', 'must-revalidate'); $response->headers->set('Expires', -1); - $this->assertLessThanOrEqual(time() - 2 * 86400, $response->getExpires()->format('U')); + $this->assertSame(0, $response->getMaxAge()); $response = new Response(); $this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available'); @@ -436,7 +435,7 @@ public function testGetTtl() $response = new Response(); $response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)); - $this->assertLessThan(0, $response->getTtl(), '->getTtl() returns negative values when Expires is in past'); + $this->assertSame(0, $response->getTtl(), '->getTtl() returns zero when Expires is in past'); $response = new Response(); $response->headers->set('Expires', $response->getDate()->format(\DATE_RFC2822)); From 3b7cb42f71658e7b171947cfe32005f962a2ac34 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 4 Feb 2023 16:25:13 +0100 Subject: [PATCH 03/14] Fix some typos --- HeaderUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeaderUtils.php b/HeaderUtils.php index 1d56be080..46b1e6aed 100644 --- a/HeaderUtils.php +++ b/HeaderUtils.php @@ -138,7 +138,7 @@ public static function quote(string $s): string * Decodes a quoted string. * * If passed an unquoted string that matches the "token" construct (as - * defined in the HTTP specification), it is passed through verbatimly. + * defined in the HTTP specification), it is passed through verbatim. */ public static function unquote(string $s): string { From f92ada62da1b5a5ba491f6df20ec7ff0fadb87ff Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 4 Feb 2023 11:23:10 +0100 Subject: [PATCH 04/14] stop using assertObjectHasAttribute()/assertObjectHasNotAttribute() --- Tests/RequestTest.php | 5 +---- Tests/ResponseTest.php | 21 +++------------------ Tests/StreamedResponseTest.php | 7 +------ 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 058b5419a..bf311044f 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -1668,10 +1668,7 @@ public function testGetSession() $request->setSession(new Session(new MockArraySessionStorage())); $this->assertTrue($request->hasSession()); - $session = $request->getSession(); - $this->assertObjectHasAttribute('storage', $session); - $this->assertObjectHasAttribute('flashName', $session); - $this->assertObjectHasAttribute('attributeName', $session); + $this->assertInstanceOf(Session::class, $request->getSession()); } public function testHasPreviousSession() diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 580099903..48713e364 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -51,24 +51,14 @@ public function testSendHeaders() { $response = new Response(); $headers = $response->sendHeaders(); - $this->assertObjectHasAttribute('headers', $headers); - $this->assertObjectHasAttribute('content', $headers); - $this->assertObjectHasAttribute('version', $headers); - $this->assertObjectHasAttribute('statusCode', $headers); - $this->assertObjectHasAttribute('statusText', $headers); - $this->assertObjectHasAttribute('charset', $headers); + $this->assertSame($response, $headers); } public function testSend() { $response = new Response(); $responseSend = $response->send(); - $this->assertObjectHasAttribute('headers', $responseSend); - $this->assertObjectHasAttribute('content', $responseSend); - $this->assertObjectHasAttribute('version', $responseSend); - $this->assertObjectHasAttribute('statusCode', $responseSend); - $this->assertObjectHasAttribute('statusText', $responseSend); - $this->assertObjectHasAttribute('charset', $responseSend); + $this->assertSame($response, $responseSend); } public function testGetCharset() @@ -132,12 +122,7 @@ public function testSetNotModified() { $response = new Response('foo'); $modified = $response->setNotModified(); - $this->assertObjectHasAttribute('headers', $modified); - $this->assertObjectHasAttribute('content', $modified); - $this->assertObjectHasAttribute('version', $modified); - $this->assertObjectHasAttribute('statusCode', $modified); - $this->assertObjectHasAttribute('statusText', $modified); - $this->assertObjectHasAttribute('charset', $modified); + $this->assertSame($response, $modified); $this->assertEquals(304, $modified->getStatusCode()); ob_start(); diff --git a/Tests/StreamedResponseTest.php b/Tests/StreamedResponseTest.php index 4a58bca44..8f76371e0 100644 --- a/Tests/StreamedResponseTest.php +++ b/Tests/StreamedResponseTest.php @@ -127,12 +127,7 @@ public function testSetNotModified() { $response = new StreamedResponse(function () { echo 'foo'; }); $modified = $response->setNotModified(); - $this->assertObjectHasAttribute('headers', $modified); - $this->assertObjectHasAttribute('content', $modified); - $this->assertObjectHasAttribute('version', $modified); - $this->assertObjectHasAttribute('statusCode', $modified); - $this->assertObjectHasAttribute('statusText', $modified); - $this->assertObjectHasAttribute('charset', $modified); + $this->assertSame($response, $modified); $this->assertEquals(304, $modified->getStatusCode()); ob_start(); From 9fc7882d6eb752686ccb879b0f50e31083ac0b19 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 05/14] Migrate to `static` data providers using `rector/rector` --- Tests/AcceptHeaderItemTest.php | 4 +- Tests/AcceptHeaderTest.php | 10 ++--- Tests/BinaryFileResponseTest.php | 10 ++--- Tests/CookieTest.php | 2 +- Tests/ExpressionRequestMatcherTest.php | 2 +- Tests/File/FileTest.php | 2 +- Tests/File/UploadedFileTest.php | 4 +- Tests/HeaderUtilsTest.php | 8 ++-- Tests/IpUtilsTest.php | 10 ++--- .../AbstractRequestRateLimiterTest.php | 2 +- Tests/RequestMatcherTest.php | 4 +- Tests/RequestTest.php | 44 +++++++++---------- Tests/ResponseFunctionalTest.php | 2 +- Tests/ResponseTest.php | 6 +-- Tests/Session/Attribute/AttributeBagTest.php | 2 +- .../Attribute/NamespacedAttributeBagTest.php | 2 +- Tests/Session/SessionTest.php | 2 +- .../AbstractRedisSessionHandlerTestCase.php | 4 +- .../Handler/AbstractSessionHandlerTest.php | 2 +- .../Handler/IdentityMarshallerTest.php | 2 +- .../Handler/MemcachedSessionHandlerTest.php | 2 +- .../Handler/NativeFileSessionHandlerTest.php | 2 +- .../Storage/Handler/PdoSessionHandlerTest.php | 2 +- .../Handler/SessionHandlerFactoryTest.php | 2 +- .../Storage/Proxy/SessionHandlerProxyTest.php | 2 +- Tests/UrlHelperTest.php | 6 +-- 26 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Tests/AcceptHeaderItemTest.php b/Tests/AcceptHeaderItemTest.php index 516bd5551..7ec8c30fb 100644 --- a/Tests/AcceptHeaderItemTest.php +++ b/Tests/AcceptHeaderItemTest.php @@ -26,7 +26,7 @@ public function testFromString($string, $value, array $attributes) $this->assertEquals($attributes, $item->getAttributes()); } - public function provideFromStringData() + public static function provideFromStringData() { return [ [ @@ -57,7 +57,7 @@ public function testToString($value, array $attributes, $string) $this->assertEquals($string, (string) $item); } - public function provideToStringData() + public static function provideToStringData() { return [ [ diff --git a/Tests/AcceptHeaderTest.php b/Tests/AcceptHeaderTest.php index 1987e97fb..bf4582430 100644 --- a/Tests/AcceptHeaderTest.php +++ b/Tests/AcceptHeaderTest.php @@ -37,7 +37,7 @@ public function testFromString($string, array $items) $this->assertEquals($items, $parsed); } - public function provideFromStringData() + public static function provideFromStringData() { return [ ['', []], @@ -57,7 +57,7 @@ public function testToString(array $items, $string) $this->assertEquals($string, (string) $header); } - public function provideToStringData() + public static function provideToStringData() { return [ [[], ''], @@ -76,7 +76,7 @@ public function testFilter($string, $filter, array $values) $this->assertEquals($values, array_keys($header->all())); } - public function provideFilterData() + public static function provideFilterData() { return [ ['fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', ['fr-FR', 'fr']], @@ -92,7 +92,7 @@ public function testSorting($string, array $values) $this->assertEquals($values, array_keys($header->all())); } - public function provideSortingData() + public static function provideSortingData() { return [ 'quality has priority' => ['*;q=0.3,ISO-8859-1,utf-8;q=0.7', ['ISO-8859-1', 'utf-8', '*']], @@ -110,7 +110,7 @@ public function testDefaultValue($acceptHeader, $value, $expectedQuality) $this->assertSame($expectedQuality, $header->get($value)->getQuality()); } - public function provideDefaultValueData() + public static function provideDefaultValueData() { yield ['text/plain;q=0.5, text/html, text/x-dvi;q=0.8, *;q=0.3', 'text/xml', 0.3]; yield ['text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/xml', 0.3]; diff --git a/Tests/BinaryFileResponseTest.php b/Tests/BinaryFileResponseTest.php index 65d6fe085..222b5f298 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -165,7 +165,7 @@ public function testRequestsWithoutEtag($requestRange, $offset, $length, $respon $this->assertEquals($responseRange, $response->headers->get('Content-Range')); } - public function provideRanges() + public static function provideRanges() { return [ ['bytes=1-4', 1, 4, 'bytes 1-4/35'], @@ -219,7 +219,7 @@ public function testFullFileRequests($requestRange) $this->assertEquals(200, $response->getStatusCode()); } - public function provideFullFileRanges() + public static function provideFullFileRanges() { return [ ['bytes=0-'], @@ -285,7 +285,7 @@ public function testInvalidRequests($requestRange) $this->assertEquals('bytes */35', $response->headers->get('Content-Range')); } - public function provideInvalidRanges() + public static function provideInvalidRanges() { return [ ['bytes=-40'], @@ -311,7 +311,7 @@ public function testXSendfile($file) $this->assertStringContainsString('README.md', $response->headers->get('X-Sendfile')); } - public function provideXSendfileFiles() + public static function provideXSendfileFiles() { return [ [__DIR__.'/../README.md'], @@ -378,7 +378,7 @@ public function testAcceptRangeNotOverriden() $this->assertEquals('foo', $response->headers->get('Accept-Ranges')); } - public function getSampleXAccelMappings() + public static function getSampleXAccelMappings() { return [ ['/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'], diff --git a/Tests/CookieTest.php b/Tests/CookieTest.php index cd65e0eaa..ec5a4e28f 100644 --- a/Tests/CookieTest.php +++ b/Tests/CookieTest.php @@ -24,7 +24,7 @@ */ class CookieTest extends TestCase { - public function namesWithSpecialCharacters() + public static function namesWithSpecialCharacters() { return [ [',MyName'], diff --git a/Tests/ExpressionRequestMatcherTest.php b/Tests/ExpressionRequestMatcherTest.php index aab5f739c..918ea08cc 100644 --- a/Tests/ExpressionRequestMatcherTest.php +++ b/Tests/ExpressionRequestMatcherTest.php @@ -51,7 +51,7 @@ public function testMatchesWhenParentMatchesIsFalse($expression) $this->assertFalse($expressionRequestMatcher->matches($request)); } - public function provideExpressions() + public static function provideExpressions() { return [ ['request.getMethod() == method', true], diff --git a/Tests/File/FileTest.php b/Tests/File/FileTest.php index 868c53af9..fc806e951 100644 --- a/Tests/File/FileTest.php +++ b/Tests/File/FileTest.php @@ -93,7 +93,7 @@ public function testGetContent() $this->assertStringEqualsFile(__FILE__, $file->getContent()); } - public function getFilenameFixtures() + public static function getFilenameFixtures() { return [ ['original.gif', 'original.gif'], diff --git a/Tests/File/UploadedFileTest.php b/Tests/File/UploadedFileTest.php index 9a48a424a..8c7fe45b5 100644 --- a/Tests/File/UploadedFileTest.php +++ b/Tests/File/UploadedFileTest.php @@ -156,7 +156,7 @@ public function testMoveLocalFileIsNotAllowed() $file->move(__DIR__.'/Fixtures/directory'); } - public function failedUploadedFile() + public static function failedUploadedFile() { foreach ([\UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_EXTENSION, -1] as $error) { yield [new UploadedFile( @@ -298,7 +298,7 @@ public function testIsInvalidOnUploadError($error) $this->assertFalse($file->isValid()); } - public function uploadedFileErrorProvider() + public static function uploadedFileErrorProvider() { return [ [\UPLOAD_ERR_INI_SIZE], diff --git a/Tests/HeaderUtilsTest.php b/Tests/HeaderUtilsTest.php index 2b585a95d..73d3f150c 100644 --- a/Tests/HeaderUtilsTest.php +++ b/Tests/HeaderUtilsTest.php @@ -24,7 +24,7 @@ public function testSplit(array $expected, string $header, string $separator) $this->assertSame($expected, HeaderUtils::split($header, $separator)); } - public function provideHeaderToSplit(): array + public static function provideHeaderToSplit(): array { return [ [['foo=123', 'bar'], 'foo=123,bar', ','], @@ -111,7 +111,7 @@ public function testMakeDisposition($disposition, $filename, $filenameFallback, $this->assertEquals($expected, HeaderUtils::makeDisposition($disposition, $filename, $filenameFallback)); } - public function provideMakeDisposition() + public static function provideMakeDisposition() { return [ ['attachment', 'foo.html', 'foo.html', 'attachment; filename=foo.html'], @@ -132,7 +132,7 @@ public function testMakeDispositionFail($disposition, $filename) HeaderUtils::makeDisposition($disposition, $filename); } - public function provideMakeDispositionFail() + public static function provideMakeDispositionFail() { return [ ['attachment', 'foo%20bar.html'], @@ -152,7 +152,7 @@ public function testParseQuery(string $query, string $expected = null) $this->assertSame($expected ?? $query, http_build_query(HeaderUtils::parseQuery($query), '', '&')); } - public function provideParseQuery() + public static function provideParseQuery() { return [ ['a=b&c=d'], diff --git a/Tests/IpUtilsTest.php b/Tests/IpUtilsTest.php index 33d67303a..085790cf6 100644 --- a/Tests/IpUtilsTest.php +++ b/Tests/IpUtilsTest.php @@ -27,7 +27,7 @@ public function testIpv4($matches, $remoteAddr, $cidr) $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function getIpv4Data() + public static function getIpv4Data() { return [ [true, '192.168.1.1', '192.168.1.1'], @@ -58,7 +58,7 @@ public function testIpv6($matches, $remoteAddr, $cidr) $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function getIpv6Data() + public static function getIpv6Data() { return [ [true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'], @@ -130,7 +130,7 @@ public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp) $this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp)); } - public function invalidIpAddressData() + public static function invalidIpAddressData() { return [ 'invalid proxy wildcard' => ['192.168.20.13', '*'], @@ -147,7 +147,7 @@ public function testAnonymize($ip, $expected) $this->assertSame($expected, IpUtils::anonymize($ip)); } - public function anonymizedIpData() + public static function anonymizedIpData() { return [ ['192.168.1.1', '192.168.1.0'], @@ -173,7 +173,7 @@ public function testIp4SubnetMaskZero($matches, $remoteAddr, $cidr) $this->assertSame($matches, IpUtils::checkIp4($remoteAddr, $cidr)); } - public function getIp4SubnetMaskZeroData() + public static function getIp4SubnetMaskZeroData() { return [ [true, '1.2.3.4', '0.0.0.0/0'], diff --git a/Tests/RateLimiter/AbstractRequestRateLimiterTest.php b/Tests/RateLimiter/AbstractRequestRateLimiterTest.php index 4790eae18..4e102777a 100644 --- a/Tests/RateLimiter/AbstractRequestRateLimiterTest.php +++ b/Tests/RateLimiter/AbstractRequestRateLimiterTest.php @@ -33,7 +33,7 @@ public function testConsume(array $rateLimits, ?RateLimit $expected) $this->assertSame($expected, $rateLimiter->consume(new Request())); } - public function provideRateLimits() + public static function provideRateLimits() { $now = new \DateTimeImmutable(); diff --git a/Tests/RequestMatcherTest.php b/Tests/RequestMatcherTest.php index 18e269693..c0e640421 100644 --- a/Tests/RequestMatcherTest.php +++ b/Tests/RequestMatcherTest.php @@ -32,7 +32,7 @@ public function testMethod($requestMethod, $matcherMethod, $isMatch) $this->assertSame($isMatch, $matcher->matches($request)); } - public function getMethodData() + public static function getMethodData() { return [ ['get', 'get', true], @@ -93,7 +93,7 @@ public function testPort() $this->assertTrue($matcher->matches($request)); } - public function getHostData() + public static function getHostData() { return [ ['.*\.example\.com', true], diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index bf311044f..e5360807b 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -309,7 +309,7 @@ public function testGetRequestUri($serverRequestUri, $expected, $message) $this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.'); } - public function getRequestUriData() + public static function getRequestUriData() { $message = 'Do not modify the path.'; yield ['/foo', '/foo', $message]; @@ -490,7 +490,7 @@ public function testGetFormatWithCustomMimeType() $this->assertEquals('custom', $request->getFormat('application/vnd.foo.api;myversion=2.3')); } - public function getFormatToMimeTypeMapProvider() + public static function getFormatToMimeTypeMapProvider() { return [ ['txt', ['text/plain']], @@ -735,7 +735,7 @@ public function testGetRelativeUriForPath($expected, $pathinfo, $path) $this->assertEquals($expected, Request::create($pathinfo)->getRelativeUriForPath($path)); } - public function getRelativeUriForPathData() + public static function getRelativeUriForPathData() { return [ ['me.png', '/foo', '/me.png'], @@ -798,7 +798,7 @@ public function testGetQueryString($query, $expectedQuery, $msg) $this->assertSame($expectedQuery, $request->getQueryString(), $msg); } - public function getQueryStringNormalizationData() + public static function getQueryStringNormalizationData() { return [ ['foo', 'foo=', 'works with valueless parameters'], @@ -1015,7 +1015,7 @@ public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded $this->assertEquals($expected, $request->getClientIps()); } - public function getClientIpsForwardedProvider() + public static function getClientIpsForwardedProvider() { // $expected $remoteAddr $httpForwarded $trustedProxies return [ @@ -1028,7 +1028,7 @@ public function getClientIpsForwardedProvider() ]; } - public function getClientIpsProvider() + public static function getClientIpsProvider() { // $expected $remoteAddr $httpForwardedFor $trustedProxies return [ @@ -1124,7 +1124,7 @@ public function testGetClientIpsOnlyXHttpForwardedForTrusted($httpForwarded, $ht $this->assertSame(array_reverse(explode(',', $httpXForwardedFor)), $request->getClientIps()); } - public function getClientIpsWithConflictingHeadersProvider() + public static function getClientIpsWithConflictingHeadersProvider() { // $httpForwarded $httpXForwardedFor return [ @@ -1158,7 +1158,7 @@ public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwar $this->assertSame($expectedIps, $clientIps); } - public function getClientIpsWithAgreeingHeadersProvider() + public static function getClientIpsWithAgreeingHeadersProvider() { // $httpForwarded $httpXForwardedFor return [ @@ -1235,7 +1235,7 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second) $this->assertSame($a, $b); } - public function getContentCanBeCalledTwiceWithResourcesProvider() + public static function getContentCanBeCalledTwiceWithResourcesProvider() { return [ 'Fetch then fetch' => [false, false], @@ -1245,7 +1245,7 @@ public function getContentCanBeCalledTwiceWithResourcesProvider() ]; } - public function provideOverloadedMethods() + public static function provideOverloadedMethods() { return [ ['PUT'], @@ -1734,7 +1734,7 @@ public function testGetBaseUrl($uri, $server, $expectedBaseUrl, $expectedPathInf $this->assertSame($expectedPathInfo, $request->getPathInfo(), 'pathInfo'); } - public function getBaseUrlData() + public static function getBaseUrlData() { return [ [ @@ -1863,7 +1863,7 @@ public function testUrlencodedStringPrefix($string, $prefix, $expect) $this->assertSame($expect, $me->invoke($request, $string, $prefix)); } - public function urlencodedStringPrefixData() + public static function urlencodedStringPrefixData() { return [ ['foo', 'foo', 'foo'], @@ -2039,7 +2039,7 @@ public function testIISRequestUri($headers, $server, $expectedRequestUri) $this->assertEquals($subRequestUri, $subRequest->getRequestUri(), '->getRequestUri() is correct in sub request'); } - public function iisRequestUriProvider() + public static function iisRequestUriProvider() { return [ [ @@ -2162,7 +2162,7 @@ public function testHostValidity($host, $isValid, $expectedHost = null, $expecte } } - public function getHostValidities() + public static function getHostValidities() { return [ ['.a', false], @@ -2175,7 +2175,7 @@ public function getHostValidities() ]; } - public function getLongHostNames() + public static function getLongHostNames() { return [ ['a'.str_repeat('.a', 40000)], @@ -2193,7 +2193,7 @@ public function testMethodIdempotent($method, $idempotent) $this->assertEquals($idempotent, $request->isMethodIdempotent()); } - public function methodIdempotentProvider() + public static function methodIdempotentProvider() { return [ ['HEAD', true], @@ -2219,7 +2219,7 @@ public function testMethodSafe($method, $safe) $this->assertEquals($safe, $request->isMethodSafe()); } - public function methodSafeProvider() + public static function methodSafeProvider() { return [ ['HEAD', true], @@ -2245,7 +2245,7 @@ public function testMethodCacheable($method, $cacheable) $this->assertEquals($cacheable, $request->isMethodCacheable()); } - public function methodCacheableProvider() + public static function methodCacheableProvider() { return [ ['HEAD', true], @@ -2281,7 +2281,7 @@ public function testProtocolVersion($serverProtocol, $trustedProxy, $via, $expec $this->assertSame($expected, $request->getProtocolVersion()); } - public function protocolVersionProvider() + public static function protocolVersionProvider() { return [ 'untrusted with empty via' => ['HTTP/2.0', false, '', 'HTTP/2.0'], @@ -2296,7 +2296,7 @@ public function protocolVersionProvider() ]; } - public function nonstandardRequestsData() + public static function nonstandardRequestsData() { return [ ['', '', '/', 'http://host:8080/', ''], @@ -2467,7 +2467,7 @@ public function testTrustedProxiesRemoteAddr($serverRemoteAddr, $trustedProxies, $this->assertSame($result, Request::getTrustedProxies()); } - public function trustedProxiesRemoteAddr() + public static function trustedProxiesRemoteAddr() { return [ ['1.1.1.1', ['REMOTE_ADDR'], ['1.1.1.1']], @@ -2487,7 +2487,7 @@ public function testPreferSafeContent($server, bool $safePreferenceExpected) $this->assertEquals($safePreferenceExpected, $request->preferSafeContent()); } - public function preferSafeContentData() + public static function preferSafeContentData() { return [ [[], false], diff --git a/Tests/ResponseFunctionalTest.php b/Tests/ResponseFunctionalTest.php index aa24291ed..ed88ff574 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -52,7 +52,7 @@ public function testCookie($fixture) $this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result); } - public function provideCookie() + public static function provideCookie() { foreach (glob(__DIR__.'/Fixtures/response-functional/*.php') as $file) { yield [pathinfo($file, \PATHINFO_FILENAME)]; diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 48713e364..50198c2d7 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -847,7 +847,7 @@ public function testSetStatusCode($code, $text, $expectedText) $this->assertEquals($expectedText, $statusText->getValue($response)); } - public function getStatusCodeFixtures() + public static function getStatusCodeFixtures() { return [ ['200', null, 'OK'], @@ -1001,7 +1001,7 @@ public function testNoDeprecationsAreTriggered() $this->addToAssertionCount(1); } - public function validContentProvider() + public static function validContentProvider() { return [ 'obj' => [new StringableObject()], @@ -1046,7 +1046,7 @@ protected function provideResponse() * @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 */ - public function ianaCodesReasonPhrasesProvider() + public static function ianaCodesReasonPhrasesProvider() { // XML taken from https://www.iana.org/assignments/http-status-codes/http-status-codes.xml // (might not be up-to-date for older Symfony versions) diff --git a/Tests/Session/Attribute/AttributeBagTest.php b/Tests/Session/Attribute/AttributeBagTest.php index 6313967af..273efddf1 100644 --- a/Tests/Session/Attribute/AttributeBagTest.php +++ b/Tests/Session/Attribute/AttributeBagTest.php @@ -153,7 +153,7 @@ public function testClear() $this->assertEquals([], $this->bag->all()); } - public function attributesProvider() + public static function attributesProvider() { return [ ['hello', 'world', true], diff --git a/Tests/Session/Attribute/NamespacedAttributeBagTest.php b/Tests/Session/Attribute/NamespacedAttributeBagTest.php index fe7838408..4df76926b 100644 --- a/Tests/Session/Attribute/NamespacedAttributeBagTest.php +++ b/Tests/Session/Attribute/NamespacedAttributeBagTest.php @@ -182,7 +182,7 @@ public function testClear() $this->assertEquals([], $this->bag->all()); } - public function attributesProvider() + public static function attributesProvider() { return [ ['hello', 'world', true], diff --git a/Tests/Session/SessionTest.php b/Tests/Session/SessionTest.php index 8efb53549..56011ddb5 100644 --- a/Tests/Session/SessionTest.php +++ b/Tests/Session/SessionTest.php @@ -156,7 +156,7 @@ public function testClear($key, $value) $this->assertEquals([], $this->session->all()); } - public function setProvider() + public static function setProvider() { return [ ['foo', 'bar', ['foo' => 'bar']], diff --git a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php index 2ac7a99ea..d961ed3bf 100644 --- a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php +++ b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php @@ -140,7 +140,7 @@ public function testSupportedParam(array $options, bool $supported) } } - public function getOptionFixtures(): array + public static function getOptionFixtures(): array { return [ [['prefix' => 'session'], true], @@ -169,7 +169,7 @@ public function testUseTtlOption(int $ttl) $this->assertGreaterThan($redisTtl, $ttl + 5); } - public function getTtlFixtures(): array + public static function getTtlFixtures(): array { return [ ['ttl' => 5000], diff --git a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php index aca2bfd88..8e42f8427 100644 --- a/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php @@ -51,7 +51,7 @@ public function testSession($fixture) $this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result); } - public function provideSession() + public static function provideSession() { foreach (glob(__DIR__.'/Fixtures/*.php') as $file) { yield [pathinfo($file, \PATHINFO_FILENAME)]; diff --git a/Tests/Session/Storage/Handler/IdentityMarshallerTest.php b/Tests/Session/Storage/Handler/IdentityMarshallerTest.php index b26bc7e60..8019bd2e9 100644 --- a/Tests/Session/Storage/Handler/IdentityMarshallerTest.php +++ b/Tests/Session/Storage/Handler/IdentityMarshallerTest.php @@ -49,7 +49,7 @@ public function testUnmarshall() $this->assertEquals('data', $marshaller->unmarshall('data')); } - public function invalidMarshallDataProvider(): iterable + public static function invalidMarshallDataProvider(): iterable { return [ [['object' => new \stdClass()]], diff --git a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index 6abdf4eb0..2e2ec3647 100644 --- a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -147,7 +147,7 @@ public function testSupportedOptions($options, $supported) } } - public function getOptionFixtures() + public static function getOptionFixtures() { return [ [['prefix' => 'session'], true], diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index ffb2e25bb..fa3f838ce 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -47,7 +47,7 @@ public function testConstructSavePath($savePath, $expectedSavePath, $path) rmdir($path); } - public function savePathDataProvider() + public static function savePathDataProvider() { $base = sys_get_temp_dir(); diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 867a6692e..5b663336f 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -329,7 +329,7 @@ public function testUrlDsn($url, $expectedDsn, $expectedUser = null, $expectedPa } } - public function provideUrlDsnPairs() + public static function provideUrlDsnPairs() { yield ['mysql://localhost/test', 'mysql:host=localhost;dbname=test;']; yield ['mysql://localhost/test?charset=utf8mb4', 'mysql:charset=utf8mb4;host=localhost;dbname=test;']; diff --git a/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php b/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php index 4d2a7dd0c..c0077871e 100644 --- a/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php +++ b/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php @@ -37,7 +37,7 @@ public function testCreateFileHandler(string $connectionDSN, string $expectedPat $this->assertEquals($expectedPath, \ini_get('session.save_path')); } - public function provideConnectionDSN(): array + public static function provideConnectionDSN(): array { $base = sys_get_temp_dir(); diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index a4f45fec6..74cf9ec94 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -170,7 +170,7 @@ public function testNativeSessionStorageSaveHandlerName($handler) $this->assertSame('files', (new NativeSessionStorage([], $handler))->getSaveHandler()->getSaveHandlerName()); } - public function provideNativeSessionStorageHandler() + public static function provideNativeSessionStorageHandler() { return [ [new \SessionHandler()], diff --git a/Tests/UrlHelperTest.php b/Tests/UrlHelperTest.php index 7d96f730d..2057dd709 100644 --- a/Tests/UrlHelperTest.php +++ b/Tests/UrlHelperTest.php @@ -31,7 +31,7 @@ public function testGenerateAbsoluteUrl($expected, $path, $pathinfo) $this->assertEquals($expected, $helper->getAbsoluteUrl($path)); } - public function getGenerateAbsoluteUrlData() + public static function getGenerateAbsoluteUrlData() { return [ ['http://localhost/foo.png', '/foo.png', '/foo/bar.html'], @@ -83,7 +83,7 @@ public function testGenerateAbsoluteUrlWithoutRequestAndRequestContext($path) $this->assertEquals($path, $helper->getAbsoluteUrl($path)); } - public function getGenerateAbsoluteUrlRequestContextData() + public static function getGenerateAbsoluteUrlRequestContextData() { return [ ['/foo.png', '/foo', 'localhost', 'http', 80, 443, 'http://localhost/foo.png'], @@ -128,7 +128,7 @@ public function testGenerateRelativePath($expected, $path, $pathinfo) $this->assertEquals($expected, $urlHelper->getRelativePath($path)); } - public function getGenerateRelativePathData() + public static function getGenerateRelativePathData() { return [ ['../foo.png', '/foo.png', '/foo/bar.html'], From abd6575464bba3afcf5e6ff63231e820d1dd8459 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Feb 2023 10:33:00 +0100 Subject: [PATCH 06/14] CS fix --- Request.php | 4 ++-- Session/Storage/Handler/PdoSessionHandler.php | 4 ++-- StreamedResponse.php | 4 ++-- .../Storage/Handler/AbstractRedisSessionHandlerTestCase.php | 1 + Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php | 2 ++ .../Session/Storage/Handler/NativeFileSessionHandlerTest.php | 1 + Tests/Session/Storage/Handler/NullSessionHandlerTest.php | 1 + Tests/Session/Storage/Handler/PdoSessionHandlerTest.php | 1 + Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php | 1 + Tests/Session/Storage/NativeSessionStorageTest.php | 1 + Tests/Session/Storage/PhpBridgeSessionStorageTest.php | 1 + Tests/Session/Storage/Proxy/AbstractProxyTest.php | 5 +++++ Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php | 1 + 13 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Request.php b/Request.php index 10f779d27..f6cc498c0 100644 --- a/Request.php +++ b/Request.php @@ -1573,9 +1573,9 @@ public function getContent(bool $asResource = false) /** * Gets the request body decoded as array, typically from a JSON payload. * - * @throws JsonException When the body cannot be decoded to an array - * * @return array + * + * @throws JsonException When the body cannot be decoded to an array */ public function toArray() { diff --git a/Session/Storage/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 24c98940d..2d830200b 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -530,8 +530,8 @@ private function buildDsnFromUrl(string $dsnOrUrl): string return $dsn; } } - // If "unix_socket" is not in the query, we continue with the same process as pgsql - // no break + // If "unix_socket" is not in the query, we continue with the same process as pgsql + // no break case 'pgsql': $dsn ?? $dsn = 'pgsql:'; diff --git a/StreamedResponse.php b/StreamedResponse.php index 676cd6687..0599bd1e4 100644 --- a/StreamedResponse.php +++ b/StreamedResponse.php @@ -114,9 +114,9 @@ public function sendContent() /** * {@inheritdoc} * - * @throws \LogicException when the content is not null - * * @return $this + * + * @throws \LogicException when the content is not null */ public function setContent(?string $content) { diff --git a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php index d961ed3bf..cd8b31c60 100644 --- a/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php +++ b/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php @@ -16,6 +16,7 @@ /** * @requires extension redis + * * @group time-sensitive */ abstract class AbstractRedisSessionHandlerTestCase extends TestCase diff --git a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index ff9eabb09..1e6a05df2 100644 --- a/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -18,7 +18,9 @@ /** * @author Markus Bachmann + * * @group time-sensitive + * * @requires extension mongodb */ class MongoDbSessionHandlerTest extends TestCase diff --git a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index fa3f838ce..e93ed2d09 100644 --- a/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -21,6 +21,7 @@ * @author Drak * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class NativeFileSessionHandlerTest extends TestCase diff --git a/Tests/Session/Storage/Handler/NullSessionHandlerTest.php b/Tests/Session/Storage/Handler/NullSessionHandlerTest.php index 76a8594b3..27704b909 100644 --- a/Tests/Session/Storage/Handler/NullSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/NullSessionHandlerTest.php @@ -22,6 +22,7 @@ * @author Drak * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class NullSessionHandlerTest extends TestCase diff --git a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 5b663336f..4403cda3d 100644 --- a/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -16,6 +16,7 @@ /** * @requires extension pdo_sqlite + * * @group time-sensitive */ class PdoSessionHandlerTest extends TestCase diff --git a/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php b/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php index c0077871e..cecee7b47 100644 --- a/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php +++ b/Tests/Session/Storage/Handler/SessionHandlerFactoryTest.php @@ -22,6 +22,7 @@ * @author Simon * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class SessionHandlerFactoryTest extends TestCase diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index b7714b9b8..adf074e36 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -27,6 +27,7 @@ * These tests require separate processes. * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class NativeSessionStorageTest extends TestCase diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index c0c667545..e2fb93ebc 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -23,6 +23,7 @@ * These tests require separate processes. * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class PhpBridgeSessionStorageTest extends TestCase diff --git a/Tests/Session/Storage/Proxy/AbstractProxyTest.php b/Tests/Session/Storage/Proxy/AbstractProxyTest.php index c50082981..fde7a4a0a 100644 --- a/Tests/Session/Storage/Proxy/AbstractProxyTest.php +++ b/Tests/Session/Storage/Proxy/AbstractProxyTest.php @@ -56,6 +56,7 @@ public function testIsWrapper() /** * @runInSeparateProcess + * * @preserveGlobalState disabled */ public function testIsActive() @@ -67,6 +68,7 @@ public function testIsActive() /** * @runInSeparateProcess + * * @preserveGlobalState disabled */ public function testName() @@ -79,6 +81,7 @@ public function testName() /** * @runInSeparateProcess + * * @preserveGlobalState disabled */ public function testNameException() @@ -90,6 +93,7 @@ public function testNameException() /** * @runInSeparateProcess + * * @preserveGlobalState disabled */ public function testId() @@ -102,6 +106,7 @@ public function testId() /** * @runInSeparateProcess + * * @preserveGlobalState disabled */ public function testIdException() diff --git a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index 74cf9ec94..eed23fe0b 100644 --- a/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -22,6 +22,7 @@ * @author Drak * * @runTestsInSeparateProcesses + * * @preserveGlobalState disabled */ class SessionHandlerProxyTest extends TestCase From 16017a2b89aa77a2a6a46903b303a2a0e69590ff Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 16 Feb 2023 18:52:14 +0000 Subject: [PATCH 07/14] Fix Request locale property doc types --- Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Request.php b/Request.php index f6cc498c0..cf2d47377 100644 --- a/Request.php +++ b/Request.php @@ -191,7 +191,7 @@ class Request protected $session; /** - * @var string + * @var string|null */ protected $locale; @@ -1452,7 +1452,7 @@ public function setLocale(string $locale) */ public function getLocale() { - return null === $this->locale ? $this->defaultLocale : $this->locale; + return $this->locale ?? $this->defaultLocale; } /** From 3bb6ee5582366c4176d5ce596b380117c8200bbf Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Fri, 17 Feb 2023 21:51:27 +0100 Subject: [PATCH 08/14] Fix phpdocs in HttpClient, HttpFoundation, HttpKernel, Intl components --- Cookie.php | 2 +- Request.php | 12 ++++++------ Session/SessionInterface.php | 18 +++++++++--------- .../Handler/NativeFileSessionHandler.php | 6 +++--- Session/Storage/MetadataBag.php | 8 ++++---- Session/Storage/SessionStorageInterface.php | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cookie.php b/Cookie.php index b4b26c015..91024535b 100644 --- a/Cookie.php +++ b/Cookie.php @@ -80,7 +80,7 @@ public static function create(string $name, string $value = null, $expire = 0, ? * @param string $name The name of the cookie * @param string|null $value The value of the cookie * @param int|string|\DateTimeInterface $expire The time the cookie expires - * @param string $path The path on the server in which the cookie will be available on + * @param string|null $path The path on the server in which the cookie will be available on * @param string|null $domain The domain that the cookie is available to * @param bool|null $secure Whether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS * @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol diff --git a/Request.php b/Request.php index cf2d47377..28cebad16 100644 --- a/Request.php +++ b/Request.php @@ -439,12 +439,12 @@ public static function setFactory(?callable $callable) /** * Clones a request and overrides some of its parameters. * - * @param array $query The GET parameters - * @param array $request The POST parameters - * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...) - * @param array $cookies The COOKIE parameters - * @param array $files The FILES parameters - * @param array $server The SERVER parameters + * @param array|null $query The GET parameters + * @param array|null $request The POST parameters + * @param array|null $attributes The request attributes (parameters parsed from the PATH_INFO, ...) + * @param array|null $cookies The COOKIE parameters + * @param array|null $files The FILES parameters + * @param array|null $server The SERVER parameters * * @return static */ diff --git a/Session/SessionInterface.php b/Session/SessionInterface.php index b2f09fd0d..e67338337 100644 --- a/Session/SessionInterface.php +++ b/Session/SessionInterface.php @@ -59,10 +59,10 @@ public function setName(string $name); * Clears all session attributes and flashes and regenerates the * session and deletes the old session from persistence. * - * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value - * will leave the system settings unchanged, 0 sets the cookie - * to expire with browser session. Time is in seconds, and is - * not a Unix timestamp. + * @param int|null $lifetime Sets the cookie lifetime for the session cookie. A null value + * will leave the system settings unchanged, 0 sets the cookie + * to expire with browser session. Time is in seconds, and is + * not a Unix timestamp. * * @return bool */ @@ -72,11 +72,11 @@ public function invalidate(int $lifetime = null); * Migrates the current session to a new session id while maintaining all * session attributes. * - * @param bool $destroy Whether to delete the old session or leave it to garbage collection - * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value - * will leave the system settings unchanged, 0 sets the cookie - * to expire with browser session. Time is in seconds, and is - * not a Unix timestamp. + * @param bool $destroy Whether to delete the old session or leave it to garbage collection + * @param int|null $lifetime Sets the cookie lifetime for the session cookie. A null value + * will leave the system settings unchanged, 0 sets the cookie + * to expire with browser session. Time is in seconds, and is + * not a Unix timestamp. * * @return bool */ diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index 1ca4bfeb0..a446c0c41 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -19,9 +19,9 @@ class NativeFileSessionHandler extends \SessionHandler { /** - * @param string $savePath Path of directory to save session files - * Default null will leave setting as defined by PHP. - * '/path', 'N;/path', or 'N;octal-mode;/path + * @param string|null $savePath Path of directory to save session files + * Default null will leave setting as defined by PHP. + * '/path', 'N;/path', or 'N;octal-mode;/path * * @see https://php.net/session.configuration#ini.session.save-path for further details. * diff --git a/Session/Storage/MetadataBag.php b/Session/Storage/MetadataBag.php index 595a9e23c..52d332094 100644 --- a/Session/Storage/MetadataBag.php +++ b/Session/Storage/MetadataBag.php @@ -95,10 +95,10 @@ public function getLifetime() /** * Stamps a new session's metadata. * - * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value - * will leave the system settings unchanged, 0 sets the cookie - * to expire with browser session. Time is in seconds, and is - * not a Unix timestamp. + * @param int|null $lifetime Sets the cookie lifetime for the session cookie. A null value + * will leave the system settings unchanged, 0 sets the cookie + * to expire with browser session. Time is in seconds, and is + * not a Unix timestamp. */ public function stampNew(int $lifetime = null) { diff --git a/Session/Storage/SessionStorageInterface.php b/Session/Storage/SessionStorageInterface.php index b7f66e7c7..705374552 100644 --- a/Session/Storage/SessionStorageInterface.php +++ b/Session/Storage/SessionStorageInterface.php @@ -80,11 +80,11 @@ public function setName(string $name); * Otherwise session data could get lost again for concurrent requests with the * new ID. One result could be that you get logged out after just logging in. * - * @param bool $destroy Destroy session when regenerating? - * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value - * will leave the system settings unchanged, 0 sets the cookie - * to expire with browser session. Time is in seconds, and is - * not a Unix timestamp. + * @param bool $destroy Destroy session when regenerating? + * @param int|null $lifetime Sets the cookie lifetime for the session cookie. A null value + * will leave the system settings unchanged, 0 sets the cookie + * to expire with browser session. Time is in seconds, and is + * not a Unix timestamp. * * @return bool * From 7e9e8d04bee3378b9f1426c206a8777b83fa219e Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 21:48:01 +0100 Subject: [PATCH 09/14] [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()` --- Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index 2e2ec3647..a3aea2e8e 100644 --- a/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -45,7 +45,7 @@ protected function setUp(): void $this->memcached = $this->getMockBuilder(\Memcached::class) ->disableOriginalConstructor() - ->setMethods($methodsToMock) + ->onlyMethods($methodsToMock) ->getMock(); $this->storage = new MemcachedSessionHandler( From 9d7018b8f32baf79b9de8f767d127ef2894a59f6 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 20:42:33 +0100 Subject: [PATCH 10/14] [Tests] Remove occurrences of `withConsecutive()` --- .../Storage/Handler/StrictSessionHandlerTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php b/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php index 4f91016ac..68db5f4cf 100644 --- a/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php +++ b/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php @@ -84,8 +84,18 @@ public function testReadWithValidateIdMismatch() { $handler = $this->createMock(\SessionHandlerInterface::class); $handler->expects($this->exactly(2))->method('read') - ->withConsecutive(['id1'], ['id2']) - ->will($this->onConsecutiveCalls('data1', 'data2')); + ->willReturnCallback(function (...$args) { + static $series = [ + [['id1'], 'data1'], + [['id2'], 'data2'], + ]; + + [$expectedArgs, $return] = array_shift($series); + $this->assertSame($expectedArgs, $args); + + return $return; + }) + ; $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->validateId('id1')); From 44acb50bef1430364469e12d51f90a7e95ff539d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 20 Mar 2023 11:45:02 +0100 Subject: [PATCH 11/14] [FrameworkBundle] Fix wiring session.handler when handler_id is null --- Session/Storage/Handler/NativeFileSessionHandler.php | 8 ++++++-- Session/Storage/NativeSessionStorage.php | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index a446c0c41..52a103879 100644 --- a/Session/Storage/Handler/NativeFileSessionHandler.php +++ b/Session/Storage/Handler/NativeFileSessionHandler.php @@ -49,7 +49,11 @@ public function __construct(string $savePath = null) throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir)); } - ini_set('session.save_path', $savePath); - ini_set('session.save_handler', 'files'); + if ($savePath !== \ini_get('session.save_path')) { + ini_set('session.save_path', $savePath); + } + if ('files' !== \ini_get('session.save_handler')) { + ini_set('session.save_handler', 'files'); + } } } diff --git a/Session/Storage/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index a50c8270f..242478c42 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -455,9 +455,10 @@ public function setOptions(array $options) */ public function setSaveHandler($saveHandler = null) { - if (!$saveHandler instanceof AbstractProxy && - !$saveHandler instanceof \SessionHandlerInterface && - null !== $saveHandler) { + if (!$saveHandler instanceof AbstractProxy + && !$saveHandler instanceof \SessionHandlerInterface + && null !== $saveHandler + ) { throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.'); } From 023087f4c3400e5885956357bef1feaa32973727 Mon Sep 17 00:00:00 2001 From: Daniel Burger <48986191+danielburger1337@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:30:23 +0100 Subject: [PATCH 12/14] [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6 --- IpUtils.php | 4 ++-- Tests/IpUtilsTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/IpUtils.php b/IpUtils.php index 2f31284e3..49d9a9d74 100644 --- a/IpUtils.php +++ b/IpUtils.php @@ -73,7 +73,7 @@ public static function checkIp4(?string $requestIp, string $ip) return false; } - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v4'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } @@ -126,7 +126,7 @@ public static function checkIp6(?string $requestIp, string $ip) return false; } - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v6'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } diff --git a/Tests/IpUtilsTest.php b/Tests/IpUtilsTest.php index 085790cf6..f5ac4053b 100644 --- a/Tests/IpUtilsTest.php +++ b/Tests/IpUtilsTest.php @@ -19,6 +19,21 @@ class IpUtilsTest extends TestCase { use ExpectDeprecationTrait; + public function testSeparateCachesPerProtocol() + { + $ip = '192.168.52.1'; + $subnet = '192.168.0.0/16'; + + $this->assertFalse(IpUtils::checkIp6($ip, $subnet)); + $this->assertTrue(IpUtils::checkIp4($ip, $subnet)); + + $ip = '2a01:198:603:0:396e:4789:8e99:890f'; + $subnet = '2a01:198:603:0::/65'; + + $this->assertFalse(IpUtils::checkIp4($ip, $subnet)); + $this->assertTrue(IpUtils::checkIp6($ip, $subnet)); + } + /** * @dataProvider getIpv4Data */ From e90984bd02048c973609e11f7e407b474e5bab86 Mon Sep 17 00:00:00 2001 From: Mike Gladysch Date: Fri, 13 Jan 2023 15:29:48 +0100 Subject: [PATCH 13/14] [HttpFoundation] Fix memory limit problems in BinaryFileResponse --- BinaryFileResponse.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 6d7b80ad1..3d0f92d02 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -34,7 +34,7 @@ class BinaryFileResponse extends Response protected $offset = 0; protected $maxlen = -1; protected $deleteFileAfterSend = false; - protected $chunkSize = 8 * 1024; + protected $chunkSize = 16 * 1024; /** * @param \SplFileInfo|string $file The file to stream @@ -267,7 +267,7 @@ public function prepare(Request $request) $range = $request->headers->get('Range'); if (str_starts_with($range, 'bytes=')) { - [$start, $end] = explode('-', substr($range, 6), 2) + [0]; + [$start, $end] = explode('-', substr($range, 6), 2) + [1 => 0]; $end = ('' === $end) ? $fileSize - 1 : (int) $end; @@ -341,14 +341,15 @@ public function sendContent() $length = $this->maxlen; while ($length && !feof($file)) { - $read = ($length > $this->chunkSize) ? $this->chunkSize : $length; - $length -= $read; + $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length; + $read = stream_copy_to_stream($file, $out, $read); - stream_copy_to_stream($file, $out, $read); - - if (connection_aborted()) { + if (false === $read || connection_aborted()) { break; } + if (0 < $length) { + $length -= $read; + } } fclose($out); From af9fbb378f5f956c8f29d4886644c84c193780ac Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 18 Apr 2023 08:30:11 +0200 Subject: [PATCH 14/14] [HttpFoundation] Fix BinaryFileResponse --- BinaryFileResponse.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index 3d0f92d02..03cf1a23e 100644 --- a/BinaryFileResponse.php +++ b/BinaryFileResponse.php @@ -342,13 +342,19 @@ public function sendContent() $length = $this->maxlen; while ($length && !feof($file)) { $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length; - $read = stream_copy_to_stream($file, $out, $read); - if (false === $read || connection_aborted()) { + if (false === $data = fread($file, $read)) { break; } - if (0 < $length) { - $length -= $read; + while ('' !== $data) { + $read = fwrite($out, $data); + if (false === $read || connection_aborted()) { + break; + } + if (0 < $length) { + $length -= $read; + } + $data = substr($data, $read); } }