From 739f40ba5dd4243b397f8fce942e60101152e8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sun, 14 Jan 2024 10:42:45 +0100 Subject: [PATCH] chore(tests): UT for Config service & repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- app/modules/cli/Commands/BackupCommand.php | 9 +- app/modules/cli/Commands/CommandBase.php | 10 +- .../Crypt/UpdateMasterPasswordCommand.php | 27 +- app/modules/cli/Commands/InstallCommand.php | 8 +- .../ConfigEncryption/SaveController.php | 8 +- .../ConfigGeneral/DownloadConfigBackup.php | 12 +- .../ConfigManager/IndexController.php | 12 +- .../web/Controllers/ControllerBase.php | 10 +- .../web/Controllers/Helpers/HelperBase.php | 10 +- .../web/Controllers/SimpleControllerBase.php | 10 +- .../web/Controllers/Traits/ConfigTrait.php | 8 +- app/modules/web/Forms/FormBase.php | 6 +- lib/SP/Core/Application.php | 10 +- lib/SP/Core/Definitions/CoreDefinitions.php | 16 +- lib/SP/Core/ModuleBase.php | 8 +- lib/SP/DataModel/ConfigData.php | 87 ------ lib/SP/DataModel/Dto/ConfigRequest.php | 30 +- .../Account/Services/AccountService.php | 6 +- .../Account/Services/PublicLinkService.php | 6 +- lib/SP/Domain/Auth/Services/AuthToken.php | 7 +- lib/SP/Domain/Category/Services/Category.php | 5 +- .../Domain/Client/Adapters/ClientAdapter.php | 10 +- lib/SP/Domain/Client/Models/Client.php | 2 +- lib/SP/Domain/Client/Services/Client.php | 3 - lib/SP/Domain/Common/Models/Model.php | 16 +- lib/SP/Domain/Common/Services/Service.php | 9 +- .../Common/Services/ServiceItemTrait.php | 3 +- lib/SP/Domain/Config/Models/Config.php | 46 +++ ...eInterface.php => ConfigBackupService.php} | 12 +- ...figInterface.php => ConfigFileService.php} | 12 +- ...toryInterface.php => ConfigRepository.php} | 57 ++-- ...ServiceInterface.php => ConfigService.php} | 32 +- .../{ConfigService.php => Config.php} | 89 ++---- ...nfigBackupService.php => ConfigBackup.php} | 22 +- .../{ConfigFileService.php => ConfigFile.php} | 45 ++- .../Crypt/Services/MasterPassService.php | 16 +- .../Services/TemporaryMasterPassService.php | 12 +- .../Export/Services/FileBackupService.php | 6 +- .../Domain/Import/Services/ImportService.php | 16 +- lib/SP/Domain/Import/Services/XmlImport.php | 20 +- .../Domain/Import/Services/XmlImportBase.php | 18 +- .../Install/Services/InstallerService.php | 75 +++-- .../Domain/Upgrade/Services/UpgradeUtil.php | 6 +- .../Domain/User/Services/UserPassService.php | 14 +- .../Config/Repositories/Config.php | 129 ++++++++ .../Config/Repositories/ConfigRepository.php | 136 --------- lib/SP/Providers/Provider.php | 8 +- tests/SPT/Config/ConfigTest.php | 30 +- .../AccountSearchTokenizerDataTrait.php | 28 +- .../Services/AccountSearchServiceTest.php | 23 +- .../Account/Services/AccountServiceTest.php | 8 +- .../Config/Services/ConfigBackupTest.php | 222 ++++++++++++++ .../SPT/Domain/Config/Services/ConfigTest.php | 286 ++++++++++++++++++ .../Domain/Install/Services/InstallerTest.php | 8 +- tests/SPT/Generators/ConfigGenerator.php | 47 +++ .../Repositories/ClientRepositoryTest.php | 4 +- .../Config/Repositories/ConfigTest.php | 185 +++++++++++ tests/SPT/Modules/Api/ApiTestCase.php | 6 +- .../Cli/Commands/BackupCommandTest.php | 6 +- .../Cli/Commands/InstallCommandTest.php | 10 +- tests/SPT/UnitaryTestCase.php | 12 +- 61 files changed, 1304 insertions(+), 690 deletions(-) delete mode 100644 lib/SP/DataModel/ConfigData.php create mode 100644 lib/SP/Domain/Config/Models/Config.php rename lib/SP/Domain/Config/Ports/{ConfigBackupServiceInterface.php => ConfigBackupService.php} (78%) rename lib/SP/Domain/Config/Ports/{ConfigInterface.php => ConfigFileService.php} (89%) rename lib/SP/Domain/Config/Ports/{ConfigRepositoryInterface.php => ConfigRepository.php} (61%) rename lib/SP/Domain/Config/Ports/{ConfigServiceInterface.php => ConfigService.php} (64%) rename lib/SP/Domain/Config/Services/{ConfigService.php => Config.php} (57%) rename lib/SP/Domain/Config/Services/{ConfigBackupService.php => ConfigBackup.php} (82%) rename lib/SP/Domain/Config/Services/{ConfigFileService.php => ConfigFile.php} (85%) create mode 100644 lib/SP/Infrastructure/Config/Repositories/Config.php delete mode 100644 lib/SP/Infrastructure/Config/Repositories/ConfigRepository.php create mode 100644 tests/SPT/Domain/Config/Services/ConfigBackupTest.php create mode 100644 tests/SPT/Domain/Config/Services/ConfigTest.php create mode 100644 tests/SPT/Generators/ConfigGenerator.php create mode 100644 tests/SPT/Infrastructure/Config/Repositories/ConfigTest.php diff --git a/app/modules/cli/Commands/BackupCommand.php b/app/modules/cli/Commands/BackupCommand.php index 3a9aeb51..6982c1ba 100644 --- a/app/modules/cli/Commands/BackupCommand.php +++ b/app/modules/cli/Commands/BackupCommand.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,7 +27,7 @@ namespace SP\Modules\Cli\Commands; use Exception; use Psr\Log\LoggerInterface; use RuntimeException; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Export\Ports\FileBackupServiceInterface; use SP\Domain\Export\Services\FileBackupService; use Symfony\Component\Console\Input\InputInterface; @@ -57,8 +57,9 @@ final class BackupCommand extends CommandBase public function __construct( FileBackupServiceInterface $fileBackupService, - LoggerInterface $logger, - ConfigInterface $config) + LoggerInterface $logger, + ConfigFileService $config + ) { $this->fileBackupService = $fileBackupService; diff --git a/app/modules/cli/Commands/CommandBase.php b/app/modules/cli/Commands/CommandBase.php index f431ef1f..571a143a 100644 --- a/app/modules/cli/Commands/CommandBase.php +++ b/app/modules/cli/Commands/CommandBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,8 +26,8 @@ namespace SP\Modules\Cli\Commands; use Psr\Log\LoggerInterface; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -40,12 +40,12 @@ abstract class CommandBase extends Command { public static array $envVarsMapping = []; protected LoggerInterface $logger; - protected ConfigFileService $config; + protected ConfigFile $config; protected ConfigDataInterface $configData; public function __construct( LoggerInterface $logger, - ConfigInterface $config + ConfigFileService $config ) { $this->logger = $logger; diff --git a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php index 95a953ec..9e663fb1 100644 --- a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php +++ b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,11 +29,14 @@ use Psr\Log\LoggerInterface; use RuntimeException; use SP\Domain\Account\Ports\AccountServiceInterface; use SP\Domain\Account\Services\AccountService; -use SP\Domain\Config\Ports\ConfigInterface; -use SP\Domain\Config\Ports\ConfigServiceInterface; -use SP\Domain\Config\Services\ConfigService; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Ports\ConfigService; +use SP\Domain\Config\Services\Config; +use SP\Domain\Crypt\Ports\MasterPassServiceInterface; use SP\Domain\Crypt\Services\MasterPassService; use SP\Domain\Crypt\Services\UpdateMasterPassRequest; +use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Cli\Commands\CommandBase; use SP\Modules\Cli\Commands\Validators; use SP\Util\Util; @@ -65,16 +68,16 @@ final class UpdateMasterPasswordCommand extends CommandBase * @var string */ protected static $defaultName = 'sp:crypt:update-master-password'; - private \SP\Domain\Crypt\Ports\MasterPassServiceInterface $masterPassService; - private ConfigService $configService; + private MasterPassServiceInterface $masterPassService; + private Config $configService; private AccountService $accountService; public function __construct( - \SP\Domain\Crypt\Ports\MasterPassServiceInterface $masterPassService, + MasterPassServiceInterface $masterPassService, AccountServiceInterface $accountService, - ConfigServiceInterface $configService, - LoggerInterface $logger, - ConfigInterface $config + ConfigService $configService, + LoggerInterface $logger, + ConfigFileService $config ) { $this->masterPassService = $masterPassService; $this->accountService = $accountService; @@ -273,8 +276,8 @@ final class UpdateMasterPasswordCommand extends CommandBase } /** - * @throws \SP\Domain\Common\Services\ServiceException - * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException + * @throws ServiceException + * @throws NoSuchItemException */ private function checkMasterPassword(string $password): void { diff --git a/app/modules/cli/Commands/InstallCommand.php b/app/modules/cli/Commands/InstallCommand.php index 82193a3e..5c4e1884 100644 --- a/app/modules/cli/Commands/InstallCommand.php +++ b/app/modules/cli/Commands/InstallCommand.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,7 +27,7 @@ namespace SP\Modules\Cli\Commands; use Exception; use Psr\Log\LoggerInterface; use SP\Core\Language; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Exceptions\InstallError; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Install\Adapters\InstallData; @@ -71,8 +71,8 @@ final class InstallCommand extends CommandBase private InstallerService $installer; public function __construct( - LoggerInterface $logger, - ConfigInterface $config, + LoggerInterface $logger, + ConfigFileService $config, InstallerServiceInterface $installer ) { parent::__construct($logger, $config); diff --git a/app/modules/web/Controllers/ConfigEncryption/SaveController.php b/app/modules/web/Controllers/ConfigEncryption/SaveController.php index f37b9b7b..fd40ef20 100644 --- a/app/modules/web/Controllers/ConfigEncryption/SaveController.php +++ b/app/modules/web/Controllers/ConfigEncryption/SaveController.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. * @@ -31,7 +31,7 @@ use SP\Core\Application; use SP\Core\Crypt\Hash; use SP\Core\Events\Event; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Exceptions\SessionTimeout; @@ -56,13 +56,13 @@ final class SaveController extends SimpleControllerBase use JsonTrait; private MasterPassServiceInterface $masterPassService; - private ConfigServiceInterface $configService; + private ConfigService $configService; public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper, MasterPassServiceInterface $masterPassService, - ConfigServiceInterface $configService + ConfigService $configService ) { parent::__construct($application, $simpleControllerHelper); diff --git a/app/modules/web/Controllers/ConfigGeneral/DownloadConfigBackup.php b/app/modules/web/Controllers/ConfigGeneral/DownloadConfigBackup.php index 9d2d59a4..3fc274a8 100644 --- a/app/modules/web/Controllers/ConfigGeneral/DownloadConfigBackup.php +++ b/app/modules/web/Controllers/ConfigGeneral/DownloadConfigBackup.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. * @@ -30,8 +30,8 @@ use RuntimeException; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Domain\Config\Ports\ConfigBackupServiceInterface; -use SP\Domain\Config\Services\ConfigBackupService; +use SP\Domain\Config\Ports\ConfigBackupService; +use SP\Domain\Config\Services\ConfigBackup; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Exceptions\SessionTimeout; @@ -46,12 +46,12 @@ final class DownloadConfigBackup extends SimpleControllerBase { use JsonTrait; - private ConfigBackupServiceInterface $configBackupService; + private ConfigBackupService $configBackupService; public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper, - ConfigBackupServiceInterface $configBackupService + ConfigBackupService $configBackupService ) { parent::__construct($application, $simpleControllerHelper); @@ -76,7 +76,7 @@ final class DownloadConfigBackup extends SimpleControllerBase ); if ($type === 'json') { - $data = ConfigBackupService::configToJson($this->configBackupService->getBackup()); + $data = ConfigBackup::configToJson($this->configBackupService->getBackup()); } else { throw new RuntimeException('Not implemented'); } diff --git a/app/modules/web/Controllers/ConfigManager/IndexController.php b/app/modules/web/Controllers/ConfigManager/IndexController.php index cafee440..3f02bc9f 100644 --- a/app/modules/web/Controllers/ConfigManager/IndexController.php +++ b/app/modules/web/Controllers/ConfigManager/IndexController.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. * @@ -35,7 +35,7 @@ use SP\Core\Events\Event; use SP\Core\Language; use SP\Domain\Account\Ports\AccountServiceInterface; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\AppInfoInterface; use SP\Domain\Core\Exceptions\CheckException; @@ -78,9 +78,9 @@ final class IndexController extends ControllerBase private UserGroupServiceInterface $userGroupService; private UserProfileServiceInterface $userProfileService; private MimeTypesInterface $mimeTypes; - private DatabaseUtil $databaseUtil; - private ConfigServiceInterface $configService; - private AccountServiceInterface $accountService; + private DatabaseUtil $databaseUtil; + private ConfigService $configService; + private AccountServiceInterface $accountService; private PluginManager $pluginManager; public function __construct( @@ -92,7 +92,7 @@ final class IndexController extends ControllerBase UserProfileServiceInterface $userProfileService, MimeTypesInterface $mimeTypes, DatabaseUtil $databaseUtil, - ConfigServiceInterface $configService, + ConfigService $configService, AccountServiceInterface $accountService, PluginManager $pluginManager ) { diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 0c0917b4..c0a83e6b 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.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. * @@ -34,7 +34,7 @@ use SP\Core\Events\EventDispatcher; use SP\DataModel\ProfileData; use SP\Domain\Auth\Services\AuthException; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Context\SessionContextInterface; use SP\Domain\Core\Exceptions\FileNotFoundException; @@ -63,9 +63,9 @@ abstract class ControllerBase protected const ERR_UNAVAILABLE = 0; - protected EventDispatcher $eventDispatcher; - protected ConfigInterface $config; - protected SessionContextInterface $session; + protected EventDispatcher $eventDispatcher; + protected ConfigFileService $config; + protected SessionContextInterface $session; protected ThemeInterface $theme; protected AclInterface $acl; protected ConfigDataInterface $configData; diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php index 1eed65c6..d72b1587 100644 --- a/app/modules/web/Controllers/Helpers/HelperBase.php +++ b/app/modules/web/Controllers/Helpers/HelperBase.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. * @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Helpers; use SP\Core\Application; use SP\Core\Events\EventDispatcher; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Http\RequestInterface; use SP\Http\Request; @@ -43,9 +43,9 @@ abstract class HelperBase protected TemplateInterface $view; protected ConfigDataInterface $configData; protected ContextInterface $context; - protected EventDispatcher $eventDispatcher; - protected ConfigFileService $config; - protected Request $request; + protected EventDispatcher $eventDispatcher; + protected ConfigFile $config; + protected Request $request; /** * Constructor diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index 7ae9e1f2..483c2198 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,7 +29,7 @@ use SP\Core\Application; use SP\Core\Events\EventDispatcher; use SP\Core\PhpExtensionChecker; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Exceptions\SessionTimeout; @@ -48,9 +48,9 @@ abstract class SimpleControllerBase { use WebControllerTrait; - protected EventDispatcher $eventDispatcher; - protected ConfigFileService $config; - protected ContextInterface $session; + protected EventDispatcher $eventDispatcher; + protected ConfigFile $config; + protected ContextInterface $session; protected ThemeInterface $theme; protected Acl $acl; protected Request $request; diff --git a/app/modules/web/Controllers/Traits/ConfigTrait.php b/app/modules/web/Controllers/Traits/ConfigTrait.php index e09810e7..5f8a7ef4 100644 --- a/app/modules/web/Controllers/Traits/ConfigTrait.php +++ b/app/modules/web/Controllers/Traits/ConfigTrait.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. * @@ -28,7 +28,7 @@ use Exception; use JsonException; use SP\Core\Bootstrap\BootstrapBase; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Http\JsonMessage; use SP\Util\Util; @@ -48,8 +48,8 @@ trait ConfigTrait */ protected function saveConfig( ConfigDataInterface $configData, - ConfigInterface $config, - callable $onSuccess = null + ConfigFileService $config, + callable $onSuccess = null ): bool { try { if ($configData->isDemoEnabled()) { diff --git a/app/modules/web/Forms/FormBase.php b/app/modules/web/Forms/FormBase.php index 1999ce6e..3aac5f3e 100644 --- a/app/modules/web/Forms/FormBase.php +++ b/app/modules/web/Forms/FormBase.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. * @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Forms; use SP\Core\Application; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Http\RequestInterface; @@ -37,7 +37,7 @@ use SP\Domain\Http\RequestInterface; */ abstract class FormBase { - protected ConfigFileService $config; + protected ConfigFile $config; protected ConfigDataInterface $configData; protected ContextInterface $context; diff --git a/lib/SP/Core/Application.php b/lib/SP/Core/Application.php index c96766d1..8da31ce1 100644 --- a/lib/SP/Core/Application.php +++ b/lib/SP/Core/Application.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,7 @@ namespace SP\Core; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Context\SessionContextInterface; use SP\Domain\Core\Events\EventDispatcherInterface; @@ -37,18 +37,18 @@ final class Application /** * Module constructor. * - * @param ConfigInterface $config + * @param ConfigFileService $config * @param EventDispatcherInterface $eventDispatcher * @param SessionContextInterface|ContextInterface $context */ public function __construct( - private readonly ConfigInterface $config, + private readonly ConfigFileService $config, private readonly EventDispatcherInterface $eventDispatcher, private readonly SessionContextInterface|ContextInterface $context ) { } - public function getConfig(): ConfigInterface + public function getConfig(): ConfigFileService { return $this->config; } diff --git a/lib/SP/Core/Definitions/CoreDefinitions.php b/lib/SP/Core/Definitions/CoreDefinitions.php index 72e0522d..de8ae85d 100644 --- a/lib/SP/Core/Definitions/CoreDefinitions.php +++ b/lib/SP/Core/Definitions/CoreDefinitions.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. * @@ -51,9 +51,9 @@ use SP\Domain\Auth\Ports\LdapActionsInterface; use SP\Domain\Auth\Ports\LdapAuthInterface; use SP\Domain\Auth\Ports\LdapConnectionInterface; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; -use SP\Domain\Config\Services\ConfigBackupService; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Services\ConfigBackup; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Acl\ActionsInterface; use SP\Domain\Core\Bootstrap\UriContextInterface; use SP\Domain\Core\Context\ContextInterface; @@ -130,16 +130,16 @@ final class CoreDefinitions UriContextInterface::class => autowire(UriContext::class), ContextInterface::class => static fn() => ContextFactory::getForModule(APP_MODULE), - ConfigInterface::class => create(ConfigFileService::class) + ConfigFileService::class => create(ConfigFile::class) ->constructor( create(XmlHandler::class) ->constructor(create(FileHandler::class)->constructor(CONFIG_FILE)), - create(FileCache::class)->constructor(ConfigFileService::CONFIG_CACHE_FILE), + create(FileCache::class)->constructor(ConfigFile::CONFIG_CACHE_FILE), get(ContextInterface::class), - autowire(ConfigBackupService::class) + autowire(ConfigBackup::class) ), ConfigDataInterface::class => - static fn(ConfigInterface $config) => $config->getConfigData(), + static fn(ConfigFileService $config) => $config->getConfigData(), DatabaseConnectionData::class => factory([DatabaseConnectionData::class, 'getFromConfig']), DbStorageInterface::class => autowire(MysqlHandler::class), ActionsInterface::class => diff --git a/lib/SP/Core/ModuleBase.php b/lib/SP/Core/ModuleBase.php index 410766cd..41918127 100644 --- a/lib/SP/Core/ModuleBase.php +++ b/lib/SP/Core/ModuleBase.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. * @@ -25,7 +25,7 @@ namespace SP\Core; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Bootstrap\ModuleInterface; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Events\EventDispatcherInterface; @@ -35,8 +35,8 @@ use SP\Domain\Core\Events\EventDispatcherInterface; */ abstract class ModuleBase implements ModuleInterface { - protected ConfigFileService $config; - protected ConfigDataInterface $configData; + protected ConfigFile $config; + protected ConfigDataInterface $configData; protected ContextInterface $context; private EventDispatcherInterface $eventDispatcher; diff --git a/lib/SP/DataModel/ConfigData.php b/lib/SP/DataModel/ConfigData.php deleted file mode 100644 index 5ca165a2..00000000 --- a/lib/SP/DataModel/ConfigData.php +++ /dev/null @@ -1,87 +0,0 @@ -. - */ - -namespace SP\DataModel; - - -/** - * Class ConfigData - * - * @package SP\DataModel - */ -class ConfigData -{ - /** - * @var string - */ - public $parameter; - /** - * @var string - */ - public $value; - - /** - * ConfigData constructor. - * - * @param string $param - * @param string $value - */ - public function __construct($param, $value) - { - $this->parameter = $param; - $this->value = $value; - } - - /** - * @return string - */ - public function getParameter() - { - return $this->parameter; - } - - /** - * @param string $parameter - */ - public function setParameter($parameter) - { - $this->parameter = $parameter; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * @param string $value - */ - public function setValue($value) - { - $this->value = $value; - } -} \ No newline at end of file diff --git a/lib/SP/DataModel/Dto/ConfigRequest.php b/lib/SP/DataModel/Dto/ConfigRequest.php index 0bc8f239..37dd0e49 100644 --- a/lib/SP/DataModel/Dto/ConfigRequest.php +++ b/lib/SP/DataModel/Dto/ConfigRequest.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,43 +24,25 @@ namespace SP\DataModel\Dto; - /** * Class ConfigRequest - * - * @package SP\DataModel\Dto */ class ConfigRequest { - /** - * @var array - */ - private $data = []; + private array $data = []; - /** - * @param $param - * @param $value - */ - public function add($param, $value) + public function add(string $param, string $value): void { $this->data[$param] = $value; } - /** - * @param $param - * - * @return mixed|null - */ - public function get($param) + public function get(string $param): ?string { return $this->data[$param] ?? null; } - /** - * @return array - */ - public function getData() + public function getData(): array { return $this->data; } -} \ No newline at end of file +} diff --git a/lib/SP/Domain/Account/Services/AccountService.php b/lib/SP/Domain/Account/Services/AccountService.php index 51d7c642..3993075a 100644 --- a/lib/SP/Domain/Account/Services/AccountService.php +++ b/lib/SP/Domain/Account/Services/AccountService.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. * @@ -49,7 +49,7 @@ use SP\Domain\Account\Ports\AccountToUserRepositoryInterface; use SP\Domain\Common\Models\Simple; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; @@ -79,7 +79,7 @@ final class AccountService extends Service implements AccountServiceInterface private AccountHistoryServiceInterface $accountHistoryService, private AccountItemsServiceInterface $accountItemsService, private AccountPresetServiceInterface $accountPresetService, - private ConfigServiceInterface $configService, + private ConfigService $configService, private AccountCryptServiceInterface $accountCryptService ) { parent::__construct($application); diff --git a/lib/SP/Domain/Account/Services/PublicLinkService.php b/lib/SP/Domain/Account/Services/PublicLinkService.php index 4d3e2582..d4a22a44 100644 --- a/lib/SP/Domain/Account/Services/PublicLinkService.php +++ b/lib/SP/Domain/Account/Services/PublicLinkService.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. * @@ -38,7 +38,7 @@ use SP\Domain\Common\Models\Simple; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Common\Services\ServiceItemTrait; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\CryptException; @@ -211,7 +211,7 @@ final class PublicLinkService extends Service implements PublicLinkServiceInterf /** * Devolver el tiempo de caducidad del enlace */ - public static function calcDateExpire(ConfigInterface $config): int + public static function calcDateExpire(ConfigFileService $config): int { return time() + $config->getConfigData()->getPublinksMaxTime(); } diff --git a/lib/SP/Domain/Auth/Services/AuthToken.php b/lib/SP/Domain/Auth/Services/AuthToken.php index 8f057d2c..3637e8bf 100644 --- a/lib/SP/Domain/Auth/Services/AuthToken.php +++ b/lib/SP/Domain/Auth/Services/AuthToken.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. * @@ -36,7 +36,6 @@ use SP\Domain\Auth\Ports\AuthTokenRepositoryInterface; use SP\Domain\Auth\Ports\AuthTokenServiceInterface; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Common\Services\ServiceItemTrait; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Crypt\CryptInterface; use SP\Domain\Core\Crypt\VaultInterface; @@ -52,14 +51,12 @@ use SP\Util\PasswordUtil; use function SP\__u; /** - * Class AuthTokenService + * Class AuthToken * * @template T of AuthTokenModel */ final class AuthToken extends Service implements AuthTokenServiceInterface { - use ServiceItemTrait; - private const SECURED_ACTIONS = [ AclActionsInterface::ACCOUNT_VIEW_PASS, AclActionsInterface::ACCOUNT_EDIT_PASS, diff --git a/lib/SP/Domain/Category/Services/Category.php b/lib/SP/Domain/Category/Services/Category.php index dd292618..78c4ce82 100644 --- a/lib/SP/Domain/Category/Services/Category.php +++ b/lib/SP/Domain/Category/Services/Category.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. * @@ -32,7 +32,6 @@ use SP\Domain\Category\Ports\CategoryRepositoryInterface; use SP\Domain\Category\Ports\CategoryServiceInterface; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Common\Services\ServiceItemTrait; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -49,8 +48,6 @@ use function SP\__u; */ final class Category extends Service implements CategoryServiceInterface { - use ServiceItemTrait; - public function __construct( Application $application, private readonly CategoryRepositoryInterface $categoryRepository diff --git a/lib/SP/Domain/Client/Adapters/ClientAdapter.php b/lib/SP/Domain/Client/Adapters/ClientAdapter.php index 56a67cc9..05aba1f0 100644 --- a/lib/SP/Domain/Client/Adapters/ClientAdapter.php +++ b/lib/SP/Domain/Client/Adapters/ClientAdapter.php @@ -66,12 +66,12 @@ final class ClientAdapter extends Adapter implements ClientAdapterInterface public function transform(Client $data): array { return [ - 'id' => $data->getId(), - 'name' => $data->getName(), - 'description' => $data->getDescription(), - 'isGlobal' => $data->isGlobal, + 'id' => $data->getId(), + 'name' => $data->getName(), + 'description' => $data->getDescription(), + 'isGlobal' => $data->getIsGlobal(), 'customFields' => null, - 'links' => [ + 'links' => [ [ 'rel' => 'self', 'uri' => Link::getDeepLink( diff --git a/lib/SP/Domain/Client/Models/Client.php b/lib/SP/Domain/Client/Models/Client.php index 7d026bdc..e139bd2c 100644 --- a/lib/SP/Domain/Client/Models/Client.php +++ b/lib/SP/Domain/Client/Models/Client.php @@ -32,7 +32,7 @@ use SP\Domain\Common\Models\Model; */ class Client extends Model implements DataModelInterface { - public ?int $isGlobal = null; + protected ?int $isGlobal = null; protected ?int $id = null; protected ?string $name = null; protected ?string $description = null; diff --git a/lib/SP/Domain/Client/Services/Client.php b/lib/SP/Domain/Client/Services/Client.php index 44ab327b..e6746f2e 100644 --- a/lib/SP/Domain/Client/Services/Client.php +++ b/lib/SP/Domain/Client/Services/Client.php @@ -33,7 +33,6 @@ use SP\Domain\Client\Ports\ClientServiceInterface; use SP\Domain\Common\Models\Simple; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Common\Services\ServiceItemTrait; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -50,8 +49,6 @@ use function SP\__u; */ final class Client extends Service implements ClientServiceInterface { - use ServiceItemTrait; - public function __construct( Application $application, private readonly ClientRepositoryInterface $clientRepository, diff --git a/lib/SP/Domain/Common/Models/Model.php b/lib/SP/Domain/Common/Models/Model.php index 284c2796..02081928 100644 --- a/lib/SP/Domain/Common/Models/Model.php +++ b/lib/SP/Domain/Common/Models/Model.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. * @@ -80,12 +80,12 @@ abstract class Model implements JsonSerializable, ArrayAccess /** * @param array|null $only Include only these properties - * @param array|null $filter Filter out these properties + * @param array|null $exclude Filter out these properties * @param bool $includeOuter Whether to include non-class properties * * @return array */ - final public function toArray(?array $only = null, ?array $filter = null, bool $includeOuter = false): array + final public function toArray(?array $only = null, ?array $exclude = null, bool $includeOuter = false): array { $fields = $this->getClassProperties(); @@ -97,8 +97,8 @@ abstract class Model implements JsonSerializable, ArrayAccess $fields = array_intersect_key($fields, array_flip($only)); } - if (null !== $filter) { - $fields = array_diff_key($fields, array_flip($filter)); + if (null !== $exclude) { + $fields = array_diff_key($fields, array_flip($exclude)); } return $fields; @@ -107,15 +107,15 @@ abstract class Model implements JsonSerializable, ArrayAccess /** * Get columns name for this model * - * @param array|null $filter + * @param array|null $exclude The columns to filter out from this model * * @return array */ - final public static function getCols(?array $filter = null): array + final public static function getCols(?array $exclude = null): array { $self = new static(); - return array_keys($self->toArray(null, $filter, false)); + return array_keys($self->toArray(null, $exclude)); } /** diff --git a/lib/SP/Domain/Common/Services/Service.php b/lib/SP/Domain/Common/Services/Service.php index 5efc93fb..b07f3b17 100644 --- a/lib/SP/Domain/Common/Services/Service.php +++ b/lib/SP/Domain/Common/Services/Service.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. * @@ -29,10 +29,9 @@ use SP\Core\Application; use SP\Core\Context\ContextException; use SP\Core\Context\SessionContext; use SP\Core\Crypt\Session; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Events\EventDispatcherInterface; - use SP\Domain\Core\Exceptions\CryptException; use function SP\__u; @@ -47,8 +46,8 @@ abstract class Service { protected const STATUS_INTERNAL_ERROR = 1000; - protected ConfigInterface $config; - protected ContextInterface $context; + protected ConfigFileService $config; + protected ContextInterface $context; protected EventDispatcherInterface $eventDispatcher; public function __construct(Application $application) diff --git a/lib/SP/Domain/Common/Services/ServiceItemTrait.php b/lib/SP/Domain/Common/Services/ServiceItemTrait.php index b9507d8b..035aebc6 100644 --- a/lib/SP/Domain/Common/Services/ServiceItemTrait.php +++ b/lib/SP/Domain/Common/Services/ServiceItemTrait.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -28,6 +28,7 @@ namespace SP\Domain\Common\Services; * Trait ServiceItemTrait * * @package SP\Domain\Common\Services + * @deprecated */ trait ServiceItemTrait { diff --git a/lib/SP/Domain/Config/Models/Config.php b/lib/SP/Domain/Config/Models/Config.php new file mode 100644 index 00000000..bca75434 --- /dev/null +++ b/lib/SP/Domain/Config/Models/Config.php @@ -0,0 +1,46 @@ +. + */ + +namespace SP\Domain\Config\Models; + +use SP\Domain\Common\Models\Model; + +/** + * Class Config + */ +class Config extends Model +{ + protected ?string $parameter = null; + protected ?string $value = null; + + public function getParameter(): ?string + { + return $this->parameter; + } + + public function getValue(): ?string + { + return $this->value; + } +} diff --git a/lib/SP/Domain/Config/Ports/ConfigBackupServiceInterface.php b/lib/SP/Domain/Config/Ports/ConfigBackupService.php similarity index 78% rename from lib/SP/Domain/Config/Ports/ConfigBackupServiceInterface.php rename to lib/SP/Domain/Config/Ports/ConfigBackupService.php index 0a026a5b..b327053c 100644 --- a/lib/SP/Domain/Config/Ports/ConfigBackupServiceInterface.php +++ b/lib/SP/Domain/Config/Ports/ConfigBackupService.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. * @@ -28,11 +28,9 @@ use SP\Domain\Common\Services\ServiceException; use SP\Infrastructure\File\FileException; /** - * Class ConfigBackupService - * - * @package SP\Domain\Config\Services + * Interface ConfigBackupService */ -interface ConfigBackupServiceInterface +interface ConfigBackupService { /** * Backs up the config data into the database @@ -43,10 +41,10 @@ interface ConfigBackupServiceInterface * @throws FileException * @throws ServiceException */ - public function restore(ConfigInterface $config): ConfigDataInterface; + public function restore(ConfigFileService $configFile): ConfigDataInterface; /** - * @throws \SP\Domain\Common\Services\ServiceException + * @throws ServiceException */ public function getBackup(): string; } diff --git a/lib/SP/Domain/Config/Ports/ConfigInterface.php b/lib/SP/Domain/Config/Ports/ConfigFileService.php similarity index 89% rename from lib/SP/Domain/Config/Ports/ConfigInterface.php rename to lib/SP/Domain/Config/Ports/ConfigFileService.php index 228fd5f0..8a7b7255 100644 --- a/lib/SP/Domain/Config/Ports/ConfigInterface.php +++ b/lib/SP/Domain/Config/Ports/ConfigFileService.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. * @@ -30,7 +30,7 @@ use SP\Infrastructure\File\FileException; /** * Esta clase es responsable de leer y escribir la configuración del archivo config.php */ -interface ConfigInterface +interface ConfigFileService { /** * Cargar el archivo de configuración @@ -45,18 +45,18 @@ interface ConfigInterface * @param ConfigDataInterface $configData * @param bool|null $backup * - * @return ConfigInterface + * @return ConfigFileService * @throws FileException */ public function saveConfig( ConfigDataInterface $configData, ?bool $backup = true - ): ConfigInterface; + ): ConfigFileService; /** * Commits a config data */ - public function updateConfig(ConfigDataInterface $configData): ConfigInterface; + public function updateConfig(ConfigDataInterface $configData): ConfigFileService; /** * Cargar la configuración desde el contexto @@ -74,5 +74,5 @@ interface ConfigInterface * @throws FileException * @throws EnvironmentIsBrokenException */ - public function generateUpgradeKey(): ConfigInterface; + public function generateUpgradeKey(): ConfigFileService; } diff --git a/lib/SP/Domain/Config/Ports/ConfigRepositoryInterface.php b/lib/SP/Domain/Config/Ports/ConfigRepository.php similarity index 61% rename from lib/SP/Domain/Config/Ports/ConfigRepositoryInterface.php rename to lib/SP/Domain/Config/Ports/ConfigRepository.php index 4382b285..7a08d789 100644 --- a/lib/SP/Domain/Config/Ports/ConfigRepositoryInterface.php +++ b/lib/SP/Domain/Config/Ports/ConfigRepository.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,70 +24,51 @@ namespace SP\Domain\Config\Ports; - -use SP\DataModel\ConfigData; +use SP\Domain\Common\Ports\RepositoryInterface; +use SP\Domain\Config\Models\Config as ConfigModel; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Infrastructure\Database\QueryResult; /** - * Class ConfigRepository + * Interface ConfigRepository * - * @package SP\Infrastructure\Common\Repositories\Config + * @template T of ConfigModel */ -interface ConfigRepositoryInterface +interface ConfigRepository extends RepositoryInterface { /** - * @param ConfigData $configData - * - * @return bool - * @throws ConstraintException - * @throws QueryException - */ - public function update(ConfigData $configData): bool; - - /** - * @param ConfigData $configData - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function create(ConfigData $configData): int; - - /** - * Obtener un array con la configuración almacenada en la BBDD. + * @param ConfigModel $config * * @return QueryResult * @throws ConstraintException * @throws QueryException */ - public function getAll(): QueryResult; + public function update(ConfigModel $config): QueryResult; /** - * @param string $param - * + * @param ConfigModel $config * @return QueryResult * @throws ConstraintException * @throws QueryException */ + public function create(ConfigModel $config): QueryResult; + + /** + * @param string $param + * + * @return QueryResult + * @throws ConstraintException + * @throws QueryException + */ public function getByParam(string $param): QueryResult; /** - * @param string $param + * @param string $param * * @return bool * @throws ConstraintException * @throws QueryException */ public function has(string $param): bool; - - /** - * @param string $param - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function deleteByParam(string $param): int; } diff --git a/lib/SP/Domain/Config/Ports/ConfigServiceInterface.php b/lib/SP/Domain/Config/Ports/ConfigService.php similarity index 64% rename from lib/SP/Domain/Config/Ports/ConfigServiceInterface.php rename to lib/SP/Domain/Config/Ports/ConfigService.php index 3afb8595..8b8e49cd 100644 --- a/lib/SP/Domain/Config/Ports/ConfigServiceInterface.php +++ b/lib/SP/Domain/Config/Ports/ConfigService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,31 +24,29 @@ namespace SP\Domain\Config\Ports; -use SP\DataModel\ConfigData; use SP\DataModel\Dto\ConfigRequest; use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Config\Models\Config; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Infrastructure\Common\Repositories\NoSuchItemException; /** - * Class ConfigService - * - * @package SP\Domain\Config\Services + * Interface ConfigService */ -interface ConfigServiceInterface +interface ConfigService { /** * @throws NoSuchItemException * @throws ServiceException */ - public function getByParam(string $param, $default = null); + public function getByParam(string $param, $default = null): ?string; /** * @throws ConstraintException * @throws QueryException */ - public function create(ConfigData $configData): int; + public function create(Config $config): int; /** * @throws ServiceException @@ -59,21 +57,5 @@ interface ConfigServiceInterface * @throws ConstraintException * @throws QueryException */ - public function save(string $param, $value): bool; - - /** - * Obtener un array con la configuración almacenada en la BBDD. - * - * @return ConfigData[] - * @throws ConstraintException - * @throws QueryException - */ - public function getAll(): array; - - /** - * @throws ConstraintException - * @throws QueryException - * @throws NoSuchItemException - */ - public function deleteByParam(string $param): void; + public function save(string $param, string $value): bool; } diff --git a/lib/SP/Domain/Config/Services/ConfigService.php b/lib/SP/Domain/Config/Services/Config.php similarity index 57% rename from lib/SP/Domain/Config/Services/ConfigService.php rename to lib/SP/Domain/Config/Services/Config.php index 06be0476..defd8859 100644 --- a/lib/SP/Domain/Config/Services/ConfigService.php +++ b/lib/SP/Domain/Config/Services/Config.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,39 +26,40 @@ namespace SP\Domain\Config\Services; use Exception; use SP\Core\Application; -use SP\DataModel\ConfigData; use SP\DataModel\Dto\ConfigRequest; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigRepositoryInterface; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Models\Config as ConfigModel; +use SP\Domain\Config\Ports\ConfigRepository; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Infrastructure\Common\Repositories\NoSuchItemException; -use SP\Infrastructure\Config\Repositories\ConfigRepository; + +use function SP\__; +use function SP\processException; /** - * Class ConfigService - * - * @package SP\Domain\Config\Services + * Class Config */ -final class ConfigService extends Service implements ConfigServiceInterface +final class Config extends Service implements ConfigService { - private ConfigRepository $configRepository; - public function __construct(Application $application, ConfigRepositoryInterface $configRepository) + public function __construct(Application $application, private readonly ConfigRepository $configRepository) { parent::__construct($application); - - $this->configRepository = $configRepository; } /** + * @param string $param + * @param null $default + * @return string|null * @throws NoSuchItemException + * @throws SPException * @throws ServiceException */ - public function getByParam(string $param, $default = null) + public function getByParam(string $param, $default = null): ?string { try { $result = $this->configRepository->getByParam($param); @@ -73,20 +74,13 @@ final class ConfigService extends Service implements ConfigServiceInterface } - if ($result->getNumRows() === 0) { - if ($default === null) { - throw new NoSuchItemException( - sprintf(__('Parameter not found (%s)'), $param) - ); - } - - return $default; + if ($result->getNumRows() === 0 && $default === null) { + throw new NoSuchItemException( + sprintf(__('Parameter not found (%s)'), $param) + ); } - /** @var ConfigData $data */ - $data = $result->getData(); - - return empty($data->value) ? $default : $data->value; + return $result->getData(ConfigModel::class)->getValue() ?? $default; } /** @@ -97,12 +91,13 @@ final class ConfigService extends Service implements ConfigServiceInterface public function saveBatch(ConfigRequest $configRequest): void { try { - $this->transactionAware( + $this->configRepository->transactionAware( function () use ($configRequest) { foreach ($configRequest->getData() as $param => $value) { $this->save($param, $value); } - } + }, + $this ); } catch (Exception $e) { processException($e); @@ -121,47 +116,23 @@ final class ConfigService extends Service implements ConfigServiceInterface * @throws ConstraintException * @throws QueryException */ - public function save(string $param, $value): bool + public function save(string $param, string $value): bool { + $config = new ConfigModel(['parameter' => $param, 'value' => $value]); + if (!$this->configRepository->has($param)) { - return $this->configRepository->create(new ConfigData($param, $value)); + return $this->configRepository->create($config)->getLastId() > 0; } - return $this->configRepository->update(new ConfigData($param, $value)); + return $this->configRepository->update($config)->getAffectedNumRows() === 1; } /** * @throws ConstraintException * @throws QueryException */ - public function create(ConfigData $configData): int + public function create(ConfigModel $config): int { - return $this->configRepository->create($configData); - } - - /** - * Obtener un array con la configuración almacenada en la BBDD. - * - * @return ConfigData[] - * @throws ConstraintException - * @throws QueryException - */ - public function getAll(): array - { - return $this->configRepository->getAll()->getDataAsArray(); - } - - /** - * @throws ConstraintException - * @throws QueryException - * @throws NoSuchItemException - */ - public function deleteByParam(string $param): void - { - if ($this->configRepository->deleteByParam($param) === 0) { - throw new NoSuchItemException( - sprintf(__('Parameter not found (%s)'), $param) - ); - } + return $this->configRepository->create($config)->getLastId(); } } diff --git a/lib/SP/Domain/Config/Services/ConfigBackupService.php b/lib/SP/Domain/Config/Services/ConfigBackup.php similarity index 82% rename from lib/SP/Domain/Config/Services/ConfigBackupService.php rename to lib/SP/Domain/Config/Services/ConfigBackup.php index 35d03e6e..869b332c 100644 --- a/lib/SP/Domain/Config/Services/ConfigBackupService.php +++ b/lib/SP/Domain/Config/Services/ConfigBackup.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. * @@ -27,29 +27,27 @@ namespace SP\Domain\Config\Services; use Exception; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Adapters\ConfigData; -use SP\Domain\Config\Ports\ConfigBackupServiceInterface; +use SP\Domain\Config\Ports\ConfigBackupService; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\SPException; use SP\Http\JsonResponse; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Infrastructure\File\FileException; use SP\Util\Util; +use function SP\__u; use function SP\processException; /** - * Class ConfigBackupService - * - * @package SP\Domain\Config\Services + * Class ConfigBackup */ -class ConfigBackupService implements ConfigBackupServiceInterface +class ConfigBackup implements ConfigBackupService { - private ConfigService $configService; - public function __construct(ConfigService $configService) + public function __construct(private readonly ConfigService $configService) { - $this->configService = $configService; } /** @@ -82,9 +80,9 @@ class ConfigBackupService implements ConfigBackupServiceInterface * @throws FileException * @throws ServiceException */ - public function restore(ConfigInterface $config): ConfigDataInterface + public function restore(ConfigFileService $configFile): ConfigDataInterface { - return $config->saveConfig( + return $configFile->saveConfig( Util::unserialize(ConfigData::class, $this->getBackup()) )->getConfigData(); } diff --git a/lib/SP/Domain/Config/Services/ConfigFileService.php b/lib/SP/Domain/Config/Services/ConfigFile.php similarity index 85% rename from lib/SP/Domain/Config/Services/ConfigFileService.php rename to lib/SP/Domain/Config/Services/ConfigFile.php index 3844f251..e021824e 100644 --- a/lib/SP/Domain/Config/Services/ConfigFileService.php +++ b/lib/SP/Domain/Config/Services/ConfigFile.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,9 +27,9 @@ namespace SP\Domain\Config\Services; use Defuse\Crypto\Exception\EnvironmentIsBrokenException; use Exception; use SP\Domain\Config\Adapters\ConfigData; -use SP\Domain\Config\Ports\ConfigBackupServiceInterface; +use SP\Domain\Config\Ports\ConfigBackupService; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\AppInfoInterface; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Exceptions\ConfigException; @@ -45,31 +45,31 @@ use function SP\processException; defined('APP_ROOT') || die(); /** - * Esta clase es responsable de leer y escribir la configuración del archivo config.php + * Read and write the settings in the definex config file */ -class ConfigFileService implements ConfigInterface +class ConfigFile implements ConfigFileService { /** * Cache file name */ - public const CONFIG_CACHE_FILE = CACHE_PATH.DIRECTORY_SEPARATOR.'config.cache'; + public const CONFIG_CACHE_FILE = CACHE_PATH . DIRECTORY_SEPARATOR . 'config.cache'; - private static int $timeUpdated; - private static ?ConfigDataInterface $configData = null; - private bool $configLoaded = false; - private ContextInterface $context; - private XmlFileStorageInterface $fileStorage; - private FileCacheInterface $fileCache; - private ConfigBackupServiceInterface $configBackupService; + private static int $timeUpdated; + private static ?ConfigDataInterface $configData = null; + private bool $configLoaded = false; + private ContextInterface $context; + private XmlFileStorageInterface $fileStorage; + private FileCacheInterface $fileCache; + private ConfigBackupService $configBackupService; /** * @throws ConfigException */ public function __construct( XmlFileStorageInterface $fileStorage, - FileCacheInterface $fileCache, - ContextInterface $context, - ConfigBackupServiceInterface $configBackupService + FileCacheInterface $fileCache, + ContextInterface $context, + ConfigBackupService $configBackupService ) { $this->fileCache = $fileCache; $this->fileStorage = $fileStorage; @@ -159,12 +159,11 @@ class ConfigFileService implements ConfigInterface $configData = new ConfigData(); foreach ($items as $item => $value) { - $methodName = 'set'.ucfirst($item); + $methodName = 'set' . ucfirst($item); if (method_exists($configData, $methodName)) { $configData->$methodName($value); } - } return $configData; @@ -174,12 +173,12 @@ class ConfigFileService implements ConfigInterface * Guardar la configuración * * @param ConfigDataInterface $configData - * @param bool|null $backup + * @param bool|null $backup * - * @return ConfigInterface + * @return ConfigFileService * @throws FileException */ - public function saveConfig(ConfigDataInterface $configData, ?bool $backup = true): ConfigInterface + public function saveConfig(ConfigDataInterface $configData, ?bool $backup = true): ConfigFileService { if ($backup) { $this->configBackupService->backup($configData); @@ -209,7 +208,7 @@ class ConfigFileService implements ConfigInterface /** * Commits a config data */ - public function updateConfig(ConfigDataInterface $configData): ConfigInterface + public function updateConfig(ConfigDataInterface $configData): ConfigFileService { $configData->setConfigDate(time()); $configData->setConfigSaver($this->context->getUserData()->getLogin()); @@ -262,7 +261,7 @@ class ConfigFileService implements ConfigInterface * @throws FileException * @throws EnvironmentIsBrokenException */ - public function generateUpgradeKey(): ConfigInterface + public function generateUpgradeKey(): ConfigFileService { if (empty(self::$configData->getUpgradeKey())) { logger('Generating upgrade key'); diff --git a/lib/SP/Domain/Crypt/Services/MasterPassService.php b/lib/SP/Domain/Crypt/Services/MasterPassService.php index 963cee03..0f9d027e 100644 --- a/lib/SP/Domain/Crypt/Services/MasterPassService.php +++ b/lib/SP/Domain/Crypt/Services/MasterPassService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -30,8 +30,8 @@ use SP\Core\Crypt\Hash; use SP\Domain\Account\Ports\AccountCryptServiceInterface; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; -use SP\Domain\Config\Services\ConfigService; +use SP\Domain\Config\Ports\ConfigService; +use SP\Domain\Config\Services\Config; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Crypt\Ports\MasterPassServiceInterface; @@ -49,15 +49,15 @@ final class MasterPassService extends Service implements MasterPassServiceInterf public const PARAM_MASTER_PASS_TIME = 'lastupdatempass'; public const PARAM_MASTER_PASS_HASH = 'masterPwd'; - protected ConfigService $configService; + protected Config $configService; protected AccountCryptServiceInterface $accountCryptService; protected CustomFieldCryptService $customFieldCryptService; public function __construct( - Application $application, - ConfigServiceInterface $configService, - AccountCryptServiceInterface $accountCryptService, - CustomFieldCryptServiceInterface $customFieldCryptService + Application $application, + ConfigService $configService, + AccountCryptServiceInterface $accountCryptService, + CustomFieldCryptServiceInterface $customFieldCryptService ) { parent::__construct($application); diff --git a/lib/SP/Domain/Crypt/Services/TemporaryMasterPassService.php b/lib/SP/Domain/Crypt/Services/TemporaryMasterPassService.php index 2899ef6c..175e7d23 100644 --- a/lib/SP/Domain/Crypt/Services/TemporaryMasterPassService.php +++ b/lib/SP/Domain/Crypt/Services/TemporaryMasterPassService.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. * @@ -35,7 +35,7 @@ use SP\Core\Messages\MailMessage; use SP\DataModel\Dto\ConfigRequest; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\AppInfoInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -67,14 +67,14 @@ final class TemporaryMasterPassService extends Service public const PARAM_MAX_TIME = 'tempmaster_maxtime'; public const PARAM_ATTEMPTS = 'tempmaster_attempts'; - private ConfigServiceInterface $configService; - private UserServiceInterface $userService; + private ConfigService $configService; + private UserServiceInterface $userService; private MailServiceInterface $mailService; private ?int $maxTime = null; public function __construct( - Application $application, - ConfigServiceInterface $configService, + Application $application, + ConfigService $configService, UserServiceInterface $userService, MailServiceInterface $mailService ) { diff --git a/lib/SP/Domain/Export/Services/FileBackupService.php b/lib/SP/Domain/Export/Services/FileBackupService.php index d3e83d34..f74966fa 100644 --- a/lib/SP/Domain/Export/Services/FileBackupService.php +++ b/lib/SP/Domain/Export/Services/FileBackupService.php @@ -5,7 +5,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. * @@ -32,7 +32,7 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\AppInfoInterface; use SP\Domain\Core\Events\EventDispatcherInterface; use SP\Domain\Core\Exceptions\CheckException; @@ -59,7 +59,7 @@ final class FileBackupService implements FileBackupServiceInterface '#^(?:[A-Z]:)?(?:/(?!(\.git|backup|cache|temp|vendor|tests))[^/]+)+/[^/]+\.\w+$#Di'; private EventDispatcherInterface $eventDispatcher; - private ConfigInterface $config; + private ConfigFileService $config; private ConfigDataInterface $configData; private ?string $backupPath = null; diff --git a/lib/SP/Domain/Import/Services/ImportService.php b/lib/SP/Domain/Import/Services/ImportService.php index b7965a5d..87a084d3 100644 --- a/lib/SP/Domain/Import/Services/ImportService.php +++ b/lib/SP/Domain/Import/Services/ImportService.php @@ -5,7 +5,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -28,7 +28,7 @@ namespace SP\Domain\Import\Services; use Exception; use SP\Core\Application; use SP\Domain\Common\Services\Service; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Import\Ports\ImportServiceInterface; use SP\Infrastructure\Database\DatabaseInterface; @@ -54,14 +54,14 @@ final class ImportService extends Service implements ImportServiceInterface private ?ImportParams $importParams = null; private ?FileImportInterface $fileImport = null; private Application $application; - private ImportHelper $importHelper; - private ConfigServiceInterface $configService; - private DatabaseInterface $database; + private ImportHelper $importHelper; + private ConfigService $configService; + private DatabaseInterface $database; public function __construct( - Application $application, - ImportHelper $importHelper, - ConfigServiceInterface $configService, + Application $application, + ImportHelper $importHelper, + ConfigService $configService, DatabaseInterface $database ) { parent::__construct($application); diff --git a/lib/SP/Domain/Import/Services/XmlImport.php b/lib/SP/Domain/Import/Services/XmlImport.php index ab9dbb85..079481e2 100644 --- a/lib/SP/Domain/Import/Services/XmlImport.php +++ b/lib/SP/Domain/Import/Services/XmlImport.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Import\Services; use SP\Core\Application; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\SPException; defined('APP_ROOT') || die(); @@ -40,19 +40,19 @@ final class XmlImport implements XmlImportInterface { private XmlFileImport $xmlFileImport; private ImportParams $importParams; - private ImportHelper $importHelper; - private ConfigServiceInterface $configService; - private Application $application; + private ImportHelper $importHelper; + private ConfigService $configService; + private Application $application; /** * XmlImport constructor. */ public function __construct( - Application $application, - ImportHelper $importHelper, - ConfigServiceInterface $configService, - XmlFileImportInterface $xmlFileImport, - ImportParams $importParams + Application $application, + ImportHelper $importHelper, + ConfigService $configService, + XmlFileImportInterface $xmlFileImport, + ImportParams $importParams ) { $this->application = $application; $this->importHelper = $importHelper; diff --git a/lib/SP/Domain/Import/Services/XmlImportBase.php b/lib/SP/Domain/Import/Services/XmlImportBase.php index 47297910..4c6528f8 100644 --- a/lib/SP/Domain/Import/Services/XmlImportBase.php +++ b/lib/SP/Domain/Import/Services/XmlImportBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,7 +29,7 @@ use DOMElement; use SP\Core\Application; use SP\Core\Events\EventDispatcher; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\SPException; /** @@ -43,19 +43,19 @@ abstract class XmlImportBase protected XmlFileImportInterface $xmlFileImport; protected DOMDocument $xmlDOM; - protected EventDispatcher $eventDispatcher; - protected ConfigServiceInterface $configService; - protected ConfigDataInterface $configData; + protected EventDispatcher $eventDispatcher; + protected ConfigService $configService; + protected ConfigDataInterface $configData; /** * ImportBase constructor. */ public function __construct( - Application $application, - ImportHelper $importHelper, - ConfigServiceInterface $configService, + Application $application, + ImportHelper $importHelper, + ConfigService $configService, XmlFileImportInterface $xmlFileImport, - ImportParams $importParams + ImportParams $importParams ) { $this->eventDispatcher = $application->getEventDispatcher(); $this->xmlFileImport = $xmlFileImport; diff --git a/lib/SP/Domain/Install/Services/InstallerService.php b/lib/SP/Domain/Install/Services/InstallerService.php index c0425cc3..f1cdecc6 100644 --- a/lib/SP/Domain/Install/Services/InstallerService.php +++ b/lib/SP/Domain/Install/Services/InstallerService.php @@ -5,7 +5,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. * @@ -27,14 +27,14 @@ namespace SP\Domain\Install\Services; use Exception; use SP\Core\Crypt\Hash; -use SP\DataModel\ConfigData; use SP\DataModel\ProfileData; use SP\DataModel\UserData; use SP\DataModel\UserGroupData; use SP\DataModel\UserProfileData; +use SP\Domain\Config\Models\Config; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Core\Exceptions\QueryException; @@ -65,25 +65,25 @@ final class InstallerService implements InstallerServiceInterface public const VERSION_TEXT = '4.0'; public const BUILD = 21031301; - private RequestInterface $request; - private ConfigInterface $config; - private UserServiceInterface $userService; - private UserGroupServiceInterface $userGroupService; - private UserProfileServiceInterface $userProfileService; - private ConfigServiceInterface $configService; - private DatabaseConnectionData $databaseConnectionData; - private DatabaseSetupInterface $databaseSetup; - private ?InstallData $installData = null; + private RequestInterface $request; + private ConfigFileService $config; + private UserServiceInterface $userService; + private UserGroupServiceInterface $userGroupService; + private UserProfileServiceInterface $userProfileService; + private ConfigService $configService; + private DatabaseConnectionData $databaseConnectionData; + private DatabaseSetupInterface $databaseSetup; + private ?InstallData $installData = null; public function __construct( - RequestInterface $request, - ConfigInterface $config, - UserServiceInterface $userService, - UserGroupServiceInterface $userGroupService, - UserProfileServiceInterface $userProfileService, - ConfigServiceInterface $configService, - DatabaseConnectionData $databaseConnectionData, - DatabaseSetupInterface $databaseSetup + RequestInterface $request, + ConfigFileService $config, + UserServiceInterface $userService, + UserGroupServiceInterface $userGroupService, + UserProfileServiceInterface $userProfileService, + ConfigService $configService, + DatabaseConnectionData $databaseConnectionData, + DatabaseSetupInterface $databaseSetup ) { $this->request = $request; $this->config = $config; @@ -155,7 +155,8 @@ final class InstallerService implements InstallerServiceInterface } if (IS_TESTING - && empty($this->installData->getDbAdminPass())) { + && empty($this->installData->getDbAdminPass()) + ) { throw new InvalidArgumentException( __u('Please, enter the database password'), SPException::ERROR, @@ -203,7 +204,12 @@ final class InstallerService implements InstallerServiceInterface $this->saveMasterPassword(); $this->createAdminAccount(); - $this->configService->create(new ConfigData('version', VersionUtil::getVersionStringNormalized())); + $this->configService->create( + new Config([ + 'parameter' => 'version', + 'value' => VersionUtil::getVersionStringNormalized() + ]) + ); $configData->setInstalled(true); @@ -281,7 +287,7 @@ final class InstallerService implements InstallerServiceInterface } /** - * @param ConfigDataInterface $configData + * @param ConfigDataInterface $configData */ private function setupDb(ConfigDataInterface $configData): void { @@ -318,10 +324,15 @@ final class InstallerService implements InstallerServiceInterface { try { $this->configService->create( - new ConfigData('masterPwd', Hash::hashKey($this->installData->getMasterPassword())) + new Config( + [ + 'parameter' => 'masterPwd', + 'value' => Hash::hashKey($this->installData->getMasterPassword()) + ] + ) ); $this->configService->create( - new ConfigData('lastupdatempass', time()) + new Config(['parameter' => 'lastupdatempass', 'value' => time()]) ); } catch (Exception $e) { processException($e); @@ -345,12 +356,12 @@ final class InstallerService implements InstallerServiceInterface $userProfileData = new UserProfileData(['name' => 'Admin', 'profile' => new ProfileData()]); $userData = new UserData([ - 'userGroupId' => $this->userGroupService->create($userGroupData), - 'userProfileId' => $this->userProfileService->create($userProfileData), - 'login' => $this->installData->getAdminLogin(), - 'name' => 'sysPass Admin', - 'isAdminApp' => 1, - ]); + 'userGroupId' => $this->userGroupService->create($userGroupData), + 'userProfileId' => $this->userProfileService->create($userProfileData), + 'login' => $this->installData->getAdminLogin(), + 'name' => 'sysPass Admin', + 'isAdminApp' => 1, + ]); $id = $this->userService->createWithMasterPass( $userData, diff --git a/lib/SP/Domain/Upgrade/Services/UpgradeUtil.php b/lib/SP/Domain/Upgrade/Services/UpgradeUtil.php index bd00dfad..b57d3e35 100644 --- a/lib/SP/Domain/Upgrade/Services/UpgradeUtil.php +++ b/lib/SP/Domain/Upgrade/Services/UpgradeUtil.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Upgrade\Services; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Infrastructure\File\FileException; use SP\Util\VersionUtil; @@ -55,7 +55,7 @@ final class UpgradeUtil /** * @throws FileException */ - public static function fixAppUpgrade(ConfigDataInterface $configData, ConfigInterface $config): void + public static function fixAppUpgrade(ConfigDataInterface $configData, ConfigFileService $config): void { // Fixes bug in 3.0.X version where some updates weren't applied // when upgrading from v2 diff --git a/lib/SP/Domain/User/Services/UserPassService.php b/lib/SP/Domain/User/Services/UserPassService.php index 52d3c093..132d2d6e 100644 --- a/lib/SP/Domain/User/Services/UserPassService.php +++ b/lib/SP/Domain/User/Services/UserPassService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -31,8 +31,8 @@ use SP\Core\Crypt\Hash; use SP\DataModel\UserLoginData; use SP\Domain\Common\Services\Service; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigServiceInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Ports\ConfigService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -60,13 +60,13 @@ final class UserPassService extends Service implements UserPassServiceInterface public const MPASS_CHECKOLD = 4; private ConfigDataInterface $configData; - private UserRepository $userRepository; - private ConfigServiceInterface $configService; + private UserRepository $userRepository; + private ConfigService $configService; public function __construct( Application $application, UserRepositoryInterface $userRepository, - ConfigServiceInterface $configService + ConfigService $configService ) { parent::__construct($application); @@ -161,7 +161,7 @@ final class UserPassService extends Service implements UserPassServiceInterface public function makeKeyForUser(string $userLogin, string $userPass): string { // Use always the most recent config data - if (ConfigFileService::getTimeUpdated() > $this->configData->getConfigDate()) { + if (ConfigFile::getTimeUpdated() > $this->configData->getConfigDate()) { return trim($userPass.$userLogin.$this->config->getConfigData()->getPasswordSalt()); } diff --git a/lib/SP/Infrastructure/Config/Repositories/Config.php b/lib/SP/Infrastructure/Config/Repositories/Config.php new file mode 100644 index 00000000..23b5a906 --- /dev/null +++ b/lib/SP/Infrastructure/Config/Repositories/Config.php @@ -0,0 +1,129 @@ +. + */ + +namespace SP\Infrastructure\Config\Repositories; + +use SP\Domain\Config\Models\Config as ConfigModel; +use SP\Domain\Config\Ports\ConfigRepository; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Infrastructure\Common\Repositories\Repository; +use SP\Infrastructure\Database\QueryData; +use SP\Infrastructure\Database\QueryResult; + +/** + * Class Config + * + * @template T of ConfigModel + */ +final class Config extends Repository implements ConfigRepository +{ + public const TABLE = 'Config'; + + /** + * @param ConfigModel $config + * + * @return QueryResult + * @throws ConstraintException + * @throws QueryException + */ + public function update(ConfigModel $config): QueryResult + { + $query = $this->queryFactory + ->newUpdate() + ->table(self::TABLE) + ->cols($config->toArray(['value'])) + ->where('parameter = :parameter') + ->limit(1) + ->bindValues( + [ + 'value' => $config->getValue(), + 'parameter' => $config->getParameter() + ] + ); + + $queryData = QueryData::build($query); + + return $this->db->doQuery($queryData); + } + + /** + * @param ConfigModel $config + * + * @return QueryResult + * @throws ConstraintException + * @throws QueryException + */ + public function create(ConfigModel $config): QueryResult + { + $query = $this->queryFactory + ->newInsert() + ->into(self::TABLE) + ->cols($config->toArray()); + + $queryData = QueryData::build($query); + + return $this->db->doQuery($queryData); + } + + /** + * @param string $param + * + * @return QueryResult + */ + public function getByParam(string $param): QueryResult + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ConfigModel::getCols()) + ->where('parameter = :parameter') + ->bindValues(['parameter' => $param]) + ->limit(1); + + $queryData = QueryData::buildWithMapper($query, ConfigModel::class); + + return $this->db->doSelect($queryData); + } + + /** + * @param string $param + * + * @return bool + */ + public function has(string $param): bool + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ConfigModel::getCols(['value'])) + ->where('parameter = :parameter') + ->bindValues(['parameter' => $param]) + ->limit(1); + + $queryData = QueryData::build($query); + + return $this->db->doSelect($queryData)->getNumRows() === 1; + } +} diff --git a/lib/SP/Infrastructure/Config/Repositories/ConfigRepository.php b/lib/SP/Infrastructure/Config/Repositories/ConfigRepository.php deleted file mode 100644 index 263ee7e5..00000000 --- a/lib/SP/Infrastructure/Config/Repositories/ConfigRepository.php +++ /dev/null @@ -1,136 +0,0 @@ -. - */ - -namespace SP\Infrastructure\Config\Repositories; - -use SP\DataModel\ConfigData; -use SP\Domain\Config\Ports\ConfigRepositoryInterface; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\QueryException; -use SP\Infrastructure\Common\Repositories\Repository; -use SP\Infrastructure\Database\QueryData; -use SP\Infrastructure\Database\QueryResult; - -/** - * Class ConfigRepository - * - * @package SP\Infrastructure\Common\Repositories\Config - */ -final class ConfigRepository extends Repository implements ConfigRepositoryInterface -{ - /** - * @param ConfigData $configData - * - * @return bool - * @throws ConstraintException - * @throws QueryException - */ - public function update(ConfigData $configData): bool - { - $queryData = new QueryData(); - $queryData->setQuery('UPDATE Config SET `value` = ? WHERE parameter = ?'); - $queryData->setParams([$configData->getValue(), $configData->getParameter()]); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } - - /** - * @param ConfigData $configData - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function create(ConfigData $configData): int - { - $queryData = new QueryData(); - $queryData->setQuery('INSERT INTO Config SET parameter = ?, `value` = ?'); - $queryData->setParams([$configData->getParameter(), $configData->getValue()]); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } - - /** - * Obtener un array con la configuración almacenada en la BBDD. - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getAll(): QueryResult - { - $queryData = new QueryData(); - $queryData->setQuery('SELECT parameter, `value` FROM Config ORDER BY parameter'); - - return $this->db->doSelect($queryData); - } - - /** - * @param string $param - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getByParam(string $param): QueryResult - { - $queryData = new QueryData(); - $queryData->setQuery('SELECT parameter, `value` FROM Config WHERE parameter = ? LIMIT 1'); - $queryData->addParam($param); - - return $this->db->doSelect($queryData); - } - - /** - * @param string $param - * - * @return bool - * @throws ConstraintException - * @throws QueryException - */ - public function has(string $param): bool - { - $queryData = new QueryData(); - $queryData->setQuery('SELECT parameter FROM Config WHERE parameter = ? LIMIT 1'); - $queryData->addParam($param); - - return $this->db->doSelect($queryData)->getNumRows() === 1; - } - - /** - * @param string $param - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function deleteByParam(string $param): int - { - $queryData = new QueryData(); - $queryData->setQuery('DELETE FROM Config WHERE parameter = ? LIMIT 1'); - $queryData->addParam($param); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } -} diff --git a/lib/SP/Providers/Provider.php b/lib/SP/Providers/Provider.php index 9a0e1456..80f0bbb9 100644 --- a/lib/SP/Providers/Provider.php +++ b/lib/SP/Providers/Provider.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. * @@ -25,7 +25,7 @@ namespace SP\Providers; use SP\Core\Application; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Events\EventDispatcherInterface; @@ -36,8 +36,8 @@ use SP\Domain\Core\Events\EventDispatcherInterface; */ abstract class Provider implements ProviderInterface { - protected readonly ConfigInterface $config; - protected readonly ContextInterface $context; + protected readonly ConfigFileService $config; + protected readonly ContextInterface $context; protected readonly EventDispatcherInterface $eventDispatcher; protected bool $initialized = false; diff --git a/tests/SPT/Config/ConfigTest.php b/tests/SPT/Config/ConfigTest.php index e9016e8d..9a7a745e 100644 --- a/tests/SPT/Config/ConfigTest.php +++ b/tests/SPT/Config/ConfigTest.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. * @@ -31,8 +31,8 @@ use DI\NotFoundException; use PHPUnit\Framework\TestCase; use SP\Core\Context\ContextException; use SP\Domain\Config\Adapters\ConfigData; -use SP\Domain\Config\Ports\ConfigInterface; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Infrastructure\File\FileException; use function SPT\getResource; @@ -85,11 +85,11 @@ class ConfigTest extends TestCase * @throws DependencyException * @throws NotFoundException */ - public function testLoadClass(): ConfigInterface + public function testLoadClass(): ConfigFileService { - $config = self::$dic->get(ConfigFileService::class); + $config = self::$dic->get(ConfigFile::class); - $this->assertInstanceOf(ConfigFileService::class, $config); + $this->assertInstanceOf(ConfigFile::class, $config); $this->assertFileExists(CONFIG_FILE); return $config; @@ -100,11 +100,11 @@ class ConfigTest extends TestCase * * @depends testLoadClass * - * @param ConfigInterface $config + * @param ConfigFileService $config * * @throws FileException */ - public function testSaveConfig(ConfigInterface $config) + public function testSaveConfig(ConfigFileService $config) { $config->saveConfig($config->getConfigData(), false); @@ -117,9 +117,9 @@ class ConfigTest extends TestCase * * @depends testLoadClass * - * @param ConfigInterface $config + * @param ConfigFileService $config */ - public function testLoadConfig(ConfigInterface $config) + public function testLoadConfig(ConfigFileService $config) { $this->assertInstanceOf(ConfigData::class, $config->loadConfig()); } @@ -129,13 +129,13 @@ class ConfigTest extends TestCase * * @depends testLoadClass * - * @param ConfigInterface $config + * @param ConfigFileService $config */ - public function testUpdateConfig(ConfigInterface $config) + public function testUpdateConfig(ConfigFileService $config) { $config->updateConfig($config->getConfigData()); - $this->assertEquals(ConfigFileService::getTimeUpdated(), $config->getConfigData()->getConfigDate()); + $this->assertEquals(ConfigFile::getTimeUpdated(), $config->getConfigData()->getConfigDate()); } /** @@ -143,12 +143,12 @@ class ConfigTest extends TestCase * * @depends testLoadClass * - * @param ConfigInterface $config + * @param ConfigFileService $config * * @throws EnvironmentIsBrokenException * @throws FileException */ - public function testGenerateUpgradeKey(ConfigInterface $config) + public function testGenerateUpgradeKey(ConfigFileService $config) { $config->generateUpgradeKey(); diff --git a/tests/SPT/Domain/Account/Search/AccountSearchTokenizerDataTrait.php b/tests/SPT/Domain/Account/Search/AccountSearchTokenizerDataTrait.php index 649b22ab..17c15e37 100644 --- a/tests/SPT/Domain/Account/Search/AccountSearchTokenizerDataTrait.php +++ b/tests/SPT/Domain/Account/Search/AccountSearchTokenizerDataTrait.php @@ -37,7 +37,7 @@ trait AccountSearchTokenizerDataTrait $faker = Factory::create(); $id = $faker->numberBetween(1); $name = $faker->userName; - $file = sprintf('%s.%s', $faker->name(), $faker->fileExtension); + $file = sprintf('%s.%s', $faker->name(), $faker->fileExtension()); $conditions = [ sprintf('id:%d', $id), @@ -46,7 +46,7 @@ trait AccountSearchTokenizerDataTrait sprintf('file:"%s"', $file), sprintf('owner:"%s"', $name), sprintf('maingroup:"%s"', $name), - sprintf('clientService:"%s"', $name), + sprintf('client:"%s"', $name), sprintf('category:"%s"', $name), sprintf('name_regex:"^%s$"', $name), ]; @@ -64,14 +64,14 @@ trait AccountSearchTokenizerDataTrait [ implode(' ', $conditions), [ - AccountSearchConstants::FILTER_ACCOUNT_ID => $id, - AccountSearchConstants::FILTER_USER_NAME => $name, - AccountSearchConstants::FILTER_GROUP_NAME => $name, - AccountSearchConstants::FILTER_FILE_NAME => $file, - AccountSearchConstants::FILTER_OWNER => $name, - AccountSearchConstants::FILTER_MAIN_GROUP => $name, - AccountSearchConstants::FILTER_CLIENT_NAME => $name, - AccountSearchConstants::FILTER_CATEGORY_NAME => $name, + AccountSearchConstants::FILTER_ACCOUNT_ID => $id, + AccountSearchConstants::FILTER_USER_NAME => $name, + AccountSearchConstants::FILTER_GROUP_NAME => $name, + AccountSearchConstants::FILTER_FILE_NAME => $file, + AccountSearchConstants::FILTER_OWNER => $name, + AccountSearchConstants::FILTER_MAIN_GROUP => $name, + AccountSearchConstants::FILTER_CLIENT_NAME => $name, + AccountSearchConstants::FILTER_CATEGORY_NAME => $name, AccountSearchConstants::FILTER_ACCOUNT_NAME_REGEX => sprintf('^%s$', $name), ], ], @@ -97,8 +97,8 @@ trait AccountSearchTokenizerDataTrait { $conditions = [ 'test string' => null, - 'op:and' => 'and', - 'op:or' => 'or', + 'op:and' => 'and', + 'op:or' => 'or', ]; return [ @@ -116,9 +116,9 @@ trait AccountSearchTokenizerDataTrait $faker->streetAddress, $faker->name, $faker->userName, - $faker->catchPhrase, + $faker->sentence, $faker->ipv4, - $faker->bankAccountNumber, + $faker->iban, $faker->companyEmail, $faker->domainName, ]; diff --git a/tests/SPT/Domain/Account/Services/AccountSearchServiceTest.php b/tests/SPT/Domain/Account/Services/AccountSearchServiceTest.php index b1b286ca..6739ed51 100644 --- a/tests/SPT/Domain/Account/Services/AccountSearchServiceTest.php +++ b/tests/SPT/Domain/Account/Services/AccountSearchServiceTest.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. * @@ -207,7 +207,7 @@ class AccountSearchServiceTest extends UnitaryTestCase $this->accountSearchService->getByFilter($accountSearchFilter); } - private function buildExpectationForCondition(string $condition) + private function buildExpectationForCondition(string $condition): void { switch ($condition) { case AccountSearchConstants::FILTER_IS_EXPIRED: @@ -241,17 +241,21 @@ class AccountSearchServiceTest extends UnitaryTestCase $userService = $this->createMock(UserServiceInterface::class); $userService ->method('getByLogin') - ->willReturn(new UserData([ - 'id' => self::$faker->randomNumber(), - 'userGroupId' => self::$faker->randomNumber(), - ])); + ->willReturn( + new UserData([ + 'id' => self::$faker->randomNumber(), + 'userGroupId' => self::$faker->randomNumber(), + ]) + ); $userGroupService = $this->createMock(UserGroupServiceInterface::class); $userGroupService ->method('getByName') - ->willReturn(new UserGroupData([ - 'id' => self::$faker->randomNumber(), - ])); + ->willReturn( + new UserGroupData([ + 'id' => self::$faker->randomNumber(), + ]) + ); $this->accountSearchRepository = $this->createMock(AccountSearchRepositoryInterface::class); $this->accountSearchDataBuilder = $this->createMock(AccountSearchDataBuilderInterface::class); @@ -264,5 +268,4 @@ class AccountSearchServiceTest extends UnitaryTestCase $this->accountSearchDataBuilder ); } - } diff --git a/tests/SPT/Domain/Account/Services/AccountServiceTest.php b/tests/SPT/Domain/Account/Services/AccountServiceTest.php index d3be716c..7ffc5f13 100644 --- a/tests/SPT/Domain/Account/Services/AccountServiceTest.php +++ b/tests/SPT/Domain/Account/Services/AccountServiceTest.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. * @@ -44,7 +44,7 @@ use SP\Domain\Account\Ports\AccountToUserRepositoryInterface; use SP\Domain\Account\Services\AccountService; use SP\Domain\Common\Models\Simple; use SP\Domain\Common\Services\ServiceException; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -70,7 +70,7 @@ class AccountServiceTest extends UnitaryTestCase private AccountToTagRepositoryInterface|MockObject $accountToTagRepository; private ItemPresetServiceInterface|MockObject $itemPresetService; private AccountHistoryServiceInterface|MockObject $accountHistoryService; - private ConfigServiceInterface|MockObject $configService; + private ConfigService|MockObject $configService; private AccountCryptServiceInterface|MockObject $accountCryptService; private AccountPresetServiceInterface|MockObject $accountPresetService; private AccountItemsServiceInterface|MockObject $accountItemsService; @@ -1332,7 +1332,7 @@ class AccountServiceTest extends UnitaryTestCase $this->accountToTagRepository = $this->createMock(AccountToTagRepositoryInterface::class); $this->itemPresetService = $this->createMock(ItemPresetServiceInterface::class); $this->accountHistoryService = $this->createMock(AccountHistoryServiceInterface::class); - $this->configService = $this->createMock(ConfigServiceInterface::class); + $this->configService = $this->createMock(ConfigService::class); $this->accountCryptService = $this->createMock(AccountCryptServiceInterface::class); $this->accountItemsService = $this->createMock(AccountItemsServiceInterface::class); $this->accountPresetService = $this->createMock(AccountPresetServiceInterface::class); diff --git a/tests/SPT/Domain/Config/Services/ConfigBackupTest.php b/tests/SPT/Domain/Config/Services/ConfigBackupTest.php new file mode 100644 index 00000000..3e31f23c --- /dev/null +++ b/tests/SPT/Domain/Config/Services/ConfigBackupTest.php @@ -0,0 +1,222 @@ +. + */ + +namespace SPT\Domain\Config\Services; + +use PHPUnit\Framework\MockObject\Exception; +use PHPUnit\Framework\MockObject\MockObject; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Config\Adapters\ConfigData; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Config\Ports\ConfigService; +use SP\Domain\Config\Services\ConfigBackup; +use SP\Domain\Core\Exceptions\SPException; +use SP\Infrastructure\Common\Repositories\NoSuchItemException; +use SP\Infrastructure\File\FileException; +use SPT\UnitaryTestCase; + +/** + * Class ConfigBackupTest + * + * @group unitary + */ +class ConfigBackupTest extends UnitaryTestCase +{ + + private ConfigService|MockObject $configService; + private ConfigBackup $configBackupService; + + public function testBackup() + { + $this->configService + ->expects(self::exactly(2)) + ->method('save') + ->with( + ... + self::withConsecutive( + ['config_backup', self::isType('string')], + ['config_backup_date', self::isType('string')] + ) + ); + + $this->configBackupService->backup($this->config->getConfigData()); + } + + public function testBackupError() + { + $this->configService + ->expects(self::once()) + ->method('save') + ->with('config_backup', self::anything()) + ->willThrowException(new SPException('test')); + + $this->configBackupService->backup($this->config->getConfigData()); + } + + /** + * @throws Exception + * @throws ServiceException + * @throws FileException + */ + public function testRestore() + { + $configData = new ConfigData(); + + $configFile = $this->createMock(ConfigFileService::class); + + $configFile->expects(self::once()) + ->method('saveConfig') + ->with($configData) + ->willReturn($configFile); + + $hexConfigData = bin2hex(gzcompress(serialize($configData))); + + $this->configService->expects(self::once()) + ->method('getByParam') + ->with('config_backup') + ->willReturn($hexConfigData); + + $configFile->expects(self::once()) + ->method('getConfigData') + ->willReturn($configData); + + $out = $this->configBackupService->restore($configFile); + + $this->assertEquals($configData, $out); + } + + /** + * @throws Exception + * @throws ServiceException + * @throws FileException + */ + public function testRestoreWithNullData() + { + $configFile = $this->createMock(ConfigFileService::class); + + $configFile->expects(self::never()) + ->method('saveConfig'); + + $this->configService->expects(self::once()) + ->method('getByParam') + ->with('config_backup') + ->willReturn(null); + + $configFile->expects(self::never()) + ->method('getConfigData'); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Unable to restore the configuration'); + + $this->configBackupService->restore($configFile); + } + + /** + * @throws Exception + * @throws ServiceException + * @throws FileException + */ + public function testRestoreWithMissingParam() + { + $configFile = $this->createMock(ConfigFileService::class); + + $configFile->expects(self::never()) + ->method('saveConfig'); + + $this->configService->expects(self::once()) + ->method('getByParam') + ->willThrowException(new NoSuchItemException('test')); + + $configFile->expects(self::never()) + ->method('getConfigData'); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Unable to restore the configuration'); + + $this->configBackupService->restore($configFile); + } + + /** + * @throws SPException + */ + public function testConfigToJson() + { + $this->assertNotEmpty(ConfigBackup::configToJson(serialize($this->config->getConfigData()))); + } + + /** + * @throws ServiceException + */ + public function testGetBackup() + { + $configData = new ConfigData(); + + $hexConfigData = bin2hex(gzcompress(serialize($configData))); + + $this->configService->expects(self::once()) + ->method('getByParam') + ->with('config_backup') + ->willReturn($hexConfigData); + + $out = unserialize($this->configBackupService->getBackup()); + + $this->assertEquals($configData, $out); + } + + public function testGetBackupWithNullData() + { + $this->configService->expects(self::once()) + ->method('getByParam') + ->with('config_backup') + ->willReturn(null); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Unable to restore the configuration'); + + $this->configBackupService->getBackup(); + } + + public function testGetBackupWithMissingParam() + { + $this->configService->expects(self::once()) + ->method('getByParam') + ->willThrowException(new NoSuchItemException('test')); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Unable to restore the configuration'); + + $this->configBackupService->getBackup(); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->configService = $this->createMock(ConfigService::class); + + $this->configBackupService = new ConfigBackup($this->configService); + } + + +} diff --git a/tests/SPT/Domain/Config/Services/ConfigTest.php b/tests/SPT/Domain/Config/Services/ConfigTest.php new file mode 100644 index 00000000..6a8cdd93 --- /dev/null +++ b/tests/SPT/Domain/Config/Services/ConfigTest.php @@ -0,0 +1,286 @@ +. + */ + +namespace SPT\Domain\Config\Services; + +use PHPUnit\Framework\Constraint\Callback; +use PHPUnit\Framework\MockObject\MockObject; +use RuntimeException; +use SP\DataModel\Dto\ConfigRequest; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Config\Ports\ConfigRepository; +use SP\Domain\Config\Services\Config; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Core\Exceptions\SPException; +use SP\Infrastructure\Common\Repositories\NoSuchItemException; +use SP\Infrastructure\Database\QueryResult; +use SPT\Generators\ConfigGenerator; +use SPT\UnitaryTestCase; + +/** + * Class ConfigTest + * + * @group unitary + */ +class ConfigTest extends UnitaryTestCase +{ + + private MockObject|ConfigRepository $configRepository; + private Config $configService; + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testCreate() + { + $config = ConfigGenerator::factory()->buildConfig(); + + $queryResult = new QueryResult(); + $queryResult->setLastId(self::$faker->randomNumber()); + + $this->configRepository + ->expects(self::once()) + ->method('create') + ->with($config) + ->willReturn($queryResult); + + $out = $this->configService->create($config); + + $this->assertEquals($queryResult->getLastId(), $out); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testSaveWithNoExistingParameter() + { + $config = ConfigGenerator::factory()->buildConfig(); + + $this->configRepository + ->expects(self::once()) + ->method('has') + ->with($config->getParameter()) + ->willReturn(false); + + $queryResult = new QueryResult(); + $queryResult->setLastId(self::$faker->randomNumber()); + + $this->configRepository + ->expects(self::once()) + ->method('create') + ->with($config) + ->willReturn($queryResult); + + $this->configService->save($config->getParameter(), $config->getValue()); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testSaveWithExistingParameter() + { + $config = ConfigGenerator::factory()->buildConfig(); + + $this->configRepository + ->expects(self::once()) + ->method('has') + ->with($config->getParameter()) + ->willReturn(true); + + $this->configRepository + ->expects(self::once()) + ->method('update') + ->with($config) + ->willReturn(new QueryResult([1])); + + $this->configService->save($config->getParameter(), $config->getValue()); + } + + /** + * @throws NoSuchItemException + * @throws ServiceException + * @throws SPException + */ + public function testGetByParam() + { + $parameter = self::$faker->colorName(); + + $config = ConfigGenerator::factory()->buildConfig(); + + $this->configRepository + ->expects(self::once()) + ->method('getByParam') + ->with($parameter) + ->willReturn(new QueryResult([$config])); + + $out = $this->configService->getByParam($parameter); + + $this->assertEquals($config->getValue(), $out); + } + + /** + * @throws NoSuchItemException + * @throws ServiceException + * @throws SPException + */ + public function testGetByParamWithDefaultValue() + { + $parameter = self::$faker->colorName(); + + $config = ConfigGenerator::factory()->buildConfig()->mutate(['value' => null]); + + $this->configRepository + ->expects(self::once()) + ->method('getByParam') + ->with($parameter) + ->willReturn(new QueryResult([$config])); + + $out = $this->configService->getByParam($parameter, 'test'); + + $this->assertEquals('test', $out); + } + + /** + * @throws NoSuchItemException + * @throws ServiceException + * @throws SPException + */ + public function testGetByParamWithNoFound() + { + $parameter = self::$faker->colorName(); + + $this->configRepository + ->expects(self::once()) + ->method('getByParam') + ->with($parameter) + ->willReturn(new QueryResult([])); + + $this->expectException(NoSuchItemException::class); + $this->expectExceptionMessage(sprintf('Parameter not found (%s)', $parameter)); + + $this->configService->getByParam($parameter); + } + + /** + * @throws NoSuchItemException + * @throws ServiceException + * @throws SPException + */ + public function testGetByParamWithException() + { + $parameter = self::$faker->colorName(); + + $this->configRepository + ->expects(self::once()) + ->method('getByParam') + ->with($parameter) + ->willThrowException(new RuntimeException('test')); + + $this->expectException(SPException::class); + $this->expectExceptionMessage('test'); + + $this->configService->getByParam($parameter); + } + + /** + * @throws ServiceException + */ + public function testSaveBatch() + { + $this->configRepository + ->expects(self::once()) + ->method('transactionAware') + ->with( + new Callback(function (callable $closure) { + $closure(); + + return true; + }) + ); + + $this->configRepository + ->expects(self::exactly(3)) + ->method('has') + ->with(self::anything()) + ->willReturn(true); + + $this->configRepository + ->expects(self::exactly(3)) + ->method('update') + ->with(self::anything()) + ->willReturn(new QueryResult([1])); + + $configRequest = new ConfigRequest(); + $configRequest->add(self::$faker->colorName, self::$faker->text); + $configRequest->add(self::$faker->colorName, self::$faker->text); + $configRequest->add(self::$faker->colorName, self::$faker->text); + + $this->configService->saveBatch($configRequest); + } + + /** + * @throws ServiceException + */ + public function testSaveBatchWithException() + { + $this->configRepository + ->expects(self::once()) + ->method('transactionAware') + ->with(self::anything()) + ->willThrowException(new RuntimeException('test')); + + $this->configRepository + ->expects(self::never()) + ->method('has') + ->with(self::anything()); + + $this->configRepository + ->expects(self::never()) + ->method('update') + ->with(self::anything()); + + $configRequest = new ConfigRequest(); + $configRequest->add(self::$faker->colorName, self::$faker->text); + $configRequest->add(self::$faker->colorName, self::$faker->text); + $configRequest->add(self::$faker->colorName, self::$faker->text); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('test'); + + $this->configService->saveBatch($configRequest); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->configRepository = $this->createMock(ConfigRepository::class); + + $this->configService = new Config($this->application, $this->configRepository); + } +} diff --git a/tests/SPT/Domain/Install/Services/InstallerTest.php b/tests/SPT/Domain/Install/Services/InstallerTest.php index 9c62fe20..0c3b324d 100644 --- a/tests/SPT/Domain/Install/Services/InstallerTest.php +++ b/tests/SPT/Domain/Install/Services/InstallerTest.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. * @@ -27,7 +27,7 @@ namespace SPT\Domain\Install\Services; use Exception; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Stub; -use SP\Domain\Config\Ports\ConfigServiceInterface; +use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\RequestInterface; @@ -63,7 +63,7 @@ class InstallerTest extends UnitaryTestCase */ private $request; /** - * @var MockObject|ConfigServiceInterface + * @var MockObject|ConfigService */ private $configService; /** @@ -440,7 +440,7 @@ class InstallerTest extends UnitaryTestCase $this->databaseSetup = $this->createMock(DatabaseSetupInterface::class); $this->userService = $this->createMock(UserServiceInterface::class); $this->request = $this->createStub(RequestInterface::class); - $this->configService = $this->createMock(ConfigServiceInterface::class); + $this->configService = $this->createMock(ConfigService::class); $this->userGroupService = $this->createMock(UserGroupServiceInterface::class); $this->userProfileService = $this->createMock(UserProfileServiceInterface::class); diff --git a/tests/SPT/Generators/ConfigGenerator.php b/tests/SPT/Generators/ConfigGenerator.php new file mode 100644 index 00000000..6fef1896 --- /dev/null +++ b/tests/SPT/Generators/ConfigGenerator.php @@ -0,0 +1,47 @@ +. + */ + +namespace SPT\Generators; + +use SP\Domain\Config\Models\Config; + +/** + * Class ConfigGenerator + */ +final class ConfigGenerator extends DataGenerator +{ + + public function buildConfig(): Config + { + return new Config($this->configProperties()); + } + + private function configProperties(): array + { + return [ + 'parameter' => $this->faker->colorName(), + 'value' => $this->faker->text() + ]; + } +} diff --git a/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php b/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php index 2b7186b6..22391029 100644 --- a/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php +++ b/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php @@ -81,7 +81,7 @@ class ClientRepositoryTest extends UnitaryTestCase } ); - $callbackUpdate = new Callback( + $callbackCreate = new Callback( static function (QueryData $arg) use ($client) { $query = $arg->getQuery(); $params = $query->getBindValues(); @@ -99,7 +99,7 @@ class ClientRepositoryTest extends UnitaryTestCase $this->database ->expects(self::exactly(2)) ->method('doQuery') - ->with(...self::withConsecutive([$callbackDuplicate], [$callbackUpdate])) + ->with(...self::withConsecutive([$callbackDuplicate], [$callbackCreate])) ->willReturn(new QueryResult([]), new QueryResult([1])); $this->clientRepository->create($client); diff --git a/tests/SPT/Infrastructure/Config/Repositories/ConfigTest.php b/tests/SPT/Infrastructure/Config/Repositories/ConfigTest.php new file mode 100644 index 00000000..4d9c0cae --- /dev/null +++ b/tests/SPT/Infrastructure/Config/Repositories/ConfigTest.php @@ -0,0 +1,185 @@ +. + */ + +namespace SPT\Infrastructure\Config\Repositories; + +use Aura\SqlQuery\Common\InsertInterface; +use Aura\SqlQuery\Common\SelectInterface; +use Aura\SqlQuery\Common\UpdateInterface; +use Aura\SqlQuery\QueryFactory; +use PHPUnit\Framework\Constraint\Callback; +use SP\Domain\Common\Models\Simple; +use SP\Domain\Config\Models\Config as ConfigModel; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Infrastructure\Config\Repositories\Config; +use SP\Infrastructure\Database\DatabaseInterface; +use SP\Infrastructure\Database\QueryData; +use SP\Infrastructure\Database\QueryResult; +use SPT\Generators\ConfigGenerator; +use SPT\UnitaryTestCase; + +/** + * Class ConfigTest + * + * @group unitary + */ +class ConfigTest extends UnitaryTestCase +{ + private Config $configRepository; + + public function testGetByParam() + { + $param = self::$faker->colorName(); + + $callback = new Callback( + static function (QueryData $arg) use ($param) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 1 + && $params['parameter'] === $param + && $arg->getMapClassName() === ConfigModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback); + + $this->configRepository->getByParam($param); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testCreate() + { + $config = ConfigGenerator::factory()->buildConfig(); + + $callback = new Callback( + static function (QueryData $arg) use ($config) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 2 + && $params['parameter'] === $config->getParameter() + && $params['value'] === $config->getValue() + && is_a($query, InsertInterface::class) + && !empty($query->getStatement()); + } + ); + + $queryResult = new QueryResult([1]); + + $this->database + ->expects(self::exactly(1)) + ->method('doQuery') + ->with($callback) + ->willReturn($queryResult); + + $out = $this->configRepository->create($config); + + $this->assertEquals($queryResult, $out); + } + + public function testHas() + { + $param = self::$faker->colorName(); + + $callback = new Callback( + static function (QueryData $arg) use ($param) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 1 + && $params['parameter'] === $param + && $arg->getMapClassName() === Simple::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback) + ->willReturn(new QueryResult([1])); + + $this->assertTrue($this->configRepository->has($param)); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testUpdate() + { + $config = ConfigGenerator::factory()->buildConfig(); + + $callback = new Callback( + static function (QueryData $arg) use ($config) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 2 + && $params['parameter'] === $config->getParameter() + && $params['value'] === $config->getValue() + && is_a($query, UpdateInterface::class) + && !empty($query->getStatement()); + } + ); + + $queryResult = new QueryResult([1]); + + $this->database + ->expects(self::exactly(1)) + ->method('doQuery') + ->with($callback) + ->willReturn($queryResult); + + $out = $this->configRepository->update($config); + + $this->assertEquals($queryResult, $out); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->database = $this->createMock(DatabaseInterface::class); + $queryFactory = new QueryFactory('mysql'); + + $this->configRepository = new Config( + $this->database, + $this->context, + $this->application->getEventDispatcher(), + $queryFactory, + ); + } +} diff --git a/tests/SPT/Modules/Api/ApiTestCase.php b/tests/SPT/Modules/Api/ApiTestCase.php index 1da32547..e9347afd 100644 --- a/tests/SPT/Modules/Api/ApiTestCase.php +++ b/tests/SPT/Modules/Api/ApiTestCase.php @@ -42,7 +42,7 @@ use SP\Domain\Api\Services\ApiRequest; use SP\Domain\Auth\Models\AuthToken; use SP\Domain\Auth\Services\AuthToken; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Exceptions\ConstraintException; @@ -166,7 +166,9 @@ abstract class ApiTestCase extends TestCase }, DbStorageInterface::class => create(MysqlHandler::class) ->constructor($databaseConnectionData), - ConfigDataInterface::class => static function (ConfigInterface $config) use ($databaseConnectionData) { + ConfigDataInterface::class => static function (ConfigFileService $config) use ( + $databaseConnectionData + ) { $configData = $config->getConfigData() ->setDbHost($databaseConnectionData->getDbHost()) ->setDbName($databaseConnectionData->getDbName()) diff --git a/tests/SPT/Modules/Cli/Commands/BackupCommandTest.php b/tests/SPT/Modules/Cli/Commands/BackupCommandTest.php index 8cb8aae4..e7a20cff 100644 --- a/tests/SPT/Modules/Cli/Commands/BackupCommandTest.php +++ b/tests/SPT/Modules/Cli/Commands/BackupCommandTest.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. * @@ -26,7 +26,7 @@ namespace SPT\Modules\Cli\Commands; use DI\DependencyException; use DI\NotFoundException; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Domain\Core\Exceptions\FileNotFoundException; use SP\Domain\Export\Services\BackupFiles; use SP\Modules\Cli\Commands\BackupCommand; @@ -94,7 +94,7 @@ class BackupCommandTest extends CliTestCase private function checkBackupFilesAreCreated(): void { - $configData = self::$dic->get(ConfigFileService::class)->getConfigData(); + $configData = self::$dic->get(ConfigFile::class)->getConfigData(); $this->assertFileExists( BackupFiles::getAppBackupFilename( diff --git a/tests/SPT/Modules/Cli/Commands/InstallCommandTest.php b/tests/SPT/Modules/Cli/Commands/InstallCommandTest.php index 3ef39cb6..27ef55b6 100644 --- a/tests/SPT/Modules/Cli/Commands/InstallCommandTest.php +++ b/tests/SPT/Modules/Cli/Commands/InstallCommandTest.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. * @@ -27,7 +27,7 @@ namespace SPT\Modules\Cli\Commands; use DI\DependencyException; use DI\NotFoundException; use Exception; -use SP\Domain\Config\Services\ConfigFileService; +use SP\Domain\Config\Services\ConfigFile; use SP\Infrastructure\Database\DatabaseException; use SP\Modules\Cli\Commands\InstallCommand; use SPT\DatabaseUtil; @@ -188,7 +188,7 @@ class InstallCommandTest extends CliTestCase $output = $commandTester->getDisplay(); $this->assertStringContainsString('Installation finished', $output); - $configData = self::$dic->get(ConfigFileService::class)->getConfigData(); + $configData = self::$dic->get(ConfigFile::class)->getConfigData(); // Cleanup database DatabaseUtil::dropDatabase(self::$commandInputData['databaseName']); @@ -222,7 +222,7 @@ class InstallCommandTest extends CliTestCase $output = $commandTester->getDisplay(); $this->assertStringContainsString('Installation finished', $output); - $configData = self::$dic->get(ConfigFileService::class)->getConfigData(); + $configData = self::$dic->get(ConfigFile::class)->getConfigData(); $this->assertEquals($configData->getSiteLang(), $inputData['--language']); @@ -269,7 +269,7 @@ class InstallCommandTest extends CliTestCase $output = $commandTester->getDisplay(); $this->assertStringContainsString('Installation finished', $output); - $configData = self::$dic->get(ConfigFileService::class)->getConfigData(); + $configData = self::$dic->get(ConfigFile::class)->getConfigData(); $this->assertEquals($configData->getDbUser(), $databaseUser); $this->assertEquals($configData->getDbPass(), $databasePassword); diff --git a/tests/SPT/UnitaryTestCase.php b/tests/SPT/UnitaryTestCase.php index afcc9783..8feae6ce 100644 --- a/tests/SPT/UnitaryTestCase.php +++ b/tests/SPT/UnitaryTestCase.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. * @@ -32,7 +32,7 @@ use SP\Core\Application; use SP\Core\Context\ContextException; use SP\Core\Context\StatelessContext; use SP\DataModel\ProfileData; -use SP\Domain\Config\Ports\ConfigInterface; +use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Context\ContextInterface; use SP\Domain\Core\Events\EventDispatcherInterface; use SP\Domain\User\Services\UserLoginResponse; @@ -45,9 +45,9 @@ abstract class UnitaryTestCase extends TestCase { use PHPUnitHelper; - protected static Generator $faker; - protected ConfigInterface $config; - protected Application $application; + protected static Generator $faker; + protected ConfigFileService $config; + protected Application $application; protected ContextInterface $context; public static function setUpBeforeClass(): void @@ -94,7 +94,7 @@ abstract class UnitaryTestCase extends TestCase $configData = ConfigDataGenerator::factory()->buildConfigData(); - $config = $this->createStub(ConfigInterface::class); + $config = $this->createStub(ConfigFileService::class); $config->method('getConfigData')->willReturn($configData); return new Application(