From 6679c895f01b4078f87e39e5577a2ca4c381d5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rancoud?= Date: Sun, 8 Dec 2024 00:31:27 +0100 Subject: [PATCH] chore: update tests for phpunit 10 and 11 --- tests/DatabaseEncryptionTest.php | 12 +++++++++--- tests/DefaultEncryptionTest.php | 4 +++- tests/EncryptionTest.php | 16 ++++++++++++---- tests/FileEncryptionTest.php | 12 +++++++++--- tests/RedisEncryptionTest.php | 12 +++++++++--- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/tests/DatabaseEncryptionTest.php b/tests/DatabaseEncryptionTest.php index f148dae..3807abe 100644 --- a/tests/DatabaseEncryptionTest.php +++ b/tests/DatabaseEncryptionTest.php @@ -105,7 +105,9 @@ public function testWrite(): void static::assertNotEmpty($row); static::assertNotSame($data, $row['content']); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInDatabaseDecrypted = $encryptionTrait->decrypt($row['content']); static::assertSame($data, $dataInDatabaseDecrypted); @@ -339,7 +341,9 @@ public function testUpdateTimestamp(): void static::assertNotEmpty($row1); static::assertNotSame($data, $row1['content']); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInDatabaseDecrypted = $encryptionTrait->decrypt($row1['content']); static::assertSame($data, $dataInDatabaseDecrypted); @@ -352,7 +356,9 @@ public function testUpdateTimestamp(): void static::assertNotEmpty($row2); static::assertNotSame($data, $row2['content']); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInDatabaseDecrypted = $encryptionTrait->decrypt($row2['content']); static::assertSame($data, $dataInDatabaseDecrypted); diff --git a/tests/DefaultEncryptionTest.php b/tests/DefaultEncryptionTest.php index a238421..d4f33dd 100644 --- a/tests/DefaultEncryptionTest.php +++ b/tests/DefaultEncryptionTest.php @@ -58,7 +58,9 @@ public function testReadAndWrite(): void $data = $this->foundSessionFile(); static::assertNotFalse($data); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataDecrypted = $encryptionTrait->decrypt($data); static::assertSame('a|s:1:"b";', $dataDecrypted); diff --git a/tests/EncryptionTest.php b/tests/EncryptionTest.php index eb2bcf6..0e19120 100644 --- a/tests/EncryptionTest.php +++ b/tests/EncryptionTest.php @@ -14,7 +14,9 @@ class EncryptionTest extends TestCase { public function testDefaultEncryption(): void { - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $dataToEncrypt = 'this is something to encrypt'; @@ -29,7 +31,9 @@ public function testAllEncryptionMethods(): void { $failedMethods = []; - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $dataToEncrypt = 'this is something to encrypt'; @@ -58,7 +62,9 @@ public function testExceptionMethod(): void $this->expectException(SessionException::class); $this->expectExceptionMessage('Unknown method: method'); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setMethod('method'); } @@ -154,7 +160,9 @@ public function testExceptionEmptyKey(): void $this->expectException(SessionException::class); $this->expectExceptionMessage('Key has to be a non-empty string'); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $dataToEncrypt = 'this is something to encrypt'; $encryptionTrait->encrypt($dataToEncrypt); } diff --git a/tests/FileEncryptionTest.php b/tests/FileEncryptionTest.php index ff60e2d..c68dc5b 100644 --- a/tests/FileEncryptionTest.php +++ b/tests/FileEncryptionTest.php @@ -99,7 +99,9 @@ public function testWrite(): void $dataInFile = \file_get_contents($this->getPath() . \DIRECTORY_SEPARATOR . 'sess_' . $sessionId); static::assertNotSame($data, $dataInFile); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInFileDecrypted = $encryptionTrait->decrypt($dataInFile); static::assertSame($data, $dataInFileDecrypted); @@ -224,7 +226,9 @@ public function testUpdateTimestamp(): void $oldFileModifiedTime = \filemtime($this->getPath() . \DIRECTORY_SEPARATOR . 'sess_' . $sessionId); static::assertNotSame($data, $dataInFile); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInFileDecrypted = $encryptionTrait->decrypt($dataInFile); static::assertSame($data, $dataInFileDecrypted); @@ -238,7 +242,9 @@ public function testUpdateTimestamp(): void $dataInFile2 = \file_get_contents($this->getPath() . \DIRECTORY_SEPARATOR . 'sess_' . $sessionId); static::assertNotSame($data, $dataInFile2); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInFileDecrypted = $encryptionTrait->decrypt($dataInFile2); static::assertSame($data, $dataInFileDecrypted); diff --git a/tests/RedisEncryptionTest.php b/tests/RedisEncryptionTest.php index f24ee25..c61780b 100644 --- a/tests/RedisEncryptionTest.php +++ b/tests/RedisEncryptionTest.php @@ -76,7 +76,9 @@ public function testWrite(): void $dataInRedis = static::$redis->get($sessionId); static::assertNotSame($data, $dataInRedis); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInRedisDecrypted = $encryptionTrait->decrypt($dataInRedis); static::assertSame($data, $dataInRedisDecrypted); @@ -230,7 +232,9 @@ public function testUpdateTimestamp(): void static::assertNotSame($data, $dataInRedis); $ttl1 = static::$redis->ttl($sessionId); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInRedisDecrypted = $encryptionTrait->decrypt($dataInRedis); static::assertSame($data, $dataInRedisDecrypted); @@ -246,7 +250,9 @@ public function testUpdateTimestamp(): void static::assertNotSame($data, $dataInRedis2); $ttl3 = static::$redis->ttl($sessionId); - $encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption'); + $encryptionTrait = new class { + use \Rancoud\Session\Encryption; + }; $encryptionTrait->setKey('randomKey'); $dataInRedisDecrypted = $encryptionTrait->decrypt($dataInRedis2); static::assertSame($data, $dataInRedisDecrypted);