Skip to content

Commit

Permalink
chore: update tests for phpunit 10 and 11
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud committed Dec 7, 2024
1 parent d02d0ec commit 6679c89
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
12 changes: 9 additions & 3 deletions tests/DatabaseEncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion tests/DefaultEncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions tests/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 9 additions & 3 deletions tests/FileEncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions tests/RedisEncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 6679c89

Please sign in to comment.