From b84d54815331f338cfc0b013400cfff1a8eb32fb Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Tue, 22 Jul 2025 19:42:55 +0200 Subject: [PATCH 1/7] chore: dev tools and dependencies updated --- .github/workflows/tests.yml | 5 +- composer.json | 10 ++-- composer.mysql.json | 10 ++-- composer.pgsql.json | 10 ++-- phpunit.dist.xml | 1 + src/Linna/Mvc/View.php | 1 - .../Authentication/AuthenticationTest.php | 7 ++- .../Authentication/PasswordGeneratorTest.php | 16 +++--- tests/Linna/Authentication/PasswordTest.php | 6 +-- .../Linna/Authorization/RoleExtendedTest.php | 19 +++---- .../Linna/Authorization/UserExtendedTest.php | 19 +++---- tests/Linna/Cache/CacheTrait.php | 25 ++++------ tests/Linna/Cache/MemcachedCacheTest.php | 5 +- tests/Linna/Cache/RedisCacheTest.php | 5 +- tests/Linna/Container/ContainerTest.php | 49 +++++++------------ tests/Linna/Mvc/ModelViewControllerTest.php | 16 +++--- tests/Linna/Router/RouterTest.php | 23 +++++---- tests/Linna/Session/SessionTest.php | 47 ++++++++++-------- tests/Linna/Storage/ExtendedPDOTest.php | 7 ++- tests/Linna/Storage/MongoDBConnectorTest.php | 2 +- tests/Linna/Storage/MysqliConnectorTest.php | 7 +-- tests/Linna/Storage/PdoConnectorTest.php | 4 +- tests/Linna/Storage/StorageFactoryTest.php | 4 +- 23 files changed, 132 insertions(+), 166 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe2663b..86a6e8b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,8 +44,7 @@ jobs: strategy: fail-fast: true matrix: - #php: [8.0, 8.1] - php: [8.1, 8.2, 8.3] + php: [8.3, 8.4] mapper: [mysql, pgsql] name: Unit tests PHP ${{ matrix.php }} and ${{ matrix.mapper }} @@ -91,7 +90,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.1, 8.2, 8.3] + php: [8.3, 8.4] name: Code analysis with PHPStan PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index 3b060b9..51d1ac1 100644 --- a/composer.json +++ b/composer.json @@ -23,13 +23,13 @@ "psr/simple-cache": "^3.0" }, "require-dev": { - "infection/infection": ">=0.26", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^10", + "infection/infection": "^0.30", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^12", "linna/auth-mapper-mysql": "dev-master", "linna/db-dumps": "dev-master", - "mongodb/mongodb": "^1.5", - "brianium/paratest": "^7.0" + "mongodb/mongodb": "^2.1", + "brianium/paratest": "^7" }, "autoload": { "psr-4": { diff --git a/composer.mysql.json b/composer.mysql.json index 3b060b9..51d1ac1 100644 --- a/composer.mysql.json +++ b/composer.mysql.json @@ -23,13 +23,13 @@ "psr/simple-cache": "^3.0" }, "require-dev": { - "infection/infection": ">=0.26", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^10", + "infection/infection": "^0.30", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^12", "linna/auth-mapper-mysql": "dev-master", "linna/db-dumps": "dev-master", - "mongodb/mongodb": "^1.5", - "brianium/paratest": "^7.0" + "mongodb/mongodb": "^2.1", + "brianium/paratest": "^7" }, "autoload": { "psr-4": { diff --git a/composer.pgsql.json b/composer.pgsql.json index 0cb7046..8f3dd8e 100644 --- a/composer.pgsql.json +++ b/composer.pgsql.json @@ -23,13 +23,13 @@ "psr/simple-cache": "^3.0" }, "require-dev": { - "infection/infection": ">=0.26", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^10", + "infection/infection": "^0.30", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^12", "linna/auth-mapper-pgsql": "dev-master", "linna/db-dumps": "dev-master", - "mongodb/mongodb": "^1.5", - "brianium/paratest": "^7.0" + "mongodb/mongodb": "^2.1", + "brianium/paratest": "^7" }, "autoload": { "psr-4": { diff --git a/phpunit.dist.xml b/phpunit.dist.xml index dbae90e..3004587 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -13,6 +13,7 @@ + diff --git a/src/Linna/Mvc/View.php b/src/Linna/Mvc/View.php index 523bca3..15e2ec8 100644 --- a/src/Linna/Mvc/View.php +++ b/src/Linna/Mvc/View.php @@ -13,7 +13,6 @@ namespace Linna\Mvc; use Linna\Mvc\TemplateInterface; - use SplObserver; use SplSubject; diff --git a/tests/Linna/Authentication/AuthenticationTest.php b/tests/Linna/Authentication/AuthenticationTest.php index 4e3889e..ced3841 100644 --- a/tests/Linna/Authentication/AuthenticationTest.php +++ b/tests/Linna/Authentication/AuthenticationTest.php @@ -13,6 +13,7 @@ namespace Linna\Authentication; use Linna\Session\Session; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -100,12 +101,11 @@ public static function tamperingProvider() /** * Test login. * - * @dataProvider tamperingProvider - * * @runInSeparateProcess * * @return void */ + #[DataProvider('tamperingProvider')] public function testLoginTampering(int $case): void { self::$session->start(); @@ -290,8 +290,6 @@ public static function loginTimeProvider(): array /** * Test login refresh. * - * @dataProvider loginTimeProvider - * * @runInSeparateProcess * * @param int $time @@ -299,6 +297,7 @@ public static function loginTimeProvider(): array * * @return void */ + #[DataProvider('loginTimeProvider')] public function testLoginRefreshTime(int $time, bool $loginPass): void { self::$session->start(); diff --git a/tests/Linna/Authentication/PasswordGeneratorTest.php b/tests/Linna/Authentication/PasswordGeneratorTest.php index 650b2d7..358742b 100644 --- a/tests/Linna/Authentication/PasswordGeneratorTest.php +++ b/tests/Linna/Authentication/PasswordGeneratorTest.php @@ -13,6 +13,7 @@ namespace Linna\Authentication; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionObject; @@ -64,12 +65,11 @@ public static function stringLengthProvider(): array /** * Test get from random. * - * @dataProvider stringLengthProvider - * * @param int $strLen * * @return void */ + #[DataProvider('stringLengthProvider')] public function testGetFromRandom(int $strLen): void { $password = self::$passwordGenerator->getFromRandom($strLen); @@ -86,12 +86,11 @@ public function testGetFromRandom(int $strLen): void /** * Test get from random. * - * @dataProvider stringLengthProvider - * * @param int $strLen * * @return void */ + #[DataProvider('stringLengthProvider')] public function testCheckRandomTopology(int $strLen): void { $topology = ''; @@ -147,13 +146,12 @@ public static function topologyAndPasswordProvider(): array /** * Test get topology. * - * @dataProvider topologyAndPasswordProvider - * * @param string $password * @param string $topology * * @return void */ + #[DataProvider('topologyAndPasswordProvider')] public function testGetTopology(string $password, string $topology): void { $this->assertEquals($topology, self::$passwordGenerator->getTopology($password)); @@ -192,12 +190,11 @@ public static function topologyProvider(): array /** * Test get topology. * - * @dataProvider topologyProvider - * * @param string $topology * * @return void */ + #[DataProvider('topologyProvider')] public function testGetFromTopology(string $topology): void { $password = self::$passwordGenerator->getFromTopology(\strtoupper($topology)); @@ -225,12 +222,11 @@ public static function badTopologyProvider(): array /** * Test get topology. * - * @dataProvider badTopologyProvider - * * @param string $topology * * @return void */ + #[DataProvider('badTopologyProvider')] public function testGetFromTopologyException(string $topology): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Linna/Authentication/PasswordTest.php b/tests/Linna/Authentication/PasswordTest.php index c8a4654..cdddebc 100644 --- a/tests/Linna/Authentication/PasswordTest.php +++ b/tests/Linna/Authentication/PasswordTest.php @@ -12,6 +12,7 @@ namespace Linna\Authentication; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -39,7 +40,7 @@ public static function setUpBeforeClass(): void */ public static function tearDownAfterClass(): void { - self::$password = null; + //self::$password = null; } /** @@ -101,10 +102,9 @@ public static function optionsProvider(): array /** * Test get hash info. * - * @dataProvider optionsProvider - * * @return void */ + #[DataProvider('optionsProvider')] public function testGetHashInfo(int $opsLimit, int $memLimit, int $memExp, int $timeExp, int $threads): void { $password = new Password($opsLimit, $memLimit); diff --git a/tests/Linna/Authorization/RoleExtendedTest.php b/tests/Linna/Authorization/RoleExtendedTest.php index 2a88fe2..2c2d838 100644 --- a/tests/Linna/Authorization/RoleExtendedTest.php +++ b/tests/Linna/Authorization/RoleExtendedTest.php @@ -15,6 +15,7 @@ use Linna\Authentication\Password; use Linna\Storage\ExtendedPDO; use Linna\Storage\StorageFactory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Linna\TestHelper\Pdo\PdoOptionsFactory; @@ -128,14 +129,13 @@ public static function userRoleProvider(): array /** * Test is user in role. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testIsUserInRole(int $roleId, int $userId, bool $result): void { /** @var RoleExtended Role Class. */ @@ -149,14 +149,13 @@ public function testIsUserInRole(int $roleId, int $userId, bool $result): void /** * Test is user in role by id. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testIsUserInRoleById(int $roleId, int $userId, bool $result): void { /** @var RoleExtended Role Class. */ @@ -168,14 +167,13 @@ public function testIsUserInRoleById(int $roleId, int $userId, bool $result): vo /** * Test is user in role by name. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testIsUserInRoleByName(int $roleId, int $userId, bool $result): void { /** @var RoleExtended Role Class. */ @@ -219,14 +217,13 @@ public static function rolePermissionProvider(): array /** * Test role can. * - * @dataProvider rolePermissionProvider - * * @param int $roleId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('rolePermissionProvider')] public function testRoleCan(int $roleId, int $permissionId, bool $result): void { /** @var RoleExtended Role Class. */ @@ -240,14 +237,13 @@ public function testRoleCan(int $roleId, int $permissionId, bool $result): void /** * Test role can by id. * - * @dataProvider rolePermissionProvider - * * @param int $roleId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('rolePermissionProvider')] public function testRoleCanById(int $roleId, int $permissionId, bool $result): void { /** @var RoleExtended Role Class. */ @@ -259,14 +255,13 @@ public function testRoleCanById(int $roleId, int $permissionId, bool $result): v /** * Test role can by name. * - * @dataProvider rolePermissionProvider - * * @param int $roleId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('rolePermissionProvider')] public function testRoleCanByName(int $roleId, int $permissionId, bool $result): void { /** @var RoleExtended Role Class. */ diff --git a/tests/Linna/Authorization/UserExtendedTest.php b/tests/Linna/Authorization/UserExtendedTest.php index ef3cedc..404f8ed 100644 --- a/tests/Linna/Authorization/UserExtendedTest.php +++ b/tests/Linna/Authorization/UserExtendedTest.php @@ -16,6 +16,7 @@ use Linna\Authentication\UserMapper; use Linna\Storage\ExtendedPDO; use Linna\Storage\StorageFactory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Linna\TestHelper\Pdo\PdoOptionsFactory; @@ -135,14 +136,13 @@ public static function userPermissionProvider(): array /** * Test user can. * - * @dataProvider userPermissionProvider - * * @param int $userId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('userPermissionProvider')] public function testUserCan(int $userId, int $permissionId, bool $result): void { /** @var UserExtended UserExtended Class. */ @@ -156,14 +156,13 @@ public function testUserCan(int $userId, int $permissionId, bool $result): void /** * Test user can by id. * - * @dataProvider userPermissionProvider - * * @param int $userId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('userPermissionProvider')] public function testUserCanById(int $userId, int $permissionId, bool $result): void { /** @var UserExtended UserExtended Class. */ @@ -175,14 +174,13 @@ public function testUserCanById(int $userId, int $permissionId, bool $result): v /** * Test user can by name. * - * @dataProvider userPermissionProvider - * * @param int $userId * @param int $permissionId * @param bool $result * * @return void */ + #[DataProvider('userPermissionProvider')] public function testUserCanByName(int $userId, int $permissionId, bool $result): void { /** @var UserExtended UserExtended Class. */ @@ -228,14 +226,13 @@ public static function userRoleProvider(): array /** * Test user has role. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testUserHasRole(int $roleId, int $userId, bool $result): void { /** @var UserExtended UserExtended Class. */ @@ -248,14 +245,13 @@ public function testUserHasRole(int $roleId, int $userId, bool $result): void /** * Test user has role by id. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testUserHasRoleById(int $roleId, int $userId, bool $result): void { /** @var UserExtended UserExtended Class. */ @@ -267,14 +263,13 @@ public function testUserHasRoleById(int $roleId, int $userId, bool $result): voi /** * Test user has role by name. * - * @dataProvider userRoleProvider - * * @param int $roleId * @param int $userId * @param bool $result * * @return void */ + #[DataProvider('userRoleProvider')] public function testUserHasRoleByName(int $roleId, int $userId, bool $result): void { /** @var UserExtended UserExtended Class. */ diff --git a/tests/Linna/Cache/CacheTrait.php b/tests/Linna/Cache/CacheTrait.php index 0976f2e..44acf62 100644 --- a/tests/Linna/Cache/CacheTrait.php +++ b/tests/Linna/Cache/CacheTrait.php @@ -12,6 +12,7 @@ namespace Linna\Cache; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\SimpleCache\CacheInterface; use TypeError; use DateInterval; @@ -43,12 +44,11 @@ public static function invalidKeyProvider(): array /** * Test set with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testSetWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -109,12 +109,11 @@ public function testSetWithNegativeTtl(): void /** * Test get with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testGetWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -143,13 +142,12 @@ public static function dataTypeProvider(): array /** * Test get for data type * - * @dataProvider dataTypeProvider - * * @param string $key * @param mixed $value * * @return void */ + #[DataProvider('dataTypeProvider')] public function testGetForDataType(string $key, mixed $value): void { $this->assertTrue(self::$cache->set($key, $value)); @@ -183,12 +181,11 @@ public function testGetWithDefault(): void /** * Test delete with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testDeleteWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -252,12 +249,11 @@ public function testClear(): void /** * Test get multiple elements with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testGetMultipleWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -306,12 +302,11 @@ public function testGetMultiple(): void /** * Test set multiple elements with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testSetMultipleWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -395,12 +390,11 @@ public function testSetMultipleTtl(): void /** * Teset delete multiple elements with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testDeleteMultipleWithInvalidKey($key): void { $this->expectException(TypeError::class); @@ -451,12 +445,11 @@ public function testDeleteMultiple(): void /** * Test has with invalid key. * - * @dataProvider invalidKeyProvider - * * @param mixed $key * * @return void */ + #[DataProvider('invalidKeyProvider')] public function testHasWithInvalidKey($key): void { $this->expectException(TypeError::class); diff --git a/tests/Linna/Cache/MemcachedCacheTest.php b/tests/Linna/Cache/MemcachedCacheTest.php index 69da664..2826e09 100644 --- a/tests/Linna/Cache/MemcachedCacheTest.php +++ b/tests/Linna/Cache/MemcachedCacheTest.php @@ -13,6 +13,7 @@ namespace Linna\Cache; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -63,10 +64,9 @@ public static function invalidOptionsProvider(): array /** * Test create instance without options. * - * @dataProvider invalidOptionsProvider - * * @return void */ + #[DataProvider('invalidOptionsProvider')] public function testCreateInstanceWithoutOptions($options): void { $this->expectException(InvalidArgumentException::class); @@ -96,6 +96,7 @@ public static function optionsProvider(): array * * @return void */ + #[DataProvider('optionsProvider')] public function testCreateInstance($options): void { $cache = new MemcachedCache($options); diff --git a/tests/Linna/Cache/RedisCacheTest.php b/tests/Linna/Cache/RedisCacheTest.php index a9ab56d..9b3bc9f 100644 --- a/tests/Linna/Cache/RedisCacheTest.php +++ b/tests/Linna/Cache/RedisCacheTest.php @@ -13,6 +13,7 @@ namespace Linna\Cache; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -86,10 +87,9 @@ public static function invalidOptionsProvider(): array /** * Test create instance without options. * - * @dataProvider invalidOptionsProvider - * * @return void */ + #[DataProvider('invalidOptionsProvider')] public function testCreateInstanceWithoutOptions($options): void { $this->expectException(InvalidArgumentException::class); @@ -105,6 +105,7 @@ public function testCreateInstanceWithoutOptions($options): void * * @return void */ + #[DataProvider('optionsProvider')] public function testCreateInstance($options): void { $cache = new RedisCache($options); diff --git a/tests/Linna/Container/ContainerTest.php b/tests/Linna/Container/ContainerTest.php index 97fff40..8d1be17 100644 --- a/tests/Linna/Container/ContainerTest.php +++ b/tests/Linna/Container/ContainerTest.php @@ -30,6 +30,7 @@ use Linna\TestHelper\Container\ClassResInterface; use Linna\TestHelper\Container\ClassResObject; use Linna\TestHelper\Container\ClassResRules; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -62,10 +63,10 @@ public static function valuesProvider(): array * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + + #[DataProvider('valuesProvider')] public function testSetAndGetWithMethodCall(string $key, $value): void { $container = new Container(); @@ -81,10 +82,9 @@ public function testSetAndGetWithMethodCall(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testSetAndGetWithArraySyntax(string $key, $value): void { $container = new Container(); @@ -100,10 +100,9 @@ public function testSetAndGetWithArraySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testSetAndGetWithPropertySyntax(string $key, $value): void { $container = new Container(); @@ -119,10 +118,9 @@ public function testSetAndGetWithPropertySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testHasWithMethodCall(string $key, $value): void { $container = new Container(); @@ -138,10 +136,9 @@ public function testHasWithMethodCall(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testHasWithArraySyntax(string $key, $value): void { $container = new Container(); @@ -157,10 +154,9 @@ public function testHasWithArraySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testHasWithWithPropertySyntax(string $key, $value): void { $container = new Container(); @@ -176,11 +172,10 @@ public function testHasWithWithPropertySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ - public function testDeleteUnexisting(string $key): void + #[DataProvider('valuesProvider')] + public function testDeleteUnexisting(string $key, $value): void { $this->assertNull((new Container())->delete($key)); } @@ -191,10 +186,9 @@ public function testDeleteUnexisting(string $key): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testDeleteWithMethodCall(string $key, $value): void { $container = new Container(); @@ -212,10 +206,9 @@ public function testDeleteWithMethodCall(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testDeleteWithArraySyntax(string $key, $value): void { $container = new Container(); @@ -235,10 +228,9 @@ public function testDeleteWithArraySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testDeleteWithPropertySyntax(string $key, $value): void { $container = new Container(); @@ -258,10 +250,9 @@ public function testDeleteWithPropertySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testGetUnexistingWithMethodCall(string $key, $value): void { $this->expectException(NotFoundException::class); @@ -277,10 +268,9 @@ public function testGetUnexistingWithMethodCall(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testGetUnexistingWithArraySyntax(string $key, $value): void { $this->expectException(NotFoundException::class); @@ -296,10 +286,9 @@ public function testGetUnexistingWithArraySyntax(string $key, $value): void * @param string $key * @param mixed $value * - * @dataProvider valuesProvider - * * @return void */ + #[DataProvider('valuesProvider')] public function testGetUnexistingWithPropertySyntax(string $key, $value): void { $this->expectException(NotFoundException::class); @@ -332,12 +321,11 @@ public static function classProvider(): array /** * Test class resolving. * - * @dataProvider classProvider - * * @param string $class * * @return void */ + #[DataProvider('classProvider')] public function testResolve(string $class): void { $this->assertInstanceOf($class, (new Container())->resolve($class)); @@ -401,13 +389,12 @@ public static function implementationProvider(): array /** * Test resolving class with interface as argument. * - * @dataProvider implementationProvider - * * @param array $rule * @param string $result * * @return void */ + #[DataProvider('implementationProvider')] public function testResolveWithInterface(array $rule, string $result): void { $container = new Container($rule); diff --git a/tests/Linna/Mvc/ModelViewControllerTest.php b/tests/Linna/Mvc/ModelViewControllerTest.php index 8f2958b..ebe6caa 100644 --- a/tests/Linna/Mvc/ModelViewControllerTest.php +++ b/tests/Linna/Mvc/ModelViewControllerTest.php @@ -38,6 +38,7 @@ use Linna\TestHelper\Mvc\MultipleModel; use Linna\TestHelper\Mvc\MultipleView; use Linna\TestHelper\Mvc\JsonTemplate; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TypeError; @@ -201,10 +202,9 @@ public static function ModelViewControllerWrongArgProvider(): array * @param Controller $controller * @param Route $route * - * @dataProvider ModelViewControllerWrongArgProvider - * * @return void */ + #[DataProvider('ModelViewControllerWrongArgProvider')] public function testNewModelViewControllerWithWrongArguments($model, $view, $controller, $route): void { $this->expectException(TypeError::class); @@ -234,10 +234,9 @@ public static function calculatorMultiProvider(): array * @param array $parameter * @param int $result * - * @dataProvider calculatorMultiProvider - * * @return void */ + #[DataProvider('calculatorMultiProvider')] public function testRunWithMultiActionMVC(string $route, array $parameter, string $result): void { $_POST['numbers'] = $parameter; @@ -272,10 +271,9 @@ public static function calculatorSingleProvider(): array * @param array $parameter * @param int $result * - * @dataProvider calculatorSingleProvider - * * @return void */ + #[DataProvider('calculatorSingleProvider')] public function testRunWithSingleActionMVC(string $route, array $parameter, string $result): void { $_POST['numbers'] = $parameter; @@ -320,10 +318,9 @@ public static function someParamProvider(): array * @param string $route * @param string $result * - * @dataProvider someParamProvider - * * @return void */ + #[DataProvider('someParamProvider')] public function testRunModelViewControllerWithSomeParam(string $route, string $result): void { self::$router->validate($route, 'GET'); @@ -392,13 +389,12 @@ public static function beforeAfterProvider(): array /** * Test run front controller before after. * - * @dataProvider beforeAfterProvider - * * @param int $input * @param int $result * * @return void */ + #[DataProvider('beforeAfterProvider')] public function testRunModelViewControllerBeforeAfter(int $input, int $result): void { self::$router->validate('/before/after/'.$input, 'GET'); diff --git a/tests/Linna/Router/RouterTest.php b/tests/Linna/Router/RouterTest.php index 4123e25..c0b9ff5 100644 --- a/tests/Linna/Router/RouterTest.php +++ b/tests/Linna/Router/RouterTest.php @@ -12,6 +12,7 @@ namespace Linna\Router; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TypeError; @@ -120,6 +121,7 @@ public static function WrongArgumentsForValidateRouteProvider(): array * * @return void */ + #[DataProvider('WrongArgumentsForValidateRouteProvider')] public function testValidateRouteWithWrongArguments($url, $method): void { $this->expectException(TypeError::class); @@ -165,8 +167,6 @@ public static function routeProvider(): array /** * Test routes. * - * @dataProvider routeProvider - * * @param string $url * @param string $method * @param array $returneRoute @@ -174,6 +174,7 @@ public static function routeProvider(): array * * @return void */ + #[DataProvider('routeProvider')] public function testRoutes(string $url, string $method, array $returneRoute, bool $validate): void { $this->assertEquals($validate, self::$router->validate($url, $method)); @@ -192,8 +193,6 @@ public function testRoutes(string $url, string $method, array $returneRoute, boo /** * Test routes with other base path. * - * @dataProvider routeProvider - * * @param string $url * @param string $method * @param array $returneRoute @@ -201,6 +200,7 @@ public function testRoutes(string $url, string $method, array $returneRoute, boo * * @return void */ + #[DataProvider('routeProvider')] public function testRoutesWithOtherBasePath(string $url, string $method, array $returneRoute, bool $validate): void { $router = new Router( @@ -241,13 +241,12 @@ public static function mapMethodRouteProvider(): array /** * Test map route into router with map method. * - * @dataProvider mapMethodRouteProvider - * * @param string $method * @param string $path * * @return void */ + #[DataProvider('mapMethodRouteProvider')] public function testMapRouteWithMapMethod(string $method, string $path): void { self::$router->map(new Route(method: $method, path: $path)); @@ -429,14 +428,14 @@ public static function restRouteProvider(): array /** * Test rest routing. * - * @dataProvider restRouteProvider - * * @param string $uri * @param string $method * @param string $action * * @return void */ + + #[DataProvider('restRouteProvider')] public function testRESTRouting(string $uri, string $method, string $action): void { $restRoutes = (new RouteCollection([ @@ -549,13 +548,13 @@ public static function routeWithParamProvider(): array /** * Test allowed chars in route param. * - * @dataProvider routeWithParamProvider - * * @param string $uri * @param string $result * * @return void */ + + #[DataProvider('routeWithParamProvider')] public function testAllowedCharsInRouteParam(string $uri, string $result): void { self::$router->validate($uri, 'GET'); @@ -584,14 +583,14 @@ public static function routeWithQueryStringProvider(): array /** * Test query strin on rewrite mode on. * - * @dataProvider routeWithQueryStringProvider - * * @param string $uri * @param string $key * @param string $value * * @return void */ + + #[DataProvider('routeWithQueryStringProvider')] public function testParseQueryStringRewriteModeTrue(string $uri, string $key, string $value): void { $routes = (new RouteCollection([ diff --git a/tests/Linna/Session/SessionTest.php b/tests/Linna/Session/SessionTest.php index 9d17569..847228e 100644 --- a/tests/Linna/Session/SessionTest.php +++ b/tests/Linna/Session/SessionTest.php @@ -12,6 +12,7 @@ namespace Linna\Session; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -51,11 +52,11 @@ public function testSessionStart(): void { $session = self::$session; - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); //check for session parameters $this->assertSame('linna_session', \session_name()); @@ -92,12 +93,13 @@ public function testSessionStart(): void public function testSessionStartWithAlreadyStartedSession(): void { $session = self::$session; + $session->destroy(); - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->cookieCheck($this->getCookieValues(), $session); @@ -121,11 +123,12 @@ public function testSessionCommit(): void { $session = self::$session; - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); + $this->assertSame($session->getSessionId(), \session_id()); $this->cookieCheck($this->getCookieValues(), $session); @@ -133,11 +136,12 @@ public function testSessionCommit(): void $session->commit(); - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); + $this->assertSame($session->getSessionId(), \session_id()); $this->assertSame('fooData', $session['fooData']); $this->cookieCheck($this->getCookieValues(), $session); @@ -157,11 +161,12 @@ public function testSessionCommit(): void public function testSessionDestroy(): void { $session = self::$session; - $this->assertSame(1, $session->getStatus()); + + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->cookieCheck($this->getCookieValues(), $session); @@ -200,11 +205,11 @@ public function testSessionRegenerate(): void { $session = self::$session; - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->cookieCheck($this->getCookieValues(), $session); @@ -214,7 +219,7 @@ public function testSessionRegenerate(): void $sessionIdBefore = \session_id(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->assertSame($sessionIdBefore, $session->getSessionId()); $this->assertSame('fooData', $session['fooData']); @@ -224,7 +229,7 @@ public function testSessionRegenerate(): void $cookieValueAfter = $this->getCookieValue($this->getCookieValues()); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->assertSame(\session_id(), $session->getSessionId()); $this->assertNotEquals(\session_id(), $sessionIdBefore); $this->assertNotEquals($cookieValueBefore, $cookieValueAfter); @@ -253,8 +258,6 @@ public static function sessionTimeProvider(): array /** * Test session expired. * - * @dataProvider sessionTimeProvider - * * @requires extension xdebug * * @runInSeparateProcess @@ -264,15 +267,17 @@ public static function sessionTimeProvider(): array * * @return void */ + + #[DataProvider('sessionTimeProvider')] public function testSessionExpired(int $time, bool $equals): void { $session = self::$session; - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $this->cookieCheck($this->getCookieValues(), $session); @@ -284,11 +289,11 @@ public function testSessionExpired(int $time, bool $equals): void $session->commit(); - $this->assertSame(1, $session->getStatus()); + $this->assertSame(PHP_SESSION_NONE, $session->getStatus()); $session->start(); - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $cookieValueAfter = $this->getCookieValue($this->getCookieValues()); @@ -306,7 +311,7 @@ public function testSessionExpired(int $time, bool $equals): void $this->assertNotEquals($cookieValueBefore, $cookieValueAfter); } - $this->assertSame(2, $session->getStatus()); + $this->assertSame(PHP_SESSION_ACTIVE, $session->getStatus()); $session->destroy(); } diff --git a/tests/Linna/Storage/ExtendedPDOTest.php b/tests/Linna/Storage/ExtendedPDOTest.php index a4c8611..f3bc8be 100644 --- a/tests/Linna/Storage/ExtendedPDOTest.php +++ b/tests/Linna/Storage/ExtendedPDOTest.php @@ -16,6 +16,7 @@ use Linna\Storage\Connectors\PdoConnector; use PDO; use PDOException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -75,13 +76,12 @@ public static function correctParametersProvider(): array /** * Test query with parameters. * - * @dataProvider correctParametersProvider - * * @param string $query * @param array $param * * @return void */ + #[DataProvider('correctParametersProvider')] public function testQueryWithParameters(string $query, array $param): void { $user = (new PdoConnector(self::$options)) @@ -150,13 +150,12 @@ public function testQueryWithParameterWithoutParameters(): void /** * Test query status. * - * @dataProvider correctParametersProvider - * * @param string $query * @param array $param * * @return void */ + #[DataProvider('correctParametersProvider')] public function testQueryStatus(string $query, array $param): void { $pdo = (new PdoConnector(self::$options))->getResource(); diff --git a/tests/Linna/Storage/MongoDBConnectorTest.php b/tests/Linna/Storage/MongoDBConnectorTest.php index 26b339f..c03434a 100644 --- a/tests/Linna/Storage/MongoDBConnectorTest.php +++ b/tests/Linna/Storage/MongoDBConnectorTest.php @@ -30,7 +30,7 @@ class MongoDBConnectorTest extends TestCase public function testConnection(): void { $options = [ - 'uri' => 'mongodb://127.0.0.1/', + 'uri' => $GLOBALS['mongodb_server_string'], 'uriOptions' => [], 'driverOptions' => [], ]; diff --git a/tests/Linna/Storage/MysqliConnectorTest.php b/tests/Linna/Storage/MysqliConnectorTest.php index f4d0b97..b261f4a 100644 --- a/tests/Linna/Storage/MysqliConnectorTest.php +++ b/tests/Linna/Storage/MysqliConnectorTest.php @@ -15,6 +15,7 @@ use Linna\Storage\Connectors\MysqliConnector; use mysqli; use mysqli_sql_exception; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -30,7 +31,7 @@ class MysqliConnectorTest extends TestCase public function testConnection(): void { $options = [ - 'host' => '127.0.0.1', + 'host' => $GLOBALS['pdo_mysql_host'], 'user' => $GLOBALS['pdo_mysql_user'], 'password' => $GLOBALS['pdo_mysql_password'], 'database' => 'linna_db', @@ -59,8 +60,6 @@ public static function connectionDataProvider(): array /** * Test fail connection. * - * @dataProvider connectionDataProvider - * * @param string $host * @param string $user * @param string $password @@ -69,6 +68,8 @@ public static function connectionDataProvider(): array * * @return void */ + + #[DataProvider('connectionDataProvider')] public function testFailConnection( string $host, string $user, diff --git a/tests/Linna/Storage/PdoConnectorTest.php b/tests/Linna/Storage/PdoConnectorTest.php index daaf18c..cfe1847 100644 --- a/tests/Linna/Storage/PdoConnectorTest.php +++ b/tests/Linna/Storage/PdoConnectorTest.php @@ -15,6 +15,7 @@ use Linna\Storage\Connectors\PdoConnector; use PDO; use PDOException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Linna\TestHelper\Pdo\PdoOptionsFactory; @@ -62,14 +63,13 @@ public static function connectionDataProvider(): array /** * Test fail connection. * - * @dataProvider connectionDataProvider - * * @param string $dsn * @param string $user * @param string $password * * @return void */ + #[DataProvider('connectionDataProvider')] public function testFailConnection(string $dsn, string $user, string $password): void { $this->expectException(PDOException::class); diff --git a/tests/Linna/Storage/StorageFactoryTest.php b/tests/Linna/Storage/StorageFactoryTest.php index 3c842ea..d351dc3 100644 --- a/tests/Linna/Storage/StorageFactoryTest.php +++ b/tests/Linna/Storage/StorageFactoryTest.php @@ -71,7 +71,7 @@ public function testCreatePdo(): void public function testCreateMysqlI(): void { $options = [ - 'host' => '127.0.0.1', + 'host' => $GLOBALS['pdo_mysql_host'], 'user' => $GLOBALS['pdo_mysql_user'], 'password' => $GLOBALS['pdo_mysql_password'], 'database' => 'linna_db', @@ -89,7 +89,7 @@ public function testCreateMysqlI(): void public function testCreateMongoDb(): void { $options = [ - 'uri' => 'mongodb://localhost:27017', + 'uri' => $GLOBALS['mongodb_server_string'], 'uriOptions' => [], 'driverOptions' => [], ]; From 583dbe2a60af48f247bfc1e969244c83034ba25f Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Tue, 22 Jul 2025 20:02:36 +0200 Subject: [PATCH 2/7] fix: phpstan errors in src --- src/Linna/Authentication/ProtectedControllerTrait.php | 2 +- src/Linna/Autoloader.php | 1 + src/Linna/Cache/RedisCache.php | 1 + src/Linna/Session/EncryptedSessionHandler.php | 4 ++++ src/Linna/Storage/ExtendedPDO.php | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Linna/Authentication/ProtectedControllerTrait.php b/src/Linna/Authentication/ProtectedControllerTrait.php index a21c9eb..941cb8b 100644 --- a/src/Linna/Authentication/ProtectedControllerTrait.php +++ b/src/Linna/Authentication/ProtectedControllerTrait.php @@ -22,7 +22,7 @@ * *

This trait contains only private mothods.

*/ -trait ProtectedControllerTrait +trait ProtectedControllerTrait // @phpstan-ignore trait.unused { /** @var bool Contain login status. */ private bool $authentication = false; diff --git a/src/Linna/Autoloader.php b/src/Linna/Autoloader.php index d370aa6..580ff76 100644 --- a/src/Linna/Autoloader.php +++ b/src/Linna/Autoloader.php @@ -88,6 +88,7 @@ public function register(): bool $callback = '\Linna\Autoloader::loadClass'; $result = false; + /** @phpstan-ignore-next-line */ if (\is_callable($callback)) { /** @phpstan-ignore-next-line */ $result = $result || \spl_autoload_register($callback); diff --git a/src/Linna/Cache/RedisCache.php b/src/Linna/Cache/RedisCache.php index 843d58a..218eacb 100644 --- a/src/Linna/Cache/RedisCache.php +++ b/src/Linna/Cache/RedisCache.php @@ -40,6 +40,7 @@ public function __construct(array $options) $this->redis = new Redis(); $callback = [$this->redis, 'connect']; + /** @phpstan-ignore-next-line */ if (!isset($options['connect']['host']) || \is_callable($callback) && !\call_user_func_array($callback, $options['connect'])) { throw new InvalidArgumentException('Unable to connect to Redis server.'); } diff --git a/src/Linna/Session/EncryptedSessionHandler.php b/src/Linna/Session/EncryptedSessionHandler.php index 46d34fe..491aef5 100644 --- a/src/Linna/Session/EncryptedSessionHandler.php +++ b/src/Linna/Session/EncryptedSessionHandler.php @@ -134,6 +134,10 @@ public function read(string $id): string|false //get encrypted session data $ciphertext = $this->handler->read($id); + if ($ciphertext === false) { + return ""; + } + //if session doesn't contain data, return a void string if (\strlen($ciphertext) === 0) { return ""; diff --git a/src/Linna/Storage/ExtendedPDO.php b/src/Linna/Storage/ExtendedPDO.php index 4f7a53c..8c230a7 100644 --- a/src/Linna/Storage/ExtendedPDO.php +++ b/src/Linna/Storage/ExtendedPDO.php @@ -39,6 +39,7 @@ public function queryWithParam(string $query, array $params): PDOStatement|false $callback = [$statement, "bindParam"]; + /** @phpstan-ignore-next-line */ if (\is_callable($callback)) { foreach ($params as $value) { $this->checkValue($value); From 068d4fe7b0b52ea314f1560d0ebae136a00064a8 Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Sat, 26 Jul 2025 08:39:39 +0200 Subject: [PATCH 3/7] chore: updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d7434a..5da7d17 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ At moment, code, isn't utilized in production environment, Hope in future. # Require -- PHP >= 8.1 +- PHP >= 8.3 - PDO extension (optional) - Memcached extension (optional) - Mongodb extension (optional) @@ -77,7 +77,7 @@ Please see [CONTRIBUTING.md](https://github.com/linna/framework/blob/master/CONT ### High Priority - [ ] [IN PROGRESS] Reduce the technical debt -- [ ] [IN PROGRESS] Complete the PHP 8.1 porting +- [ ] [IN PROGRESS] Complete the PHP 8.3 porting - [X] Complete the updating and the review of the code comments - [ ] [IN PROGRESS] Create documentation for the site, api and articles about how to do things - [X] Unify database session handlers From 9c3c36e00dd8ede4e57f3ffaede72efb117bc6ac Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Sat, 26 Jul 2025 08:47:22 +0200 Subject: [PATCH 4/7] fix: php version for composer --- .github/workflows/sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index a050f2b..12fe10f 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -57,7 +57,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 tools: composer:v2 coverage: xdebug extensions: redis From c1084b43f502905b9cadfea237d608079e4c72b1 Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Sat, 26 Jul 2025 11:13:35 +0200 Subject: [PATCH 5/7] chore: sonar action switched to sonarqube --- .github/workflows/sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 12fe10f..f2a9081 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -78,7 +78,7 @@ jobs: # run: sed -i 's/\/home\/runner\/work\/framework\/framework\//\/github\/workspace\//g' coverage-report.clover - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: SonarSource/sonarqube-scan-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From b94877361129c421736e4768d02da3571b42fe3b Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Sat, 26 Jul 2025 11:25:16 +0200 Subject: [PATCH 6/7] chore: added missing test --- .github/workflows/sonar.yml | 4 ++-- .github/workflows/tests.yml | 4 ++-- .../EncryptedSessionHandlerDefaultTest.php | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index f2a9081..cceebff 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -14,14 +14,14 @@ jobs: services: mysql: - image: mysql:latest + image: mysql:9 env: MYSQL_ROOT_PASSWORD: password ports: - 3306:3306 options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10 postgres: - image: postgres:12 + image: postgres:17 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: password diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 86a6e8b..4231ac3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,14 +10,14 @@ jobs: services: mysql: - image: mysql:latest + image: mysql:9 env: MYSQL_ROOT_PASSWORD: password ports: - 3306:3306 options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10 postgres: - image: postgres:12 + image: postgres:17 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: password diff --git a/tests/Linna/Session/EncryptedSessionHandlerDefaultTest.php b/tests/Linna/Session/EncryptedSessionHandlerDefaultTest.php index 77337a4..95a9f5c 100644 --- a/tests/Linna/Session/EncryptedSessionHandlerDefaultTest.php +++ b/tests/Linna/Session/EncryptedSessionHandlerDefaultTest.php @@ -41,4 +41,28 @@ public static function setUpBeforeClass(): void self::$handler = new EncryptedSessionHandler($crypto, $handler, $addtionaData, $nonce, $key); self::$session = new Session(expire: 10); } + + /** + * Test create encrypted session handler. + * + * @runInSeparateProcess + * + * @return void + */ + public function testCreateEncryptedSessionHandler(): void + { + $crypto = new SecretKeyCrypto(); + //the handler to be decorated + $handler = new SessionHandler(); + + $addtionaData = 'session_test'; + $nonce = SecretKeyCrypto::generateNonce(); + $key = SecretKeyCrypto::generateKey(); + + $handler = new EncryptedSessionHandler($crypto, $handler, $addtionaData, $nonce, $key); + $session = new Session(expire: 10); + + $this->assertInstanceOf(EncryptedSessionHandler::class, $handler); + $this->assertInstanceOf(Session::class, $session); + } } From f9c29d263f0b2f3cfef2d1e4568baa6330fe9d79 Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Sat, 26 Jul 2025 12:15:46 +0200 Subject: [PATCH 7/7] fix: removed useless code --- src/Linna/Session/EncryptedSessionHandler.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Linna/Session/EncryptedSessionHandler.php b/src/Linna/Session/EncryptedSessionHandler.php index 491aef5..7f41fa2 100644 --- a/src/Linna/Session/EncryptedSessionHandler.php +++ b/src/Linna/Session/EncryptedSessionHandler.php @@ -134,16 +134,14 @@ public function read(string $id): string|false //get encrypted session data $ciphertext = $this->handler->read($id); - if ($ciphertext === false) { - return ""; - } - //if session doesn't contain data, return a void string + // @phpstan-ignore-next-line if (\strlen($ciphertext) === 0) { return ""; } //decrypt session data + // @phpstan-ignore-next-line $plaintext = $this->crypto->decrypt(\sodium_base642bin($ciphertext, SODIUM_BASE64_VARIANT_ORIGINAL), $this->additionalData, $this->nonce, $this->key); //return plaintext