diff --git a/BinaryFileResponse.php b/BinaryFileResponse.php index ad2cbda63..72cef7c0e 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 @@ -240,7 +240,7 @@ public function prepare(Request $request): static $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; @@ -311,14 +311,21 @@ public function sendContent(): static $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; - stream_copy_to_stream($file, $out, $read); - - if (connection_aborted()) { + if (false === $data = fread($file, $read)) { break; } + while ('' !== $data) { + $read = fwrite($out, $data); + if (false === $read || connection_aborted()) { + break; + } + if (0 < $length) { + $length -= $read; + } + $data = substr($data, $read); + } } fclose($out); diff --git a/Cookie.php b/Cookie.php index a68f745ee..9f43cc2ae 100644 --- a/Cookie.php +++ b/Cookie.php @@ -83,7 +83,7 @@ public static function create(string $name, string $value = null, int|string|\Da * @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/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 { diff --git a/IpUtils.php b/IpUtils.php index 8f78d1b1d..917eb6e1a 100644 --- a/IpUtils.php +++ b/IpUtils.php @@ -59,7 +59,7 @@ public static function checkIp(string $requestIp, string|array $ips): bool */ public static function checkIp4(string $requestIp, string $ip): bool { - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v4'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } @@ -104,7 +104,7 @@ public static function checkIp4(string $requestIp, string $ip): bool */ public static function checkIp6(string $requestIp, string $ip): bool { - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v6'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } 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 diff --git a/Request.php b/Request.php index 3cf8a9954..80866bb3b 100644 --- a/Request.php +++ b/Request.php @@ -189,7 +189,7 @@ class Request protected $session; /** - * @var string + * @var string|null */ protected $locale; @@ -426,12 +426,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 */ public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null): static { @@ -1367,7 +1367,7 @@ public function setLocale(string $locale) */ public function getLocale(): string { - return null === $this->locale ? $this->defaultLocale : $this->locale; + return $this->locale ?? $this->defaultLocale; } /** @@ -1436,6 +1436,7 @@ public function getProtocolVersion(): ?string * @param bool $asResource If true, a resource will be returned * * @return string|resource + * * @psalm-return ($asResource is true ? resource : string) */ public function getContent(bool $asResource = false) diff --git a/Response.php b/Response.php index d5c7129a5..c141cbc0b 100644 --- a/Response.php +++ b/Response.php @@ -758,8 +758,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; @@ -835,7 +837,7 @@ public function setSharedMaxAge(int $value): static * * 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 @@ -844,7 +846,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/Session/SessionInterface.php b/Session/SessionInterface.php index ae0c9b7d3..da2b3a37d 100644 --- a/Session/SessionInterface.php +++ b/Session/SessionInterface.php @@ -53,10 +53,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. */ public function invalidate(int $lifetime = null): bool; @@ -64,11 +64,11 @@ public function invalidate(int $lifetime = null): bool; * 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. */ public function migrate(bool $destroy = false, int $lifetime = null): bool; diff --git a/Session/Storage/Handler/NativeFileSessionHandler.php b/Session/Storage/Handler/NativeFileSessionHandler.php index e13fcc173..f6e73f9e6 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. * @@ -45,7 +45,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/Handler/PdoSessionHandler.php b/Session/Storage/Handler/PdoSessionHandler.php index 302372627..06429b4ba 100644 --- a/Session/Storage/Handler/PdoSessionHandler.php +++ b/Session/Storage/Handler/PdoSessionHandler.php @@ -441,8 +441,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 ??= 'pgsql:'; diff --git a/Session/Storage/MetadataBag.php b/Session/Storage/MetadataBag.php index f2be617ce..2c77f9db6 100644 --- a/Session/Storage/MetadataBag.php +++ b/Session/Storage/MetadataBag.php @@ -78,10 +78,10 @@ public function getLifetime(): int /** * 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/NativeSessionStorage.php b/Session/Storage/NativeSessionStorage.php index 834a5ebd6..8b8947882 100644 --- a/Session/Storage/NativeSessionStorage.php +++ b/Session/Storage/NativeSessionStorage.php @@ -305,7 +305,6 @@ public function setMetadataBag(MetadataBag $metaBag = null) trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); } $this->metadataBag = $metaBag ?? new MetadataBag(); - } /** diff --git a/Session/Storage/SessionStorageInterface.php b/Session/Storage/SessionStorageInterface.php index 36839e69f..8bd62a43a 100644 --- a/Session/Storage/SessionStorageInterface.php +++ b/Session/Storage/SessionStorageInterface.php @@ -72,11 +72,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. * * @throws \RuntimeException If an error occurs while regenerating this storage */ 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 59264af73..e8a194959 100644 --- a/Tests/BinaryFileResponseTest.php +++ b/Tests/BinaryFileResponseTest.php @@ -142,7 +142,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'], @@ -196,7 +196,7 @@ public function testFullFileRequests($requestRange) $this->assertEquals(200, $response->getStatusCode()); } - public function provideFullFileRanges() + public static function provideFullFileRanges() { return [ ['bytes=0-'], @@ -262,7 +262,7 @@ public function testInvalidRequests($requestRange) $this->assertEquals('bytes */35', $response->headers->get('Content-Range')); } - public function provideInvalidRanges() + public static function provideInvalidRanges() { return [ ['bytes=-40'], @@ -288,7 +288,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'], @@ -354,7 +354,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 39f3e398e..874758e9d 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 5a6f6c906..02917f3a3 100644 --- a/Tests/ExpressionRequestMatcherTest.php +++ b/Tests/ExpressionRequestMatcherTest.php @@ -54,7 +54,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 bc639a2ff..69179fc37 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( @@ -283,7 +283,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 5669f188a..bde49e7a9 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 */ @@ -27,7 +42,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 +73,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'], @@ -103,7 +118,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', '*'], @@ -120,7 +135,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'], @@ -146,7 +161,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/RequestMatcher/AttributesRequestMatcherTest.php b/Tests/RequestMatcher/AttributesRequestMatcherTest.php index 9ca887652..3f4fd39c3 100644 --- a/Tests/RequestMatcher/AttributesRequestMatcherTest.php +++ b/Tests/RequestMatcher/AttributesRequestMatcherTest.php @@ -32,7 +32,7 @@ public function test(string $key, string $regexp, bool $expected) $this->assertSame($expected, $matcher->matches($request)); } - public function getData(): array + public static function getData(): array { return [ ['foo', 'foo_.*', true], diff --git a/Tests/RequestMatcher/ExpressionRequestMatcherTest.php b/Tests/RequestMatcher/ExpressionRequestMatcherTest.php index 737aeceae..a0118e236 100644 --- a/Tests/RequestMatcher/ExpressionRequestMatcherTest.php +++ b/Tests/RequestMatcher/ExpressionRequestMatcherTest.php @@ -28,7 +28,7 @@ public function testMatchesWhenParentMatchesIsTrue($expression, $expected) $this->assertSame($expected, $expressionRequestMatcher->matches($request)); } - public function provideExpressions() + public static function provideExpressions() { return [ ['request.getMethod() == method', true], diff --git a/Tests/RequestMatcher/HostRequestMatcherTest.php b/Tests/RequestMatcher/HostRequestMatcherTest.php index 89f9d82b6..903bde088 100644 --- a/Tests/RequestMatcher/HostRequestMatcherTest.php +++ b/Tests/RequestMatcher/HostRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test($pattern, $isMatch) $this->assertSame($isMatch, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ ['.*\.example\.com', true], diff --git a/Tests/RequestMatcher/IpsRequestMatcherTest.php b/Tests/RequestMatcher/IpsRequestMatcherTest.php index 8dd0ec1bb..57014b50a 100644 --- a/Tests/RequestMatcher/IpsRequestMatcherTest.php +++ b/Tests/RequestMatcher/IpsRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test($ips, bool $expected) $this->assertSame($expected, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ [[], true], diff --git a/Tests/RequestMatcher/IsJsonRequestMatcherTest.php b/Tests/RequestMatcher/IsJsonRequestMatcherTest.php index f6be8655d..a32172ed5 100644 --- a/Tests/RequestMatcher/IsJsonRequestMatcherTest.php +++ b/Tests/RequestMatcher/IsJsonRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test($json, bool $isValid) $this->assertSame($isValid, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ ['not json', false], diff --git a/Tests/RequestMatcher/MethodRequestMatcherTest.php b/Tests/RequestMatcher/MethodRequestMatcherTest.php index fe6b48e3e..d4af82cd9 100644 --- a/Tests/RequestMatcher/MethodRequestMatcherTest.php +++ b/Tests/RequestMatcher/MethodRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test(string $requestMethod, array|string $matcherMethod, bool $i $this->assertSame($isMatch, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ ['get', 'get', true], diff --git a/Tests/RequestMatcher/PathRequestMatcherTest.php b/Tests/RequestMatcher/PathRequestMatcherTest.php index 28d4b294e..04ecdc913 100644 --- a/Tests/RequestMatcher/PathRequestMatcherTest.php +++ b/Tests/RequestMatcher/PathRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test(string $regexp, bool $expected) $this->assertSame($expected, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ ['/admin/.*', true], diff --git a/Tests/RequestMatcher/PortRequestMatcherTest.php b/Tests/RequestMatcher/PortRequestMatcherTest.php index 0d0edc503..77b394f8a 100644 --- a/Tests/RequestMatcher/PortRequestMatcherTest.php +++ b/Tests/RequestMatcher/PortRequestMatcherTest.php @@ -27,7 +27,7 @@ public function test(int $port, bool $expected) $this->assertSame($expected, $matcher->matches($request)); } - public function getData() + public static function getData() { return [ [8000, true], diff --git a/Tests/RequestMatcher/SchemeRequestMatcherTest.php b/Tests/RequestMatcher/SchemeRequestMatcherTest.php index bacadedb6..f8d83645f 100644 --- a/Tests/RequestMatcher/SchemeRequestMatcherTest.php +++ b/Tests/RequestMatcher/SchemeRequestMatcherTest.php @@ -42,7 +42,7 @@ public function test(string $requestScheme, array|string $matcherScheme, bool $i } } - public function getData() + public static function getData() { return [ ['http', 'http', true], diff --git a/Tests/RequestMatcherTest.php b/Tests/RequestMatcherTest.php index 0419d3693..5e028fc4a 100644 --- a/Tests/RequestMatcherTest.php +++ b/Tests/RequestMatcherTest.php @@ -36,7 +36,7 @@ public function testMethod($requestMethod, $matcherMethod, $isMatch) $this->assertSame($isMatch, $matcher->matches($request)); } - public function getMethodData() + public static function getMethodData() { return [ ['get', 'get', true], @@ -97,7 +97,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 23acd2e05..1ed4e5fcc 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -328,7 +328,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]; @@ -509,7 +509,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']], @@ -754,7 +754,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'], @@ -817,7 +817,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'], @@ -1034,7 +1034,7 @@ public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded $this->assertEquals($expected, $request->getClientIps()); } - public function getClientIpsForwardedProvider() + public static function getClientIpsForwardedProvider() { // $expected $remoteAddr $httpForwarded $trustedProxies return [ @@ -1047,7 +1047,7 @@ public function getClientIpsForwardedProvider() ]; } - public function getClientIpsProvider() + public static function getClientIpsProvider() { // $expected $remoteAddr $httpForwardedFor $trustedProxies return [ @@ -1143,7 +1143,7 @@ public function testGetClientIpsOnlyXHttpForwardedForTrusted($httpForwarded, $ht $this->assertSame(array_reverse(explode(',', $httpXForwardedFor)), $request->getClientIps()); } - public function getClientIpsWithConflictingHeadersProvider() + public static function getClientIpsWithConflictingHeadersProvider() { // $httpForwarded $httpXForwardedFor return [ @@ -1177,7 +1177,7 @@ public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwar $this->assertSame($expectedIps, $clientIps); } - public function getClientIpsWithAgreeingHeadersProvider() + public static function getClientIpsWithAgreeingHeadersProvider() { // $httpForwarded $httpXForwardedFor return [ @@ -1254,7 +1254,7 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second) $this->assertSame($a, $b); } - public function getContentCanBeCalledTwiceWithResourcesProvider() + public static function getContentCanBeCalledTwiceWithResourcesProvider() { return [ 'Fetch then fetch' => [false, false], @@ -1264,7 +1264,7 @@ public function getContentCanBeCalledTwiceWithResourcesProvider() ]; } - public function provideOverloadedMethods() + public static function provideOverloadedMethods() { return [ ['PUT'], @@ -1687,10 +1687,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() @@ -1756,7 +1753,7 @@ public function testGetBaseUrl($uri, $server, $expectedBaseUrl, $expectedPathInf $this->assertSame($expectedPathInfo, $request->getPathInfo(), 'pathInfo'); } - public function getBaseUrlData() + public static function getBaseUrlData() { return [ [ @@ -1884,7 +1881,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'], @@ -2059,7 +2056,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 [ [ @@ -2182,7 +2179,7 @@ public function testHostValidity($host, $isValid, $expectedHost = null, $expecte } } - public function getHostValidities() + public static function getHostValidities() { return [ ['.a', false], @@ -2195,7 +2192,7 @@ public function getHostValidities() ]; } - public function getLongHostNames() + public static function getLongHostNames() { return [ ['a'.str_repeat('.a', 40000)], @@ -2213,7 +2210,7 @@ public function testMethodIdempotent($method, $idempotent) $this->assertEquals($idempotent, $request->isMethodIdempotent()); } - public function methodIdempotentProvider() + public static function methodIdempotentProvider() { return [ ['HEAD', true], @@ -2239,7 +2236,7 @@ public function testMethodSafe($method, $safe) $this->assertEquals($safe, $request->isMethodSafe()); } - public function methodSafeProvider() + public static function methodSafeProvider() { return [ ['HEAD', true], @@ -2265,7 +2262,7 @@ public function testMethodCacheable($method, $cacheable) $this->assertEquals($cacheable, $request->isMethodCacheable()); } - public function methodCacheableProvider() + public static function methodCacheableProvider() { return [ ['HEAD', true], @@ -2301,7 +2298,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'], @@ -2316,7 +2313,7 @@ public function protocolVersionProvider() ]; } - public function nonstandardRequestsData() + public static function nonstandardRequestsData() { return [ ['', '', '/', 'http://host:8080/', ''], @@ -2485,7 +2482,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']], @@ -2505,7 +2502,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 aca283af0..5cffa87d0 100644 --- a/Tests/ResponseFunctionalTest.php +++ b/Tests/ResponseFunctionalTest.php @@ -48,7 +48,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 90734a8cf..7ab060ec1 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -39,24 +39,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(); - $responseSent = $response->send(); - $this->assertObjectHasAttribute('headers', $responseSent); - $this->assertObjectHasAttribute('content', $responseSent); - $this->assertObjectHasAttribute('version', $responseSent); - $this->assertObjectHasAttribute('statusCode', $responseSent); - $this->assertObjectHasAttribute('statusText', $responseSent); - $this->assertObjectHasAttribute('charset', $responseSent); + $responseSend = $response->send(); + $this->assertSame($response, $responseSend); } public function testGetCharset() @@ -120,12 +110,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(); @@ -341,9 +326,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'); @@ -462,7 +446,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)); @@ -888,7 +872,7 @@ public function testSetStatusCode($code, $text, $expectedText) $this->assertEquals($expectedText, $statusText->getValue($response)); } - public function getStatusCodeFixtures() + public static function getStatusCodeFixtures() { return [ ['200', null, 'OK'], @@ -1042,7 +1026,7 @@ public function testNoDeprecationsAreTriggered() $this->addToAssertionCount(1); } - public function validContentProvider() + public static function validContentProvider() { return [ 'obj' => [new StringableObject()], @@ -1087,7 +1071,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/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 e5937b7df..0e13f13fb 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 @@ -137,7 +138,7 @@ public function testSupportedParam(array $options, bool $supported) } } - public function getOptionFixtures(): array + public static function getOptionFixtures(): array { return [ [['prefix' => 'session'], true], @@ -178,7 +179,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 3e0e78441..d5e84d181 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( @@ -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/MongoDbSessionHandlerTest.php b/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index b67d0c30e..30e8cc0f9 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 ffb2e25bb..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 @@ -47,7 +48,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/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 34dad9685..eb6842a5e 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 @@ -326,7 +327,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 203c4b285..e91f06a92 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 @@ -37,7 +38,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/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')); diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index 717c6773c..9234e2b40 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 a4f45fec6..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 @@ -170,7 +171,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/StreamedResponseTest.php b/Tests/StreamedResponseTest.php index 3ebae422b..1ca1bb92a 100644 --- a/Tests/StreamedResponseTest.php +++ b/Tests/StreamedResponseTest.php @@ -116,12 +116,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(); diff --git a/Tests/UrlHelperTest.php b/Tests/UrlHelperTest.php index 05da3a0a3..168f69efe 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'], @@ -124,7 +124,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'],