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/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/src/Linna/Session/EncryptedSessionHandler.php b/src/Linna/Session/EncryptedSessionHandler.php index 46d34fe..7f41fa2 100644 --- a/src/Linna/Session/EncryptedSessionHandler.php +++ b/src/Linna/Session/EncryptedSessionHandler.php @@ -135,11 +135,13 @@ public function read(string $id): string|false $ciphertext = $this->handler->read($id); //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 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); 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/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); + } } 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' => [], ];