From a2622e3e62a9d959e3fdab287f13df4c0866cf5a Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 29 Apr 2024 16:31:15 +0200 Subject: [PATCH] Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder` --- .../Storage/NativeSessionStorageTest.php | 63 ++++++++++++------- .../Storage/PhpBridgeSessionStorageTest.php | 10 ++- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/Tests/Session/Storage/NativeSessionStorageTest.php b/Tests/Session/Storage/NativeSessionStorageTest.php index adf074e36..c67b1391d 100644 --- a/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/Tests/Session/Storage/NativeSessionStorageTest.php @@ -34,10 +34,14 @@ class NativeSessionStorageTest extends TestCase { private $savePath; + private $initialSessionSaveHandler; + private $initialSessionSavePath; + protected function setUp(): void { - $this->iniSet('session.save_handler', 'files'); - $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); + $this->initialSessionSaveHandler = ini_set('session.save_handler', 'files'); + $this->initialSessionSavePath = ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); + if (!is_dir($this->savePath)) { mkdir($this->savePath); } @@ -52,6 +56,8 @@ protected function tearDown(): void } $this->savePath = null; + ini_set('session.save_handler', $this->initialSessionSaveHandler); + ini_set('session.save_path', $this->initialSessionSavePath); } protected function getStorage(array $options = []): NativeSessionStorage @@ -154,18 +160,26 @@ public function testRegenerationFailureDoesNotFlagStorageAsStarted() public function testDefaultSessionCacheLimiter() { - $this->iniSet('session.cache_limiter', 'nocache'); + $initialLimiter = ini_set('session.cache_limiter', 'nocache'); - new NativeSessionStorage(); - $this->assertEquals('', \ini_get('session.cache_limiter')); + try { + new NativeSessionStorage(); + $this->assertEquals('', \ini_get('session.cache_limiter')); + } finally { + ini_set('session.cache_limiter', $initialLimiter); + } } public function testExplicitSessionCacheLimiter() { - $this->iniSet('session.cache_limiter', 'nocache'); + $initialLimiter = ini_set('session.cache_limiter', 'nocache'); - new NativeSessionStorage(['cache_limiter' => 'public']); - $this->assertEquals('public', \ini_get('session.cache_limiter')); + try { + new NativeSessionStorage(['cache_limiter' => 'public']); + $this->assertEquals('public', \ini_get('session.cache_limiter')); + } finally { + ini_set('session.cache_limiter', $initialLimiter); + } } public function testCookieOptions() @@ -208,20 +222,25 @@ public function testSessionOptions() public function testSetSaveHandler() { - $this->iniSet('session.save_handler', 'files'); - $storage = $this->getStorage(); - $storage->setSaveHandler(); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); - $storage->setSaveHandler(null); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); - $storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler())); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); - $storage->setSaveHandler(new NativeFileSessionHandler()); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); - $storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler())); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); - $storage->setSaveHandler(new NullSessionHandler()); - $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $initialSaveHandler = ini_set('session.save_handler', 'files'); + + try { + $storage = $this->getStorage(); + $storage->setSaveHandler(); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $storage->setSaveHandler(null); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler())); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $storage->setSaveHandler(new NativeFileSessionHandler()); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler())); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + $storage->setSaveHandler(new NullSessionHandler()); + $this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler()); + } finally { + ini_set('session.save_handler', $initialSaveHandler); + } } public function testStarted() diff --git a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index e2fb93ebc..80d656518 100644 --- a/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -30,10 +30,14 @@ class PhpBridgeSessionStorageTest extends TestCase { private $savePath; + private $initialSessionSaveHandler; + private $initialSessionSavePath; + protected function setUp(): void { - $this->iniSet('session.save_handler', 'files'); - $this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); + $this->initialSessionSaveHandler = ini_set('session.save_handler', 'files'); + $this->initialSessionSavePath = ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest'); + if (!is_dir($this->savePath)) { mkdir($this->savePath); } @@ -48,6 +52,8 @@ protected function tearDown(): void } $this->savePath = null; + ini_set('session.save_handler', $this->initialSessionSaveHandler); + ini_set('session.save_path', $this->initialSessionSavePath); } protected function getStorage(): PhpBridgeSessionStorage