diff --git a/lib/SP/Domain/Auth/Services/AuthToken.php b/lib/SP/Domain/Auth/Services/AuthToken.php index 4e3fb8a7..c973477c 100644 --- a/lib/SP/Domain/Auth/Services/AuthToken.php +++ b/lib/SP/Domain/Auth/Services/AuthToken.php @@ -94,9 +94,8 @@ final class AuthToken extends Service implements AuthTokenService } /** - * @throws ConstraintException - * @throws QueryException - * @throws SPException + * @param int $id + * @return AuthTokenModel */ public function getById(int $id): AuthTokenModel { @@ -278,10 +277,10 @@ final class AuthToken extends Service implements AuthTokenService /** * Devolver los datos de un token * - * @throws ConstraintException + * @param int $actionId + * @param string $token + * @return AuthTokenModel * @throws NoSuchItemException - * @throws QueryException - * @throws SPException */ public function getTokenByToken(int $actionId, string $token): AuthTokenModel { @@ -296,9 +295,6 @@ final class AuthToken extends Service implements AuthTokenService /** * @return array - * @throws ConstraintException - * @throws QueryException - * @throws SPException */ public function getAll(): array { diff --git a/tests/SPT/Domain/Auth/Services/AuthTokenTest.php b/tests/SPT/Domain/Auth/Services/AuthTokenTest.php index efe2698e..cfdf0800 100644 --- a/tests/SPT/Domain/Auth/Services/AuthTokenTest.php +++ b/tests/SPT/Domain/Auth/Services/AuthTokenTest.php @@ -59,7 +59,7 @@ class AuthTokenTest extends UnitaryTestCase private AuthTokenRepository|MockObject $authTokenRepository; private CryptInterface|MockObject $crypt; - private AuthToken $authToken; + private AuthToken $authToken; public static function secureActionDataProvider(): array { @@ -567,12 +567,7 @@ class AuthTokenTest extends UnitaryTestCase $this->authTokenRepository ->expects(self::once()) ->method('transactionAware') - ->with( - new Callback(function (callable $callable) use ($authToken) { - $callable(); - return true; - }) - ) + ->with(self::withResolveCallableCallback()) ->willReturn(true); $this->authTokenRepository diff --git a/tests/SPT/Domain/Config/Services/ConfigTest.php b/tests/SPT/Domain/Config/Services/ConfigTest.php index 956da3da..e9731600 100644 --- a/tests/SPT/Domain/Config/Services/ConfigTest.php +++ b/tests/SPT/Domain/Config/Services/ConfigTest.php @@ -25,7 +25,6 @@ namespace SPT\Domain\Config\Services; use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; use RuntimeException; use SP\DataModel\Dto\ConfigRequest; @@ -216,13 +215,7 @@ class ConfigTest extends UnitaryTestCase $this->configRepository ->expects(self::once()) ->method('transactionAware') - ->with( - new Callback(function (callable $closure) { - $closure(); - - return true; - }) - ); + ->with(self::withResolveCallableCallback()); $this->configRepository ->expects(self::exactly(3)) diff --git a/tests/SPT/Domain/Crypt/Services/MasterPassTest.php b/tests/SPT/Domain/Crypt/Services/MasterPassTest.php index 6d830d42..0dee2d43 100644 --- a/tests/SPT/Domain/Crypt/Services/MasterPassTest.php +++ b/tests/SPT/Domain/Crypt/Services/MasterPassTest.php @@ -27,7 +27,6 @@ namespace SPT\Domain\Crypt\Services; use Dotenv\Repository\RepositoryInterface; use Exception; use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; use SP\Domain\Account\Ports\AccountCryptService; use SP\Domain\Common\Ports\Repository; @@ -49,11 +48,11 @@ use SPT\UnitaryTestCase; class MasterPassTest extends UnitaryTestCase { - private ConfigService|MockObject $configService; + private ConfigService|MockObject $configService; private AccountCryptService|MockObject $accountCryptService; private CustomFieldCryptService|MockObject $customFieldCryptService; private MockObject|RepositoryInterface $repository; - private MasterPass $masterPass; + private MasterPass $masterPass; public function testCheckUserUpdateMPassWithFutureTime() { @@ -166,13 +165,7 @@ class MasterPassTest extends UnitaryTestCase $this->repository ->expects(self::once()) ->method('transactionAware') - ->with( - new Callback(static function (callable $callable) { - $callable(); - - return true; - }) - ); + ->with(self::withResolveCallableCallback()); $request = new UpdateMasterPassRequest('123', '456', $hash); @@ -236,5 +229,4 @@ class MasterPassTest extends UnitaryTestCase $this->repository ); } - } diff --git a/tests/SPT/Domain/Plugin/Services/PluginUpgraderTest.php b/tests/SPT/Domain/Plugin/Services/PluginUpgraderTest.php index e4c6a709..866d29d4 100644 --- a/tests/SPT/Domain/Plugin/Services/PluginUpgraderTest.php +++ b/tests/SPT/Domain/Plugin/Services/PluginUpgraderTest.php @@ -62,17 +62,19 @@ class PluginUpgraderTest extends UnitaryTestCase ->method('getByName') ->willReturn($pluginModel); - $version = $pluginModel->getVersionLevel() + 100; + [$version, $build] = explode('.', $pluginModel->getVersionLevel()); + + $upgradeVersion = sprintf('%d.%d', (int)$version + 100, (int)$build); $plugin->expects($this->once()) ->method('onUpgrade') - ->with($version); + ->with($upgradeVersion); $pluginManagerService->expects($this->once()) ->method('update') - ->with($pluginModel->mutate(['data' => null, 'versionLevel' => $version])); + ->with($pluginModel->mutate(['data' => null, 'versionLevel' => $upgradeVersion])); - $pluginUpgrader->upgradeFor($plugin, $version); + $pluginUpgrader->upgradeFor($plugin, $upgradeVersion); } /** @@ -95,7 +97,9 @@ class PluginUpgraderTest extends UnitaryTestCase ->method('getByName') ->willReturn($pluginModel); - $version = $pluginModel->getVersionLevel() - 100; + [$version, $build] = explode('.', $pluginModel->getVersionLevel()); + + $upgradeVersion = sprintf('%d.%d', (int)$version - 100, (int)$build); $plugin->expects($this->never()) ->method('onUpgrade'); @@ -103,7 +107,7 @@ class PluginUpgraderTest extends UnitaryTestCase $pluginManagerService->expects($this->never()) ->method('update'); - $pluginUpgrader->upgradeFor($plugin, $version); + $pluginUpgrader->upgradeFor($plugin, $upgradeVersion); } /** diff --git a/tests/SPT/Generators/PluginGenerator.php b/tests/SPT/Generators/PluginGenerator.php index 79fef206..ffe01152 100644 --- a/tests/SPT/Generators/PluginGenerator.php +++ b/tests/SPT/Generators/PluginGenerator.php @@ -47,5 +47,4 @@ final class PluginGenerator extends DataGenerator 'versionLevel' => sprintf('%d.%d', $this->faker->randomNumber(3, true), $this->faker->randomNumber(6, true)) ]; } - } diff --git a/tests/SPT/PHPUnitHelper.php b/tests/SPT/PHPUnitHelper.php index 9a3c47c9..1578cca4 100644 --- a/tests/SPT/PHPUnitHelper.php +++ b/tests/SPT/PHPUnitHelper.php @@ -104,4 +104,20 @@ trait PHPUnitHelper } }); } + + public static function withResolveCallableCallback(): Callback + { + return new Callback(function (callable $callable) { + $callable(); + return true; + }); + } + + public static function getRepositoryStubMethods(string $class): array + { + return array_filter( + get_class_methods($class), + static fn(string $method) => $method != 'transactionAware' + ); + } } diff --git a/tests/SPT/Stubs/AccountRepositoryStub.php b/tests/SPT/Stubs/AccountRepositoryStub.php index 871455af..6d036482 100644 --- a/tests/SPT/Stubs/AccountRepositoryStub.php +++ b/tests/SPT/Stubs/AccountRepositoryStub.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,6 @@ namespace SPT\Stubs; -use Closure; use SP\Domain\Account\Ports\AccountRepository; /** @@ -32,8 +31,5 @@ use SP\Domain\Account\Ports\AccountRepository; */ abstract class AccountRepositoryStub implements AccountRepository { - public function transactionAware(Closure $closure, object $newThis): mixed - { - return $closure->call($newThis); - } + use TransactionAwareTrait; } diff --git a/tests/SPT/Stubs/PublicLinkRepositoryStub.php b/tests/SPT/Stubs/PublicLinkRepositoryStub.php index 77b40cdb..5043ee6e 100644 --- a/tests/SPT/Stubs/PublicLinkRepositoryStub.php +++ b/tests/SPT/Stubs/PublicLinkRepositoryStub.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,16 +24,12 @@ namespace SPT\Stubs; -use Closure; use SP\Domain\Account\Ports\PublicLinkRepository; /** - * Class AbstractPublicLinkRepositoryStub + * Class PublicLinkRepositoryStub */ abstract class PublicLinkRepositoryStub implements PublicLinkRepository { - public function transactionAware(Closure $closure, object $newThis): mixed - { - return $closure->call($newThis); - } + use TransactionAwareTrait; } diff --git a/tests/SPT/Stubs/TransactionAwareTrait.php b/tests/SPT/Stubs/TransactionAwareTrait.php new file mode 100644 index 00000000..5b0f1ccc --- /dev/null +++ b/tests/SPT/Stubs/TransactionAwareTrait.php @@ -0,0 +1,38 @@ +. + */ + +namespace SPT\Stubs; + +use Closure; + +/** + * Trait TransactionAwareTrait + */ +trait TransactionAwareTrait +{ + public function transactionAware(Closure $closure, object $newThis): mixed + { + return $closure->call($newThis); + } +}