From 680d40f23e059fa3d15f356b58b8bd8a166136e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 18:59:34 +0000 Subject: [PATCH 01/20] QA: Removes unused import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 9eb8c55..7c351e7 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -11,7 +11,6 @@ use Dflydev\FigCookies\FigRequestCookies; use Dflydev\FigCookies\FigResponseCookies; use Dflydev\FigCookies\SetCookie; -use Mezzio\Session\GenerateIdPersistenceInterface; use Mezzio\Session\InitializePersistenceIdInterface; use Mezzio\Session\Session; use Mezzio\Session\SessionCookiePersistenceInterface; From 6b13253008cbbc1b17d2e5e3de85c331e0f55d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:00:28 +0000 Subject: [PATCH 02/20] QA: Rename private static property (camelCase) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 7c351e7..cb28d43 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -77,7 +77,7 @@ class PhpSessionPersistence implements InitializePersistenceIdInterface, Session private $cacheLimiter; /** @var array */ - private static $supported_cache_limiters = [ + private static $supportedCacheLimiters = [ 'nocache' => true, 'public' => true, 'private' => true, @@ -282,7 +282,7 @@ private function addCacheHeaders(ResponseInterface $response) : ResponseInterfac private function generateCacheHeaders() : array { // Unsupported cache_limiter - if (! isset(self::$supported_cache_limiters[$this->cacheLimiter])) { + if (! isset(self::$supportedCacheLimiters[$this->cacheLimiter])) { return []; } From bb8248f5c2eeabe8f00a1c5eb8e890a824ec1f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:01:34 +0000 Subject: [PATCH 03/20] QA: Moves constant definition before properties (top of the class) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index cb28d43..98b7e8a 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -52,6 +52,14 @@ */ class PhpSessionPersistence implements InitializePersistenceIdInterface, SessionPersistenceInterface { + /** + * This unusual past date value is taken from the php-engine source code and + * used "as is" for consistency. + */ + public const CACHE_PAST_DATE = 'Thu, 19 Nov 1981 08:52:00 GMT'; + + public const HTTP_DATE_FORMAT = 'D, d M Y H:i:s T'; + /** * Use non locking mode during session initialization? * @@ -84,14 +92,6 @@ class PhpSessionPersistence implements InitializePersistenceIdInterface, Session 'private_no_expire' => true, ]; - /** - * This unusual past date value is taken from the php-engine source code and - * used "as is" for consistency. - */ - public const CACHE_PAST_DATE = 'Thu, 19 Nov 1981 08:52:00 GMT'; - - public const HTTP_DATE_FORMAT = 'D, d M Y H:i:s T'; - /** * Memoize session ini settings before starting the request. * From 495cfff2ab7ef72d2ca4562c33aa8426cb74cc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:02:13 +0000 Subject: [PATCH 04/20] QA: Adds missing strict type declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/ConfigProvider.php | 2 ++ src/PhpSessionPersistence.php | 2 ++ test/ConfigProviderTest.php | 2 ++ test/PhpSessionPersistenceTest.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index dbe911c..bf6609b 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -6,6 +6,8 @@ * @license https://github.com/mezzio/mezzio-session-ext/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Mezzio\Session\Ext; use Mezzio\Session\SessionPersistenceInterface; diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 98b7e8a..2a4580b 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -6,6 +6,8 @@ * @license https://github.com/mezzio/mezzio-session-ext/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace Mezzio\Session\Ext; use Dflydev\FigCookies\FigRequestCookies; diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 43380e7..1c3e099 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -6,6 +6,8 @@ * @license https://github.com/mezzio/mezzio-session-ext/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace MezzioTest\Session\Ext; use Mezzio\Session\Ext\ConfigProvider; diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index c8863d9..eed5ad3 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -6,6 +6,8 @@ * @license https://github.com/mezzio/mezzio-session-ext/blob/master/LICENSE.md New BSD License */ +declare(strict_types=1); + namespace MezzioTest\Session\Ext; use Dflydev\FigCookies\Cookie; From 5e30c91b278b72386842d8173a7991ba8a749dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:11:24 +0000 Subject: [PATCH 05/20] QA: Swaps yoda conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 18 +++++++++--------- test/PhpSessionPersistenceTest.php | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 2a4580b..2c06e5b 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -130,7 +130,7 @@ public function persistSession(SessionInterface $session, ResponseInterface $res // - the session is marked as regenerated // - the id is empty, but the data has changed (new session) if ($session->isRegenerated() - || ('' === $id && $session->hasChanged()) + || ($id === '' && $session->hasChanged()) ) { $id = $this->regenerateSession(); } elseif ($this->nonLocking && $session->hasChanged()) { @@ -138,7 +138,7 @@ public function persistSession(SessionInterface $session, ResponseInterface $res $this->startSession($id); } - if (PHP_SESSION_ACTIVE === session_status()) { + if (session_status() === PHP_SESSION_ACTIVE) { $_SESSION = $session->toArray(); session_write_close(); } @@ -146,7 +146,7 @@ public function persistSession(SessionInterface $session, ResponseInterface $res // If we do not have an identifier at this point, it means a new // session was created, but never written to. In that case, there's // no reason to provide a cookie back to the user. - if ('' === $id) { + if ($id === '') { return $response; } @@ -164,7 +164,7 @@ public function persistSession(SessionInterface $session, ResponseInterface $res public function initializeId(SessionInterface $session): SessionInterface { $id = $session->getId(); - if ('' === $id || $session->isRegenerated()) { + if ($id === '' || $session->isRegenerated()) { $session = new Session($session->toArray(), $this->generateSessionId()); } @@ -191,7 +191,7 @@ private function startSession(string $id, array $options = []) : void */ private function regenerateSession() : string { - if (PHP_SESSION_ACTIVE === session_status()) { + if (session_status() === PHP_SESSION_ACTIVE) { session_destroy(); } @@ -269,7 +269,7 @@ private function addCacheHeaders(ResponseInterface $response) : ResponseInterfac $cacheHeaders = $this->generateCacheHeaders(); foreach ($cacheHeaders as $name => $value) { - if (false !== $value) { + if ($value !== false) { $response = $response->withHeader($name, $value); } } @@ -289,7 +289,7 @@ private function generateCacheHeaders() : array } // cache_limiter: 'nocache' - if ('nocache' === $this->cacheLimiter) { + if ($this->cacheLimiter === 'nocache') { return [ 'Expires' => self::CACHE_PAST_DATE, 'Cache-Control' => 'no-store, no-cache, must-revalidate', @@ -301,7 +301,7 @@ private function generateCacheHeaders() : array $lastModified = $this->getLastModified(); // cache_limiter: 'public' - if ('public' === $this->cacheLimiter) { + if ($this->cacheLimiter === 'public') { return [ 'Expires' => gmdate(self::HTTP_DATE_FORMAT, time() + $maxAge), 'Cache-Control' => sprintf('public, max-age=%d', $maxAge), @@ -310,7 +310,7 @@ private function generateCacheHeaders() : array } // cache_limiter: 'private' - if ('private' === $this->cacheLimiter) { + if ($this->cacheLimiter === 'private') { return [ 'Expires' => self::CACHE_PAST_DATE, 'Cache-Control' => sprintf('private, max-age=%d', $maxAge), diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index eed5ad3..6088e26 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -428,7 +428,7 @@ public function testPersistSessionInjectsExpectedLastModifiedHeader() $response = $persistence->persistSession($session, new Response()); $lastmod = getlastmod(); - if (false === $lastmod) { + if ($lastmod === false) { $rc = new ReflectionClass($persistence); $classFile = $rc->getFileName(); $lastmod = filemtime($classFile); @@ -436,10 +436,10 @@ public function testPersistSessionInjectsExpectedLastModifiedHeader() $lastModified = $lastmod ? gmdate(PhpSessionPersistence::HTTP_DATE_FORMAT, $lastmod) : false; - $expectedHeaderLine = false === $lastModified ? '' : $lastModified; + $expectedHeaderLine = $lastModified === false ? '' : $lastModified; $this->assertSame($expectedHeaderLine, $response->getHeaderLine('Last-Modified')); - if (false === $lastModified) { + if ($lastModified === false) { $this->assertFalse($response->hasHeader('Last-Modified')); } From 2d6fd30170c7ce12528267d2ab7045a800e3c6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:13:32 +0000 Subject: [PATCH 06/20] QA: Imports internal PHP functions and constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 2 ++ test/PhpSessionPersistenceTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 2c06e5b..a68cce3 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -23,6 +23,7 @@ use function bin2hex; use function filemtime; +use function filter_var; use function getlastmod; use function gmdate; use function ini_get; @@ -31,6 +32,7 @@ use function session_id; use function session_name; use function session_start; +use function session_status; use function session_write_close; use function sprintf; use function time; diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 6088e26..cba721a 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -26,17 +26,32 @@ use ReflectionMethod; use function filemtime; +use function filter_var; use function getlastmod; +use function glob; use function gmdate; use function ini_get; +use function ini_set; +use function intval; +use function is_bool; +use function is_dir; +use function mkdir; use function session_id; use function session_name; use function session_save_path; +use function session_set_cookie_params; use function session_start; use function session_status; +use function session_write_close; +use function sprintf; +use function strtotime; +use function strval; use function sys_get_temp_dir; use function time; +use function unlink; +use const FILTER_NULL_ON_FAILURE; +use const FILTER_VALIDATE_BOOLEAN; use const PHP_SESSION_ACTIVE; use const PHP_SESSION_NONE; From 123f4cc1846e96697492d0b9826db4cabed64a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:28:12 +0000 Subject: [PATCH 07/20] QA: Updates PHPUnit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- composer.json | 2 +- test/ConfigProviderTest.php | 2 +- test/PhpSessionPersistenceTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 34512d3..41ee6cf 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", "laminas/laminas-diactoros": "^1.6", - "phpunit/phpunit": "^7.0.2" + "phpunit/phpunit": "^7.5.20 || ^8.5.2 || ^9.0.1" }, "conflict": { "phpspec/prophecy": "<1.7.2" diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 1c3e099..0197fc9 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -15,7 +15,7 @@ class ConfigProviderTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->provider = new ConfigProvider(); } diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index cba721a..3085764 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -75,7 +75,7 @@ class PhpSessionPersistenceTest extends TestCase */ private $sessionSavePath; - public function setUp() + protected function setUp() : void { $this->sessionSavePath = sys_get_temp_dir() . "/mezzio-session-ext"; @@ -91,7 +91,7 @@ public function setUp() $this->persistence = new PhpSessionPersistence(); } - public function tearDown() + protected function tearDown() : void { session_write_close(); $this->restoreOriginalSessionIniSettings($this->originalSessionSettings); From 256edf659db665691367538c76846a2aa6fa7408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:28:32 +0000 Subject: [PATCH 08/20] QA: Removes redundant bracket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index a68cce3..5ded78c 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -344,12 +344,10 @@ private function getLastModified() */ private function responseAlreadyHasCacheHeaders(ResponseInterface $response) : bool { - return ( - $response->hasHeader('Expires') + return $response->hasHeader('Expires') || $response->hasHeader('Last-Modified') || $response->hasHeader('Cache-Control') - || $response->hasHeader('Pragma') - ); + || $response->hasHeader('Pragma'); } private function getCookieLifetime(SessionInterface $session) : int From b7b2267b27501df5abf6e2552aae83f0d9db422f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:28:43 +0000 Subject: [PATCH 09/20] QA: Adds missing space before RTH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 5ded78c..744607c 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -163,7 +163,7 @@ public function persistSession(SessionInterface $session, ResponseInterface $res return $response; } - public function initializeId(SessionInterface $session): SessionInterface + public function initializeId(SessionInterface $session) : SessionInterface { $id = $session->getId(); if ($id === '' || $session->isRegenerated()) { From 984a09c0ead50f5176e44afe341e0ab9dc477b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:29:34 +0000 Subject: [PATCH 10/20] QA: Better assertions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/ConfigProviderTest.php | 5 +++-- test/PhpSessionPersistenceFactoryTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 0197fc9..d0b6a0a 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -23,7 +23,8 @@ protected function setUp() : void public function testInvocationReturnsArray() { $config = ($this->provider)(); - $this->assertInternalType('array', $config); + $this->assertIsArray($config); + return $config; } @@ -33,6 +34,6 @@ public function testInvocationReturnsArray() public function testReturnedArrayContainsDependencies(array $config) { $this->assertArrayHasKey('dependencies', $config); - $this->assertInternalType('array', $config['dependencies']); + $this->assertIsArray($config['dependencies']); } } diff --git a/test/PhpSessionPersistenceFactoryTest.php b/test/PhpSessionPersistenceFactoryTest.php index 365335c..3bd7e7d 100644 --- a/test/PhpSessionPersistenceFactoryTest.php +++ b/test/PhpSessionPersistenceFactoryTest.php @@ -17,7 +17,7 @@ class PhpSessionPersistenceFactoryTest extends TestCase { - public function testFactoryConfigProducesPhpSessionPersistenceInterfaceService() + public function testFactoryConfigProducesPhpSessionPersistenceInterfaceService() : void { $container = $this->prophesize(ContainerInterface::class); $factory = new PhpSessionPersistenceFactory(); From 6fa5fd5b27eaa40a964c2a8b23bb33a4512e4e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:29:46 +0000 Subject: [PATCH 11/20] QA: Fixes typo in test name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/PhpSessionPersistenceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 3085764..5cc9b33 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -719,7 +719,7 @@ public function testNoMultipleEmptySessionFilesAreCreatedIfNoSessionCookiePresen $this->restoreOriginalSessionIniSettings($ini); } - public function testOnlyOneSessionFileIsCreatedIfNoSessionCookiePresentINFirstRequestButSessionDataChanged() + public function testOnlyOneSessionFileIsCreatedIfNoSessionCookiePresentInFirstRequestButSessionDataChanged() { $sessionName = 'NOSESSIONCOOKIESESSID'; $ini = $this->applyCustomSessionOptions([ From b7731be1b459d941fa549355a676e735318d61db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:30:30 +0000 Subject: [PATCH 12/20] QA: CamelCase variable names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/PhpSessionPersistenceTest.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 5cc9b33..90430fd 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -32,7 +32,6 @@ use function gmdate; use function ini_get; use function ini_set; -use function intval; use function is_bool; use function is_dir; use function mkdir; @@ -45,7 +44,6 @@ use function session_write_close; use function sprintf; use function strtotime; -use function strval; use function sys_get_temp_dir; use function time; use function unlink; @@ -137,9 +135,9 @@ private function applyCustomSessionOptions(array $options) { $ini = []; foreach ($options as $key => $value) { - $ini_key = "session.{$key}"; - $ini[$ini_key] = ini_get($ini_key); - ini_set($ini_key, strval(is_bool($value) ? intval($value) : $value)); + $iniKey = "session.{$key}"; + $ini[$iniKey] = ini_get($iniKey); + ini_set($iniKey, (string) (is_bool($value) ? (int) $value : $value)); } return $ini; @@ -675,13 +673,13 @@ public function testStartSessionDoesNotOverrideRequiredSettings() $filter = FILTER_VALIDATE_BOOLEAN; $flags = FILTER_NULL_ON_FAILURE; - $session_use_cookies = filter_var(ini_get('session.use_cookies'), $filter, $flags); - $session_use_only_cookies = filter_var(ini_get('session.use_only_cookies'), $filter, $flags); - $session_cache_limiter = ini_get('session.cache_limiter'); + $sessionUseCookies = filter_var(ini_get('session.use_cookies'), $filter, $flags); + $sessionUseOnlyCookies = filter_var(ini_get('session.use_only_cookies'), $filter, $flags); + $sessionCacheLimiter = ini_get('session.cache_limiter'); - $this->assertFalse($session_use_cookies); - $this->assertTrue($session_use_only_cookies); - $this->assertSame('', $session_cache_limiter); + $this->assertFalse($sessionUseCookies); + $this->assertTrue($sessionUseOnlyCookies); + $this->assertSame('', $sessionCacheLimiter); } public function testNoMultipleEmptySessionFilesAreCreatedIfNoSessionCookiePresent() From d265e8a5110aeaee7eb5c0c8e367a4cffb9c7eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:31:06 +0000 Subject: [PATCH 13/20] QA: Signature updates in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/ConfigProviderTest.php | 4 ++-- test/PhpSessionPersistenceTest.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index d0b6a0a..8cc0dad 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -20,7 +20,7 @@ protected function setUp() : void $this->provider = new ConfigProvider(); } - public function testInvocationReturnsArray() + public function testInvocationReturnsArray() : array { $config = ($this->provider)(); $this->assertIsArray($config); @@ -31,7 +31,7 @@ public function testInvocationReturnsArray() /** * @depends testInvocationReturnsArray */ - public function testReturnedArrayContainsDependencies(array $config) + public function testReturnedArrayContainsDependencies(array $config) : void { $this->assertArrayHasKey('dependencies', $config); $this->assertIsArray($config['dependencies']); diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 90430fd..fd50c5e 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -103,7 +103,7 @@ protected function tearDown() : void } } - public function startSession(string $id = null, array $options = []) + public function startSession(?string $id = null, array $options = []) : void { $id = $id ?: 'testing'; session_id($id); @@ -113,11 +113,11 @@ public function startSession(string $id = null, array $options = []) ] + $options); } - /** - * @return ServerRequestInterface - */ - private function createSessionCookieRequest($sessionId = null, string $sessionName = null, array $serverParams = []) - { + private function createSessionCookieRequest( + ?string $sessionId = null, + ?string $sessionName = null, + array $serverParams = [] + ) : ServerRequestInterface { return FigRequestCookies::set( new ServerRequest($serverParams), Cookie::create( @@ -131,7 +131,7 @@ private function createSessionCookieRequest($sessionId = null, string $sessionNa * @param array $options Custom session options (without the "session" namespace) * @return array Return the original (and overwritten) namespaced ini settings */ - private function applyCustomSessionOptions(array $options) + private function applyCustomSessionOptions(array $options) : array { $ini = []; foreach ($options as $key => $value) { @@ -146,14 +146,14 @@ private function applyCustomSessionOptions(array $options) /** * @param array $ini The original session namespaced ini settings */ - private function restoreOriginalSessionIniSettings(array $ini) + private function restoreOriginalSessionIniSettings(array $ini) : void { foreach ($ini as $key => $value) { ini_set($key, $value); } } - private function assertPersistedSessionsCount(int $expectedCount): void + private function assertPersistedSessionsCount(int $expectedCount) : void { $files = glob("{$this->sessionSavePath}/sess_*"); $this->assertCount($expectedCount, $files); From 0865de4ecc0566b2369b848f7e05059d297f84c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:31:26 +0000 Subject: [PATCH 14/20] QA: Incrementation operator in for-loop in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/PhpSessionPersistenceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index fd50c5e..1d2b70b 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -694,7 +694,7 @@ public function testNoMultipleEmptySessionFilesAreCreatedIfNoSessionCookiePresen // initial sessioncookie-less request $request = new ServerRequest(); - for ($i = 0; $i < 3; $i += 1) { + for ($i = 0; $i < 3; ++$i) { $session = $persistence->initializeSessionFromRequest($request); $response = $persistence->persistSession($session, new Response()); @@ -729,7 +729,7 @@ public function testOnlyOneSessionFileIsCreatedIfNoSessionCookiePresentInFirstRe // initial sessioncookie-less request $request = new ServerRequest(); - for ($i = 0; $i < 3; $i += 1) { + for ($i = 0; $i < 3; ++$i) { $session = $persistence->initializeSessionFromRequest($request); $session->set('foo' . $i, 'bar' . $i); $response = $persistence->persistSession($session, new Response()); From cc013ccc7627d67decd1f86552017272876eab7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:31:36 +0000 Subject: [PATCH 15/20] QA: Adds missing trailing comma MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/PhpSessionPersistenceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 1d2b70b..9d0255e 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -667,7 +667,7 @@ public function testStartSessionDoesNotOverrideRequiredSettings() 'use_cookies' => true, // FALSE is required 'use_only_cookies' => false, // TRUE is required 'cache_limiter' => 'nocache', // '' is required - ] + ], ]); $filter = FILTER_VALIDATE_BOOLEAN; From 1245f6b70c68bbf669aea3c634607935413336cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:31:46 +0000 Subject: [PATCH 16/20] QA: Single quotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/PhpSessionPersistenceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 9d0255e..98c1559 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -75,7 +75,7 @@ class PhpSessionPersistenceTest extends TestCase protected function setUp() : void { - $this->sessionSavePath = sys_get_temp_dir() . "/mezzio-session-ext"; + $this->sessionSavePath = sys_get_temp_dir() . '/mezzio-session-ext'; $this->originalSessionSettings = $this->applyCustomSessionOptions([ 'save_path' => $this->sessionSavePath, From b4c78f4a29fb0288d18f9a6c4d118608fcbc0495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:32:02 +0000 Subject: [PATCH 17/20] QA: PHPDocs updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 1 + test/PhpSessionPersistenceTest.php | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index 744607c..ee081ce 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -331,6 +331,7 @@ private function generateCacheHeaders() : array * Return the Last-Modified header line based on main script of execution * modified time. If unable to get a valid timestamp we use this class file * modification time as fallback. + * * @return string|false */ private function getLastModified() diff --git a/test/PhpSessionPersistenceTest.php b/test/PhpSessionPersistenceTest.php index 98c1559..613178b 100644 --- a/test/PhpSessionPersistenceTest.php +++ b/test/PhpSessionPersistenceTest.php @@ -58,19 +58,13 @@ */ class PhpSessionPersistenceTest extends TestCase { - /** - * @var PhpSessionPersistence - */ + /** @var PhpSessionPersistence */ private $persistence; - /** - * @var array - */ + /** @var array */ private $originalSessionSettings; - /** - * @var string - */ + /** @var string */ private $sessionSavePath; protected function setUp() : void @@ -755,6 +749,7 @@ public function testOnlyOneSessionFileIsCreatedIfNoSessionCookiePresentInFirstRe /** * @dataProvider cookieSettingsProvider + * * @param string|int|bool $secureIni * @param string|int|bool $httpOnlyIni */ From dcae77abfd78ca094a2f01a365f96f9ba2f69287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:32:10 +0000 Subject: [PATCH 18/20] QA: Adds missing property in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- test/ConfigProviderTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 8cc0dad..322e93c 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -15,6 +15,9 @@ class ConfigProviderTest extends TestCase { + /** @var ConfigProvider */ + private $provider; + protected function setUp() : void { $this->provider = new ConfigProvider(); From de7e6fdcb5f5ee3acb22d315b6b7a6f4d9727f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:40:18 +0000 Subject: [PATCH 19/20] QA: Adds internal function isNonLocking and update tests to work with PHPUnit 9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- src/PhpSessionPersistence.php | 9 +++++++++ test/PhpSessionPersistenceFactoryTest.php | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/PhpSessionPersistence.php b/src/PhpSessionPersistence.php index ee081ce..3f64455 100644 --- a/src/PhpSessionPersistence.php +++ b/src/PhpSessionPersistence.php @@ -113,6 +113,15 @@ public function __construct(bool $nonLocking = false) $this->cacheExpire = (int) ini_get('session.cache_expire'); } + /** + * @internal + * @return bool the non-locking mode used during initialization + */ + public function isNonLocking() : bool + { + return $this->nonLocking; + } + public function initializeSessionFromRequest(ServerRequestInterface $request) : SessionInterface { $sessionId = FigRequestCookies::get($request, session_name())->getValue() ?? ''; diff --git a/test/PhpSessionPersistenceFactoryTest.php b/test/PhpSessionPersistenceFactoryTest.php index 3bd7e7d..d08f9e0 100644 --- a/test/PhpSessionPersistenceFactoryTest.php +++ b/test/PhpSessionPersistenceFactoryTest.php @@ -26,7 +26,7 @@ public function testFactoryConfigProducesPhpSessionPersistenceInterfaceService() $container->has('config')->willReturn(false); $persistence = $factory($container->reveal()); $this->assertInstanceOf(PhpSessionPersistence::class, $persistence); - $this->assertAttributeSame(false, 'nonLocking', $persistence); + $this->assertFalse($persistence->isNonLocking()); // test php-session-persistence with non-locking config set to false and true foreach ([false, true] as $nonLocking) { @@ -41,7 +41,7 @@ public function testFactoryConfigProducesPhpSessionPersistenceInterfaceService() ], ]); $persistence = $factory($container->reveal()); - $this->assertAttributeSame($nonLocking, 'nonLocking', $persistence); + $this->assertSame($nonLocking, $persistence->isNonLocking()); } } } From e57bbc53906e8ccbbdf7f4f4d82989beadbd6aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Thu, 19 Mar 2020 19:47:28 +0000 Subject: [PATCH 20/20] QA: Updates Travis CI configuration - adds PHP 7.4 builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Bundyra --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index e810782..1fd8790 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,12 @@ matrix: - php: 7.3 env: - DEPS=latest + - php: 7.4 + env: + - DEPS=lowest + - php: 7.4 + env: + - DEPS=latest before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi