diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000000000000000000000000000000000..ab448556cc6009a00c2a58e79383ed0d833100a6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,57 @@ +name: Test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + + +jobs: + test-74: + runs-on: ubuntu-latest + container: + image: cicnavi/dap:74 + steps: + - uses: actions/checkout@v3 + - name: Validate composer.json and composer.lock + run: composer validate + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-${{ job.container.id }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-${{ job.container.id }}-php- + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + - name: Run test suite + run: composer run-script pre-commit + - name: Show PHP version + run: php -v + + test-latest: + runs-on: ubuntu-latest + container: + image: cicnavi/dap:08 + steps: + - uses: actions/checkout@v3 + - name: Validate composer.json and composer.lock + run: composer validate + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-${{ job.container.id }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-${{ job.container.id }}-php- + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + - name: Run test suite + run: composer run-script pre-commit + - name: Show PHP version + run: php -v \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..e50b5fbcf24142aed3b06bad6f59e1e0f93cefe2 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,29 @@ + +# Composer stores all downloaded packages in the vendor/ directory. +# Do not use the following if the vendor/ directory is committed to +# your git repository. +cache: + # We key the cache using the commit unique identifier. + key: ${CI_COMMIT_REF_SLUG} + paths: + - vendor/ + +# List of stages for jobs, and their order of execution +stages: + - test + +# PHP v7.4 +test-74: + stage: test + image: cicnavi/dap:74 + script: + - composer install --prefer-dist --no-progress --no-suggest + - composer run-script pre-commit + +# PHP latest +test-08: + stage: test + image: cicnavi/dap:08 + script: + - composer install --prefer-dist --no-progress --no-suggest + - composer run-script pre-commit diff --git a/README.md b/README.md index c623a6fee7ee27d21cfc5f3bc75bade6f02a0852..c37884dc22d503ccab57f5387cda2c438160d2ab 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[](https://github.com/cicnavi/simplesamlphp-module-accounting/actions/workflows/test.yml) + # simplesamlphp-module-accounting SimpleSAMLphp module providing user accounting functionality using SimpleSAMLphp authentication processing filters feature. @@ -32,6 +34,17 @@ Module is installable using Composer: composer require cicnavi/simplesamlphp-module-accounting ``` +In config.php, search for the "module.enable" key and set 'accounting' to true: + +```php +// ... +'module.enable' => [ + 'accounting' => true, + // ... +], +// ... +``` + Depending on used features, module also requires: - ext-redis: if PhpRedis is to be used as a store @@ -112,6 +125,19 @@ in config/config.php: ], // ... ``` +## Job Runner +If accounting processing is asynchronous, a job runner will have to be used in order to process jobs that have +been created during authentication events. + +Job runner can be executed using [SimpleSAMLphp Cron module](https://github.com/simplesamlphp/simplesamlphp/blob/master/modules/cron/docs/cron.md). +As you can see in Cron documentation, a cron tag can be invoked using HTTP or CLI. When it comes to Job Runner, using +CLI is the preferred way, since the job runner can run in a long-running fashion, even indefinitely. However, +you are free to test execution using the HTTP version, in which case the maximum job runner execution time +will correspond to the 'max_execution_time' INI setting. + +Only one job runner instance can run at given point in time. By maintaining internal state, job runner can first check +if there is another job runner active. If yes, the latter will simply exit and let the active job runner do its work. +This way one is free to invoke the cron tag at any time, since only one job runner will ever be active. ## TODO - [ ] Translation diff --git a/bin/test.php b/bin/test.php deleted file mode 100644 index cf32aff522b2369015f7b4d50e3a40ccb8406181..0000000000000000000000000000000000000000 --- a/bin/test.php +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env php -<?php -// TODO mivanci remove this file before release -declare(strict_types=1); - -use SimpleSAML\Module\accounting\Entities\Authentication\Event; -use SimpleSAML\Module\accounting\Entities\Authentication\Event\Job; -use SimpleSAML\Module\accounting\Entities\Authentication\State; -use SimpleSAML\Module\accounting\Services\HelpersManager; -use SimpleSAML\Module\accounting\Services\Logger; -use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; -use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store\Repository; -use SimpleSAML\Module\accounting\Stores\Jobs\PhpRedis\RedisStore; - -require 'vendor/autoload.php'; - -$helpersManager = new HelpersManager(); - -$start = new DateTime(); - -$newLine = "\n"; - -echo "Start: " . $start->format(DateTime::ATOM); -echo $newLine; - -$job = new Job(new Event(new State(SimpleSAML\Test\Module\accounting\Constants\StateArrays::FULL))); - -$options = getopt('c:'); - -$numberOfItems = $options['c'] ?? 1000; - -echo 'Number of items: ' . $numberOfItems; -echo $newLine; - -$spinnerChars = ['|', '/', '-', '\\']; - -/**/ -echo 'Starting simulating MySQL: '; -$mysqlStartTime = new DateTime(); -echo $mysqlStartTime->format(DateTime::ATOM); -echo $newLine; - -$mysqlParameters = [ - 'driver' => 'pdo_mysql', // (string): The built-in driver implementation to use - 'user' => 'apps', // (string): Username to use when connecting to the database. - 'password' => 'apps', // (string): Password to use when connecting to the database. - 'host' => '127.0.0.1', // (string): Hostname of the database to connect to. - 'port' => 33306, // (integer): Port of the database to connect to. - 'dbname' => 'accounting', // (string): Name of the database/schema to connect to. - //'unix_socket' => 'unix_socet', // (string): Name of the socket used to connect to the database. - 'charset' => 'utf8', // (string): The charset used when connecting to the database. - //'url' => 'mysql://user:secret@localhost/mydb?charset=utf8', // ...alternative way of providing parameters. - // Additional parameters not originally avaliable in Doctrine DBAL - 'table_prefix' => '', // (string): Prefix for each table. -]; - -$logger = new Logger(); - -$jobsStoreRepository = new Repository(new Connection($mysqlParameters), 'job', $logger); -$mysqlDurationInSeconds = (new DateTime())->getTimestamp() - $mysqlStartTime->getTimestamp(); -$mysqlItemsInCurrentSecond = 0; -$mysqlItemsPerSecond = []; -for ($i = 1; $i <= $numberOfItems; $i++) { - $mysqlUpdatedDurationInSeconds = (new DateTime())->getTimestamp() - $mysqlStartTime->getTimestamp(); - if ($mysqlDurationInSeconds === $mysqlUpdatedDurationInSeconds) { - $mysqlItemsInCurrentSecond++; - } else { - $mysqlItemsPerSecond[] = $mysqlItemsInCurrentSecond; - $mysqlItemsInCurrentSecond = 0; - } - $mysqlItemsInCurrentSecond = $mysqlDurationInSeconds === $mysqlUpdatedDurationInSeconds ? - $mysqlItemsInCurrentSecond++ : 0; - $mysqlDurationInSeconds = (new DateTime())->getTimestamp() - $mysqlStartTime->getTimestamp(); - - $mysqlItemsPerSeconds = count($mysqlItemsPerSecond) ? - array_sum($mysqlItemsPerSecond) / count($mysqlItemsPerSecond) : 0; - $mysqlPercentage = $i / $numberOfItems * 100; - $spinnerChar = $spinnerChars[array_rand($spinnerChars)]; - $line = sprintf( - '%1$s percentage: %2$ 3d%%, items/s: %3$04d, duration: %4$ss', - $spinnerChar, $mysqlPercentage, $mysqlItemsPerSeconds, $mysqlDurationInSeconds - ); - echo $line; - echo "\r"; - $jobsStoreRepository->insert($job); -} -echo $newLine; -echo $newLine; - - -echo 'Starting simulating Redis: '; -$redisStartTime = new DateTime(); -echo $redisStartTime->format(DateTime::ATOM); -echo $newLine; - -$redisClient = new Redis(); -$redisClient->connect( - '127.0.0.1', - 6379, - 1, - null, - 500, - 1 -); -$redisClient->auth('apps'); -$redisClient->setOption(Redis::OPT_PREFIX, 'ssp_accounting:'); - - -$redisDurationInSeconds = (new DateTime())->getTimestamp() - $redisStartTime->getTimestamp(); -$redisItemsInCurrentSecond = 0; -$redisItemsPerSecond = []; -for ($i = 1; $i <= $numberOfItems; $i++) { - $redisUpdatedDurationInSeconds = (new DateTime())->getTimestamp() - $redisStartTime->getTimestamp(); - if ($redisDurationInSeconds === $redisUpdatedDurationInSeconds) { - $redisItemsInCurrentSecond++; - } else { - $redisItemsPerSecond[] = $redisItemsInCurrentSecond; - $redisItemsInCurrentSecond = 0; - } - $redisItemsInCurrentSecond = $redisDurationInSeconds === $redisUpdatedDurationInSeconds ? - $redisItemsInCurrentSecond++ : 0; - - $redisDurationInSeconds = $redisUpdatedDurationInSeconds; - - $redisItemsPerSeconds = count($redisItemsPerSecond) ? - array_sum($redisItemsPerSecond) / count($redisItemsPerSecond) : 0; - $redisPercentage = $i / $numberOfItems * 100; - $spinnerChar = $spinnerChars[array_rand($spinnerChars)]; - $line = sprintf( - '%1$s percentage: %2$ 3d%%, items/s: %3$04d, duration: %4$ss', - $spinnerChar, $redisPercentage, $redisItemsPerSeconds, $redisDurationInSeconds - ); - echo $line; - echo "\r"; - $redisClient->rPush(RedisStore::LIST_KEY_JOB . ':' . sha1($job->getType()), serialize($job)); -// $redisClient->rPush(RedisStore::LIST_KEY_JOB, serializgit add .e($job)); -} -echo $newLine; -echo 'End: ' . (new DateTime())->format(DateTime::ATOM); -echo $newLine; \ No newline at end of file diff --git a/hooks/hook_adminmenu.php b/hooks/hook_adminmenu.php index cb7b83be42f8f3b54cd341bbbe3fd8618cd29827..9d7c996486a2c738150e99ba4f50f68efac69c89 100644 --- a/hooks/hook_adminmenu.php +++ b/hooks/hook_adminmenu.php @@ -5,8 +5,10 @@ declare(strict_types=1); use SimpleSAML\Locale\Translate; use SimpleSAML\Module\accounting\Helpers\ModuleRoutesHelper; use SimpleSAML\Module\accounting\ModuleConfiguration; +use SimpleSAML\XHTML\Template; -function accounting_hook_adminmenu(\SimpleSAML\XHTML\Template &$template): void +/** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection Reference is actually used by SimpleSAMLphp */ +function accounting_hook_adminmenu(Template &$template): void { $menuKey = 'menu'; diff --git a/hooks/hook_configpage.php b/hooks/hook_configpage.php index a2b95135f9c84a3f0d5c321e8e0b389837fdee1b..c950bbc2a05650aeef3581ca32bf01eb01e58058 100644 --- a/hooks/hook_configpage.php +++ b/hooks/hook_configpage.php @@ -7,6 +7,7 @@ use SimpleSAML\Module\accounting\Helpers\ModuleRoutesHelper; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\XHTML\Template; +/** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection Reference is used by SimpleSAMLphp */ function accounting_hook_configpage(Template &$template): void { $moduleRoutesHelper = new ModuleRoutesHelper(); diff --git a/hooks/hook_cron.php b/hooks/hook_cron.php index ee6c7c2203a19a3cc82f90b1b93c357109494b4a..0bd374c204087c3297521fe5d41f233ab62485ba 100644 --- a/hooks/hook_cron.php +++ b/hooks/hook_cron.php @@ -70,6 +70,9 @@ function accounting_hook_cron(array &$cronInfo): void } } +/** + * @throws \SimpleSAML\Module\accounting\Exceptions\Exception + */ function handleDataRetentionPolicy( ModuleConfiguration $moduleConfiguration, LoggerInterface $logger, diff --git a/routing/routes/routes.yml b/routing/routes/routes.yml index 79241fb266c79420e0d6706d41dbd1db422206df..a44a2bd3adf0ddbd1e660269e2b409f56950cdf8 100644 --- a/routing/routes/routes.yml +++ b/routing/routes/routes.yml @@ -1,9 +1,4 @@ -# TODO mivanci delete test route -accounting-test: - path: /test - defaults: { _controller: 'SimpleSAML\Module\accounting\Http\Controllers\Test::test' } - accounting-admin-configuration-status: path: /admin/configuration/status defaults: { _controller: 'SimpleSAML\Module\accounting\Http\Controllers\Admin\Configuration::status' } diff --git a/src/Auth/Process/Accounting.php b/src/Auth/Process/Accounting.php index 817fa9e6636cb0e87eb86b9b1e8291f4c103dfac..b84d3a2d20332dbc60cac1c0ee13ac36ccb67282 100644 --- a/src/Auth/Process/Accounting.php +++ b/src/Auth/Process/Accounting.php @@ -14,6 +14,7 @@ use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Services\Logger; use SimpleSAML\Module\accounting\Stores\Builders\JobsStoreBuilder; use SimpleSAML\Module\accounting\Trackers\Builders\AuthenticationDataTrackerBuilder; +use Throwable; class Accounting extends ProcessingFilter { @@ -54,6 +55,7 @@ class Accounting extends ProcessingFilter } /** + * @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection Reference is actually used by SimpleSAMLphp */ public function process(array &$state): void { @@ -75,7 +77,7 @@ class Accounting extends ProcessingFilter foreach ($configuredTrackers as $tracker) { ($this->authenticationDataTrackerBuilder->build($tracker))->process($authenticationEvent); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Accounting error, skipping... Error was: %s.', $exception->getMessage()); $this->logger->error($message, $state); } diff --git a/src/Entities/Activity/Bag.php b/src/Entities/Activity/Bag.php index 7e91a1c9604527a43b3bcb5bf8e68ebc9d881a41..add2566d1005c0f216db54c14d49afb6fe4b2d4e 100644 --- a/src/Entities/Activity/Bag.php +++ b/src/Entities/Activity/Bag.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Entities\Activity; use SimpleSAML\Module\accounting\Entities\Activity; diff --git a/src/Entities/Authentication/Event.php b/src/Entities/Authentication/Event.php index 08c9e8c3c44e9889632b988b00c4ffae982a5305..3155d2e29ad4ff4e36080e2b6ac05fab45edc3da 100644 --- a/src/Entities/Authentication/Event.php +++ b/src/Entities/Authentication/Event.php @@ -4,17 +4,18 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Entities\Authentication; +use DateTimeImmutable; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; class Event extends AbstractPayload { protected State $state; - protected \DateTimeImmutable $happenedAt; + protected DateTimeImmutable $happenedAt; - public function __construct(State $state, \DateTimeImmutable $happenedAt = null) + public function __construct(State $state, DateTimeImmutable $happenedAt = null) { $this->state = $state; - $this->happenedAt = $happenedAt ?? new \DateTimeImmutable(); + $this->happenedAt = $happenedAt ?? new DateTimeImmutable(); } public function getState(): State @@ -22,7 +23,7 @@ class Event extends AbstractPayload return $this->state; } - public function getHappenedAt(): \DateTimeImmutable + public function getHappenedAt(): DateTimeImmutable { return $this->happenedAt; } diff --git a/src/Entities/Authentication/State.php b/src/Entities/Authentication/State.php index 899b3e75d51c500111e729ca8d73293fee7b7a1a..aa5378c2cebf45e0910cd7b182ced2f459ed44a5 100644 --- a/src/Entities/Authentication/State.php +++ b/src/Entities/Authentication/State.php @@ -4,10 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Entities\Authentication; +use DateTimeImmutable; use SimpleSAML\Module\accounting\Entities\Bases\AbstractProvider; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; -use SimpleSAML\Module\accounting\Helpers\NetworkHelper; use SimpleSAML\Module\accounting\Services\HelpersManager; +use Throwable; class State { @@ -24,8 +25,8 @@ class State protected string $identityProviderEntityId; protected string $serviceProviderEntityId; protected array $attributes; - protected \DateTimeImmutable $createdAt; - protected ?\DateTimeImmutable $authenticationInstant; + protected DateTimeImmutable $createdAt; + protected ?DateTimeImmutable $authenticationInstant; protected array $identityProviderMetadata; protected array $serviceProviderMetadata; protected ?string $clientIpAddress; @@ -33,10 +34,10 @@ class State public function __construct( array $state, - \DateTimeImmutable $createdAt = null, + DateTimeImmutable $createdAt = null, HelpersManager $helpersManager = null ) { - $this->createdAt = $createdAt ?? new \DateTimeImmutable(); + $this->createdAt = $createdAt ?? new DateTimeImmutable(); $this->helpersManager = $helpersManager ?? new HelpersManager(); $this->identityProviderMetadata = $this->resolveIdentityProviderMetadata($state); @@ -105,12 +106,12 @@ class State return null; } - public function getCreatedAt(): \DateTimeImmutable + public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } - protected function resolveAuthenticationInstant(array $state): ?\DateTimeImmutable + protected function resolveAuthenticationInstant(array $state): ?DateTimeImmutable { if (empty($state[self::KEY_AUTHENTICATION_INSTANT])) { return null; @@ -119,8 +120,8 @@ class State $authInstant = (string)$state[self::KEY_AUTHENTICATION_INSTANT]; try { - return new \DateTimeImmutable('@' . $authInstant); - } catch (\Throwable $exception) { + return new DateTimeImmutable('@' . $authInstant); + } catch (Throwable $exception) { $message = sprintf( 'Unable to create DateTimeImmutable using AuthInstant value \'%s\'. Error was: %s.', $authInstant, @@ -130,7 +131,7 @@ class State } } - public function getAuthenticationInstant(): ?\DateTimeImmutable + public function getAuthenticationInstant(): ?DateTimeImmutable { return $this->authenticationInstant; } diff --git a/src/Entities/Bases/AbstractProvider.php b/src/Entities/Bases/AbstractProvider.php index 56c0927f39e52c3a1288b6d742aec30747b3e0a1..bad746a9e43750fe3c421fb0ed6fae7edc213a1d 100644 --- a/src/Entities/Bases/AbstractProvider.php +++ b/src/Entities/Bases/AbstractProvider.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Entities\Bases; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; diff --git a/src/Entities/ConnectedServiceProvider.php b/src/Entities/ConnectedServiceProvider.php index 21bf0fc3a6c618c91faa71233d09e9b04d0ef9e5..7c4b7e720db1fa0ccb34c0009f303c8c24cf9814 100644 --- a/src/Entities/ConnectedServiceProvider.php +++ b/src/Entities/ConnectedServiceProvider.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Entities; +use DateTimeImmutable; + /** * Represents a Service Provider to which a user has authenticated at least once. */ @@ -11,23 +13,22 @@ class ConnectedServiceProvider { protected ServiceProvider $serviceProvider; protected int $numberOfAuthentications; - protected \DateTimeImmutable $lastAuthenticationAt; - protected \DateTimeImmutable $firstAuthenticationAt; + protected DateTimeImmutable $lastAuthenticationAt; + protected DateTimeImmutable $firstAuthenticationAt; protected User $user; /** - * TODO mivanci make sortable by name (or entity ID if not present), number of authns, last/first authn. * @param ServiceProvider $serviceProvider * @param int $numberOfAuthentications - * @param \DateTimeImmutable $lastAuthenticationAt - * @param \DateTimeImmutable $firstAuthenticationAt + * @param DateTimeImmutable $lastAuthenticationAt + * @param DateTimeImmutable $firstAuthenticationAt * @param User $user */ public function __construct( ServiceProvider $serviceProvider, int $numberOfAuthentications, - \DateTimeImmutable $lastAuthenticationAt, - \DateTimeImmutable $firstAuthenticationAt, + DateTimeImmutable $lastAuthenticationAt, + DateTimeImmutable $firstAuthenticationAt, User $user ) { $this->serviceProvider = $serviceProvider; @@ -54,17 +55,17 @@ class ConnectedServiceProvider } /** - * @return \DateTimeImmutable + * @return DateTimeImmutable */ - public function getLastAuthenticationAt(): \DateTimeImmutable + public function getLastAuthenticationAt(): DateTimeImmutable { return $this->lastAuthenticationAt; } /** - * @return \DateTimeImmutable + * @return DateTimeImmutable */ - public function getFirstAuthenticationAt(): \DateTimeImmutable + public function getFirstAuthenticationAt(): DateTimeImmutable { return $this->firstAuthenticationAt; } diff --git a/src/Exceptions/Exception.php b/src/Exceptions/Exception.php index 7a0306d210c88d215f326f2b591e86df49ed191b..a14b9379c11b46305b58c99e66e03cb7f9e7fd54 100644 --- a/src/Exceptions/Exception.php +++ b/src/Exceptions/Exception.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Exceptions; class Exception extends \Exception diff --git a/src/Helpers/DateTimeHelper.php b/src/Helpers/DateTimeHelper.php index 0fc5f25242105b35e58ee10257340b8dd7dcfdf2..1e13c714d655e0eb12ef7093cacda7fec0ea4eb6 100644 --- a/src/Helpers/DateTimeHelper.php +++ b/src/Helpers/DateTimeHelper.php @@ -4,16 +4,19 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Helpers; +use DateInterval; +use DateTimeImmutable; + class DateTimeHelper { /** * Convert date interval to seconds, interval being minimum 1 second. - * @param \DateInterval $dateInterval Minimum is 1 second. + * @param DateInterval $dateInterval Minimum is 1 second. * @return int */ - public function convertDateIntervalToSeconds(\DateInterval $dateInterval): int + public function convertDateIntervalToSeconds(DateInterval $dateInterval): int { - $reference = new \DateTimeImmutable(); + $reference = new DateTimeImmutable(); $endTime = $reference->add($dateInterval); $duration = $endTime->getTimestamp() - $reference->getTimestamp(); diff --git a/src/Helpers/EnvironmentHelper.php b/src/Helpers/EnvironmentHelper.php index b67f33c1b7e50ef6dbe8589a3a70d7c1b2d368ce..1e3f27dd8c83dfe315572034db7bf188fcadf19c 100644 --- a/src/Helpers/EnvironmentHelper.php +++ b/src/Helpers/EnvironmentHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Helpers; class EnvironmentHelper diff --git a/src/Helpers/InstanceBuilderUsingModuleConfigurationHelper.php b/src/Helpers/InstanceBuilderUsingModuleConfigurationHelper.php index fed30792f71320136230bf25f825919a4c594d75..0d8b2bb004a02380cf411e5851682f7d20166865 100644 --- a/src/Helpers/InstanceBuilderUsingModuleConfigurationHelper.php +++ b/src/Helpers/InstanceBuilderUsingModuleConfigurationHelper.php @@ -10,6 +10,9 @@ use SimpleSAML\Module\accounting\Exceptions\Exception; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\Interfaces\BuildableUsingModuleConfigurationInterface; use SimpleSAML\Module\accounting\ModuleConfiguration; +use Throwable; + +use function sprintf; class InstanceBuilderUsingModuleConfigurationHelper { @@ -37,8 +40,8 @@ class InstanceBuilderUsingModuleConfigurationHelper $reflectionMethod = new ReflectionMethod($class, $method); /** @var BuildableUsingModuleConfigurationInterface $instance */ $instance = $reflectionMethod->invoke(null, ...$allArguments); - } catch (\Throwable $exception) { - $message = \sprintf( + } catch (Throwable $exception) { + $message = sprintf( 'Error building instance using module configuration. Error was: %s.', $exception->getMessage() ); diff --git a/src/Helpers/ModuleRoutesHelper.php b/src/Helpers/ModuleRoutesHelper.php index ed41487ec70ff43ab744f97e3df745c25b7253ef..e23ee2f3244abb3355952a5686ab87f69d0aa7c7 100644 --- a/src/Helpers/ModuleRoutesHelper.php +++ b/src/Helpers/ModuleRoutesHelper.php @@ -1,7 +1,11 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Helpers; +use SimpleSAML\Error\CriticalConfigurationError; +use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Utils\HTTP; @@ -20,7 +24,12 @@ class ModuleRoutesHelper public function getUrl(string $path, array $parameters = []): string { - $url = $this->sspHttpUtils->getBaseURL() . 'module.php/' . ModuleConfiguration::MODULE_NAME . '/' . $path; + try { + $url = $this->sspHttpUtils->getBaseURL() . 'module.php/' . ModuleConfiguration::MODULE_NAME . '/' . $path; + } catch (CriticalConfigurationError $exception) { + $message = \sprintf('Could not load SimpleSAMLphp base URL. Error was: %s', $exception->getMessage()); + throw new InvalidConfigurationException($message, (int)$exception->getCode(), $exception); + } if (!empty($parameters)) { $url = $this->sspHttpUtils->addURLParameters($url, $parameters); diff --git a/src/Helpers/RandomHelper.php b/src/Helpers/RandomHelper.php index 3a74a7fe318a6705c8835bc10a2ae02c72e90d63..0d773cf93f6d7ad21f8e031a465b3a8013a4fe41 100644 --- a/src/Helpers/RandomHelper.php +++ b/src/Helpers/RandomHelper.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Helpers; +use Throwable; + class RandomHelper { public function getRandomInt(int $minimum = PHP_INT_MIN, int $maximum = PHP_INT_MAX): int @@ -11,7 +13,7 @@ class RandomHelper try { return random_int($minimum, $maximum); // @codeCoverageIgnoreStart - } catch (\Throwable $exception) { + } catch (Throwable $exception) { return mt_rand($minimum, $maximum); // @codeCoverageIgnoreEnd } diff --git a/src/Http/Controllers/Admin/Configuration.php b/src/Http/Controllers/Admin/Configuration.php index 909518ce4e4dbdf56fc72f881c67870c7546c668..fa2adaa132eb4b706f9c2b7ee7db919e96dad262 100644 --- a/src/Http/Controllers/Admin/Configuration.php +++ b/src/Http/Controllers/Admin/Configuration.php @@ -14,7 +14,6 @@ use SimpleSAML\Module\accounting\Stores\Builders\JobsStoreBuilder; use SimpleSAML\Module\accounting\Trackers\Builders\AuthenticationDataTrackerBuilder; use SimpleSAML\Session; use SimpleSAML\Utils; -use SimpleSAML\Utils\Auth; use SimpleSAML\XHTML\Template; use Symfony\Component\HttpFoundation\Request; use Throwable; @@ -27,6 +26,9 @@ class Configuration protected Utils\Auth $sspAuthUtils; protected HelpersManager $helpersManager; + /** + * @throws \SimpleSAML\Error\Exception + */ public function __construct( SspConfiguration $sspConfiguration, Session $session, diff --git a/src/Http/Controllers/Test.php b/src/Http/Controllers/Test.php deleted file mode 100644 index e7b4446d6942869d0d30d92e60655bef7c047ae5..0000000000000000000000000000000000000000 --- a/src/Http/Controllers/Test.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php -// phpcs:ignoreFile - -declare(strict_types=1); - -namespace SimpleSAML\Module\accounting\Http\Controllers; - -use Exception; -use Psr\Log\LoggerInterface; -use SimpleSAML\Configuration as SspConfiguration; -use SimpleSAML\Locale\Translate; -use SimpleSAML\Module\accounting\Entities\Authentication\Event; -use SimpleSAML\Module\accounting\Entities\Authentication\State; -use SimpleSAML\Module\accounting\ModuleConfiguration; -use SimpleSAML\Module\accounting\Services\HelpersManager; -use SimpleSAML\Module\accounting\Stores\Builders\JobsStoreBuilder; -use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; -use SimpleSAML\Module\accounting\Trackers\Authentication\DoctrineDbal\Versioned\Tracker; -use SimpleSAML\Module\accounting\Trackers\Builders\AuthenticationDataTrackerBuilder; -use SimpleSAML\Session; -use SimpleSAML\XHTML\Template; -use Symfony\Component\HttpFoundation\Request; - -/** - * TODO mivanci delete this file before release - * @psalm-suppress all - */ -class Test -{ - protected SspConfiguration $sspConfiguration; - protected Session $session; - protected ModuleConfiguration $moduleConfiguration; - protected LoggerInterface $logger; - protected HelpersManager $helpersManager; - - /** - * @param SspConfiguration $sspConfiguration - * @param Session $session The current user session. - * @param ModuleConfiguration $moduleConfiguration - * @param LoggerInterface $logger - */ - public function __construct( - SspConfiguration $sspConfiguration, - Session $session, - ModuleConfiguration $moduleConfiguration, - LoggerInterface $logger, - HelpersManager $helpersManager - ) { - $this->sspConfiguration = $sspConfiguration; - $this->session = $session; - $this->moduleConfiguration = $moduleConfiguration; - $this->logger = $logger; - $this->helpersManager = $helpersManager; - } - - /** - * @param Request $request - * @return Template - * @throws Exception - */ - public function test(Request $request): Template - { - $template = new Template($this->sspConfiguration, 'accounting:test.twig'); - - $retentionPolicy = new \DateInterval('P4D'); - - (new AuthenticationDataTrackerBuilder($this->moduleConfiguration, $this->logger, $this->helpersManager)) - ->build($this->moduleConfiguration->getDefaultDataTrackerAndProviderClass()) - ->enforceDataRetentionPolicy($retentionPolicy); - - die('end'); - - return $template; - } -} diff --git a/src/Http/Controllers/User/Profile.php b/src/Http/Controllers/User/Profile.php index aba52d9356602ed28a3ed1e095557abb0f3c138d..34b321299517cfea23e19525b7e31092aa34af4c 100644 --- a/src/Http/Controllers/User/Profile.php +++ b/src/Http/Controllers/User/Profile.php @@ -7,8 +7,11 @@ namespace SimpleSAML\Module\accounting\Http\Controllers\User; use Psr\Log\LoggerInterface; use SimpleSAML\Auth\Simple; use SimpleSAML\Configuration as SspConfiguration; +use SimpleSAML\Error\ConfigurationError; +use SimpleSAML\Error\CriticalConfigurationError; use SimpleSAML\HTTP\RunnableResponse; use SimpleSAML\Module\accounting\Exceptions\Exception; +use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; use SimpleSAML\Module\accounting\Helpers\AttributesHelper; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\ModuleConfiguration\ConnectionType; @@ -66,6 +69,9 @@ class Profile $this->authSimple->requireAuth(); } + /** + * @throws ConfigurationError + */ public function personalData(Request $request): Response { $normalizedAttributes = []; @@ -90,13 +96,16 @@ class Profile return $template; } + /** + * @throws Exception + * @throws ConfigurationError + */ public function connectedOrganizations(Request $request): Template { $userIdentifier = $this->resolveUserIdentifier(); $authenticationDataProvider = $this->resolveAuthenticationDataProvider(); - $this->removeDebugDisplayLimits(); $connectedServiceProviderBag = $authenticationDataProvider->getConnectedServiceProviders($userIdentifier); $template = $this->resolveTemplate('accounting:user/connected-organizations.twig'); @@ -105,6 +114,10 @@ class Profile return $template; } + /** + * @throws Exception + * @throws ConfigurationError + */ public function activity(Request $request): Template { $userIdentifier = $this->resolveUserIdentifier(); @@ -116,7 +129,6 @@ class Profile $maxResults = 10; $firstResult = ($page - 1) * $maxResults; - $this->removeDebugDisplayLimits(); $activityBag = $authenticationDataProvider->getActivity($userIdentifier, $maxResults, $firstResult); $template = $this->resolveTemplate('accounting:user/activity.twig'); @@ -125,6 +137,9 @@ class Profile return $template; } + /** + * @throws Exception + */ protected function resolveUserIdentifier(): string { $attributes = $this->authSimple->getAttributes(); @@ -157,7 +172,12 @@ class Profile protected function getLogoutUrl(): string { - return $this->sspConfiguration->getBasePath() . 'logout.php'; + try { + return $this->sspConfiguration->getBasePath() . 'logout.php'; + } catch (CriticalConfigurationError $exception) { + $message = \sprintf('Could not resolve SimpleSAMLphp base path. Error was: %s', $exception->getMessage()); + throw new InvalidConfigurationException($message, (int)$exception->getCode(), $exception); + } } /** @@ -171,14 +191,9 @@ class Profile ); } - /** TODO mivanci remove after debugging */ - protected function removeDebugDisplayLimits(): void - { - ini_set('xdebug.var_display_max_depth', '-1'); - ini_set('xdebug.var_display_max_children', '-1'); - ini_set('xdebug.var_display_max_data', '-1'); - } - + /** + * @throws ConfigurationError + */ protected function resolveTemplate(string $template): Template { $templateInstance = new Template($this->sspConfiguration, $template); diff --git a/src/Interfaces/BuildableUsingModuleConfigurationInterface.php b/src/Interfaces/BuildableUsingModuleConfigurationInterface.php index c1a4aedc646a07c1abbd697f4b25e493c8480647..4b56a465bccbba4aedd15223888980cc8db654d6 100644 --- a/src/Interfaces/BuildableUsingModuleConfigurationInterface.php +++ b/src/Interfaces/BuildableUsingModuleConfigurationInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Interfaces; use Psr\Log\LoggerInterface; diff --git a/src/Interfaces/SetupableInterface.php b/src/Interfaces/SetupableInterface.php index da036e145c3d1ea6d3af16f6d92aa60ad77cd70b..b788c28c63e3c28cd1b731690273977f57a8febf 100644 --- a/src/Interfaces/SetupableInterface.php +++ b/src/Interfaces/SetupableInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Interfaces; interface SetupableInterface diff --git a/src/Providers/Builders/AuthenticationDataProviderBuilder.php b/src/Providers/Builders/AuthenticationDataProviderBuilder.php index b064f1c2cd8efd288dfbd7643d2e75b083f951e7..db0349eb22448c54161276039913c2513c4b8cea 100644 --- a/src/Providers/Builders/AuthenticationDataProviderBuilder.php +++ b/src/Providers/Builders/AuthenticationDataProviderBuilder.php @@ -7,7 +7,6 @@ namespace SimpleSAML\Module\accounting\Providers\Builders; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\Exception; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; -use SimpleSAML\Module\accounting\Helpers\InstanceBuilderUsingModuleConfigurationHelper; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Providers\Interfaces\AuthenticationDataProviderInterface; use SimpleSAML\Module\accounting\Services\HelpersManager; diff --git a/src/Services/JobRunner.php b/src/Services/JobRunner.php index b08d96f17e4903a5b12b4def57108e3544f956b8..6b07f2be04737d95be3edfe2ba34711c3de64511 100644 --- a/src/Services/JobRunner.php +++ b/src/Services/JobRunner.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Services; use Cicnavi\SimpleFileCache\SimpleFileCache; +use DateInterval; +use DateTimeImmutable; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\InvalidArgumentException; @@ -19,6 +21,7 @@ use SimpleSAML\Module\accounting\Services\JobRunner\State; use SimpleSAML\Module\accounting\Stores\Builders\JobsStoreBuilder; use SimpleSAML\Module\accounting\Trackers\Builders\AuthenticationDataTrackerBuilder; use SimpleSAML\Module\accounting\Trackers\Interfaces\AuthenticationDataTrackerInterface; +use Throwable; class JobRunner { @@ -43,12 +46,16 @@ class JobRunner */ protected int $jobRunnerId; protected array $trackers; - protected \DateInterval $stateStaleThresholdInterval; + protected DateInterval $stateStaleThresholdInterval; protected RateLimiter $rateLimiter; protected HelpersManager $helpersManager; - protected ?\DateInterval $maximumExecutionTime; + protected ?DateInterval $maximumExecutionTime; protected ?int $shouldPauseAfterNumberOfJobsProcessed; + /** + * @throws Exception + * @throws \Exception + */ public function __construct( ModuleConfiguration $moduleConfiguration, SspConfiguration $sspConfiguration, @@ -77,7 +84,7 @@ class JobRunner $this->state = $state ?? new State($this->jobRunnerId); $this->trackers = $this->resolveTrackers(); - $this->stateStaleThresholdInterval = new \DateInterval(self::STATE_STALE_THRESHOLD_INTERVAL); + $this->stateStaleThresholdInterval = new DateInterval(self::STATE_STALE_THRESHOLD_INTERVAL); $this->rateLimiter = $rateLimiter ?? new RateLimiter(); $this->maximumExecutionTime = $this->resolveMaximumExecutionTime(); @@ -94,7 +101,7 @@ class JobRunner { try { $this->validatePreRunState(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Pre-run state validation failed. Clearing cached state and continuing. Error was %s', $exception->getMessage() @@ -106,7 +113,7 @@ class JobRunner try { $this->validateRunConditions(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Run conditions are not met, stopping. Reason was: %s', $exception->getMessage()); $this->logger->info($message); $this->state->addStatusMessage($message); @@ -181,8 +188,8 @@ class JobRunner } else { $jobsProcessedSincePause++; } - } catch (\Throwable $exception) { - $message = sprintf('Error while processing jobs. Error was: %', $exception->getMessage()); + } catch (Throwable $exception) { + $message = sprintf('Error while processing jobs. Error was: %s', $exception->getMessage()); $context = []; if (isset($job)) { $context = ['job' => $job]; @@ -196,7 +203,7 @@ class JobRunner $this->clearCachedState(); - $this->state->setEndedAt(new \DateTimeImmutable()); + $this->state->setEndedAt(new DateTimeImmutable()); return $this->state; } @@ -222,7 +229,7 @@ class JobRunner try { $this->validateSelfState(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Job runner state is not valid. Message was: %s', $exception->getMessage() @@ -246,13 +253,13 @@ class JobRunner if ($this->getCachedState() !== null) { throw new UnexpectedValueException('Job runner state already initialized.'); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error initializing job runner state. Error was: %s.', $exception->getMessage()); $this->logger->error($message); throw new Exception($message, (int)$exception->getCode(), $exception); } - $startedAt = new \DateTimeImmutable(); + $startedAt = new DateTimeImmutable(); $this->state->setStartedAt($startedAt); $this->updateCachedState($this->state, $startedAt); } @@ -340,7 +347,7 @@ class JobRunner } return $cachedState->getJobRunnerId() !== $this->jobRunnerId; - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error checking if another job runner is active. To play safe, we will assume true. ' . 'Error was: %s', @@ -364,7 +371,7 @@ class JobRunner ); $this->logger->debug('Successfully initialized cache using SSP datadir.'); return $cache; - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error initializing job runner cache using datadir. Error was: %s', $exception->getMessage() @@ -380,7 +387,7 @@ class JobRunner ); $this->logger->debug('Successfully initialized job runner cache using SSP tempdir.'); return $cache; - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error initializing job runner cache using tempdir. Error was: %s.', $exception->getMessage() @@ -393,7 +400,7 @@ class JobRunner $cache = new SimpleFileCache(self::CACHE_NAME); $this->logger->debug('Successfully initialized cache using system tmp dir.'); return $cache; - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error initializing job runner cache. Error was: %s.', $exception->getMessage() @@ -411,7 +418,7 @@ class JobRunner /** @psalm-suppress InvalidCatch */ try { $this->cache->delete(self::CACHE_KEY_STATE); - } catch (\Throwable | InvalidArgumentException $exception) { + } catch (Throwable | InvalidArgumentException $exception) { $message = sprintf( 'Error clearing job runner cache. Error was: %s.', $exception->getMessage() @@ -435,7 +442,7 @@ class JobRunner } else { return null; } - } catch (\Throwable | InvalidArgumentException $exception) { + } catch (Throwable | InvalidArgumentException $exception) { $message = sprintf('Error getting job runner state from cache. Error was: %s', $exception->getMessage()); throw new Exception($message, (int)$exception->getCode(), $exception); } @@ -444,15 +451,15 @@ class JobRunner /** * @throws Exception */ - protected function updateCachedState(State $state, \DateTimeImmutable $updatedAt = null): void + protected function updateCachedState(State $state, DateTimeImmutable $updatedAt = null): void { - $updatedAt = $updatedAt ?? new \DateTimeImmutable(); + $updatedAt = $updatedAt ?? new DateTimeImmutable(); $state->setUpdatedAt($updatedAt); /** @psalm-suppress InvalidCatch */ try { $this->cache->set(self::CACHE_KEY_STATE, $state); - } catch (\Throwable | InvalidArgumentException $exception) { + } catch (Throwable | InvalidArgumentException $exception) { $message = sprintf('Error setting job runner state. Error was: %s.', $exception->getMessage()); $this->logger->error($message); throw new Exception($message, (int)$exception->getCode(), $exception); @@ -527,7 +534,9 @@ class JobRunner return; } + /** @noinspection PhpComposerExtensionStubsInspection Module is still usable without this.*/ pcntl_signal(SIGINT, [$this, 'handleInterrupt']); + /** @noinspection PhpComposerExtensionStubsInspection Module is still usable without this.*/ pcntl_signal(SIGTERM, [$this, 'handleInterrupt']); } @@ -543,7 +552,10 @@ class JobRunner $this->updateCachedState($this->state); } - protected function resolveMaximumExecutionTime(): ?\DateInterval + /** + * @throws \Exception + */ + protected function resolveMaximumExecutionTime(): ?DateInterval { $maximumExecutionTime = $this->moduleConfiguration->getJobRunnerMaximumExecutionTime(); @@ -554,7 +566,7 @@ class JobRunner // We are in a "web" environment, so take max execution time ini setting into account. $iniMaximumExecutionTimeSeconds = (int)floor((int)ini_get('max_execution_time') * 0.8); - $iniMaximumExecutionTime = new \DateInterval('PT' . $iniMaximumExecutionTimeSeconds . 'S'); + $iniMaximumExecutionTime = new DateInterval('PT' . $iniMaximumExecutionTimeSeconds . 'S'); // If the module setting is null (meaning infinite), use the ini setting. if ($maximumExecutionTime === null) { @@ -588,7 +600,7 @@ class JobRunner } $maxDateTime = $startedAt->add($this->maximumExecutionTime); - if ($maxDateTime > (new \DateTimeImmutable())) { + if ($maxDateTime > (new DateTimeImmutable())) { // Maximum has not been reached yet. return false; } diff --git a/src/Services/JobRunner/RateLimiter.php b/src/Services/JobRunner/RateLimiter.php index bc8dc55b7845250c45753cd71cf647536ed97263..c4c42572c8144f77be0d8271cb64ebfd443cbc87 100644 --- a/src/Services/JobRunner/RateLimiter.php +++ b/src/Services/JobRunner/RateLimiter.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Services\JobRunner; +use DateInterval; use SimpleSAML\Module\accounting\Services\HelpersManager; class RateLimiter @@ -16,17 +19,17 @@ class RateLimiter protected int $currentBackoffPauseInSeconds = 1; public function __construct( - \DateInterval $maxPauseInterval = null, - \DateInterval $maxBackoffInterval = null, + DateInterval $maxPauseInterval = null, + DateInterval $maxBackoffInterval = null, HelpersManager $helpersManager = null ) { $this->helpersManager = $helpersManager ?? new HelpersManager(); $this->maxPauseInSeconds = $this->helpersManager->getDateTimeHelper()->convertDateIntervalToSeconds( - $maxPauseInterval ?? new \DateInterval(self::DEFAULT_MAX_PAUSE_DURATION) + $maxPauseInterval ?? new DateInterval(self::DEFAULT_MAX_PAUSE_DURATION) ); $this->maxBackoffPauseInSeconds = $this->helpersManager->getDateTimeHelper()->convertDateIntervalToSeconds( - $maxBackoffInterval ?? new \DateInterval(self::DEFAULT_MAX_BACKOFF_PAUSE_DURATION) + $maxBackoffInterval ?? new DateInterval(self::DEFAULT_MAX_BACKOFF_PAUSE_DURATION) ); } diff --git a/src/Services/JobRunner/State.php b/src/Services/JobRunner/State.php index 3d1704927002a2464d3b06bc0f73b8da8f8c2246..bb0c5108e68f7e2795ac979e1e3cebf4de373207 100644 --- a/src/Services/JobRunner/State.php +++ b/src/Services/JobRunner/State.php @@ -4,15 +4,18 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Services\JobRunner; +use DateInterval; +use DateTimeImmutable; + class State { public const MAX_NUMBER_OF_MESSAGES_TO_KEEP = 100; public const DEFAULT_NUMBER_OF_MESSAGES_TO_KEEP = 10; protected int $jobRunnerId; - protected ?\DateTimeImmutable $startedAt; - protected \DateTimeImmutable $updatedAt; - protected ?\DateTimeImmutable $endedAt = null; + protected ?DateTimeImmutable $startedAt; + protected DateTimeImmutable $updatedAt; + protected ?DateTimeImmutable $endedAt = null; protected int $successfulJobsProcessed = 0; protected int $failedJobsProcessed = 0; /** @@ -24,13 +27,13 @@ class State public function __construct( int $jobRunnerId, - \DateTimeImmutable $startedAt = null, - \DateTimeImmutable $updatedAt = null, + DateTimeImmutable $startedAt = null, + DateTimeImmutable $updatedAt = null, int $numberOfStatusMessagesToKeep = self::DEFAULT_NUMBER_OF_MESSAGES_TO_KEEP ) { $this->jobRunnerId = $jobRunnerId; $this->startedAt = $startedAt; - $this->updatedAt = $updatedAt ?? new \DateTimeImmutable(); + $this->updatedAt = $updatedAt ?? new DateTimeImmutable(); $this->numberOfStatusMessagesToKeep = $numberOfStatusMessagesToKeep > 0 && $numberOfStatusMessagesToKeep <= self::MAX_NUMBER_OF_MESSAGES_TO_KEEP ? @@ -47,19 +50,19 @@ class State } /** - * @return ?\DateTimeImmutable + * @return ?DateTimeImmutable */ - public function getStartedAt(): ?\DateTimeImmutable + public function getStartedAt(): ?DateTimeImmutable { return $this->startedAt; } /** * Set startedAt if not already set. - * @param \DateTimeImmutable $startedAt + * @param DateTimeImmutable $startedAt * @return bool True if set, false otherwise. */ - public function setStartedAt(\DateTimeImmutable $startedAt): bool + public function setStartedAt(DateTimeImmutable $startedAt): bool { if ($this->startedAt === null) { $this->startedAt = $startedAt; @@ -70,27 +73,27 @@ class State } /** - * @return \DateTimeImmutable + * @return DateTimeImmutable */ - public function getUpdatedAt(): \DateTimeImmutable + public function getUpdatedAt(): DateTimeImmutable { return $this->updatedAt; } /** - * @param \DateTimeImmutable $updatedAt + * @param DateTimeImmutable $updatedAt */ - public function setUpdatedAt(\DateTimeImmutable $updatedAt): void + public function setUpdatedAt(DateTimeImmutable $updatedAt): void { $this->updatedAt = $updatedAt; } /** * Set endedAt if not already set. - * @param \DateTimeImmutable $endedAt + * @param DateTimeImmutable $endedAt * @return bool True if set, false otherwise. */ - public function setEndedAt(\DateTimeImmutable $endedAt): bool + public function setEndedAt(DateTimeImmutable $endedAt): bool { if ($this->endedAt === null) { $this->endedAt = $endedAt; @@ -101,9 +104,9 @@ class State } /** - * @return ?\DateTimeImmutable + * @return ?DateTimeImmutable */ - public function getEndedAt(): ?\DateTimeImmutable + public function getEndedAt(): ?DateTimeImmutable { return $this->endedAt; } @@ -139,9 +142,9 @@ class State return $this->failedJobsProcessed; } - public function isStale(\DateInterval $threshold): bool + public function isStale(DateInterval $threshold): bool { - $minDateTime = (new \DateTimeImmutable())->sub($threshold); + $minDateTime = (new DateTimeImmutable())->sub($threshold); if ($this->getUpdatedAt() < $minDateTime) { return true; diff --git a/src/Stores/Bases/DoctrineDbal/AbstractRawEntity.php b/src/Stores/Bases/DoctrineDbal/AbstractRawEntity.php index ac0b534bb0553f66b5360b82eabbd0b657250587..28150f40f1e3398006b743fca12d39d2212e4c8c 100644 --- a/src/Stores/Bases/DoctrineDbal/AbstractRawEntity.php +++ b/src/Stores/Bases/DoctrineDbal/AbstractRawEntity.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Bases\DoctrineDbal; use DateTimeImmutable; diff --git a/src/Stores/Bases/DoctrineDbal/AbstractStore.php b/src/Stores/Bases/DoctrineDbal/AbstractStore.php index 7dabc9872ec576a5dcb60a8e0d9add99e0bcf0ee..0f992d994ea615091942623e5248f9bc222d3337 100644 --- a/src/Stores/Bases/DoctrineDbal/AbstractStore.php +++ b/src/Stores/Bases/DoctrineDbal/AbstractStore.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Bases\DoctrineDbal; use Psr\Log\LoggerInterface; -use ReflectionClass; use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; diff --git a/src/Stores/Connections/Bases/AbstractMigrator.php b/src/Stores/Connections/Bases/AbstractMigrator.php index 2cdb590c78825979a5895e3dd80a4308e57d7270..caa816681910be82a08723b4f261a654e6643f42 100644 --- a/src/Stores/Connections/Bases/AbstractMigrator.php +++ b/src/Stores/Connections/Bases/AbstractMigrator.php @@ -6,7 +6,6 @@ namespace SimpleSAML\Module\accounting\Stores\Connections\Bases; use SimpleSAML\Module\accounting\Exceptions\InvalidValueException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; -use SimpleSAML\Module\accounting\Helpers\FilesystemHelper; use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Stores\Interfaces\MigrationInterface; use Throwable; diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store.php index ce3478f1ed114d9a0734807e12326ddc285654c3..413bae3cab0674bc08e13905946a396bd391d623 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned; +use DateTimeImmutable; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Activity; use SimpleSAML\Module\accounting\Entities\Authentication\Event; @@ -21,6 +22,7 @@ use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Version use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\RawConnectedServiceProvider; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Repository; use SimpleSAML\Module\accounting\Stores\Interfaces\DataStoreInterface; +use Throwable; class Store extends AbstractStore implements DataStoreInterface { @@ -100,7 +102,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($idpId !== false) { return (int)$idpId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving Idp ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -111,7 +113,7 @@ class Store extends AbstractStore implements DataStoreInterface $hashDecoratedState->getState()->getIdentityProviderEntityId(), $idpEntityIdHashSha256 ); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new IdP, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -133,7 +135,7 @@ class Store extends AbstractStore implements DataStoreInterface $idpEntityIdHashSha256 ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving Idp ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -154,7 +156,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($idpVersionId !== false) { return (int)$idpVersionId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving IdP Version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -166,7 +168,7 @@ class Store extends AbstractStore implements DataStoreInterface serialize($hashDecoratedState->getState()->getIdentityProviderMetadata()), $idpMetadataArrayHashSha256 ); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new IdP Version, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -188,12 +190,15 @@ class Store extends AbstractStore implements DataStoreInterface $idpId ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving Idp Version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } } + /** + * @throws StoreException + */ protected function resolveSpId(HashDecoratedState $hashDecoratedState): int { $spEntityIdHashSha256 = $hashDecoratedState->getServiceProviderEntityIdHashSha256(); @@ -206,7 +211,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($spId !== false) { return (int)$spId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving SP ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -217,7 +222,7 @@ class Store extends AbstractStore implements DataStoreInterface $hashDecoratedState->getState()->getServiceProviderEntityId(), $spEntityIdHashSha256 ); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new SP, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -239,7 +244,7 @@ class Store extends AbstractStore implements DataStoreInterface $spEntityIdHashSha256 ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving SP ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -260,7 +265,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($spVersionId !== false) { return (int)$spVersionId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving SP Version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -272,7 +277,7 @@ class Store extends AbstractStore implements DataStoreInterface serialize($hashDecoratedState->getState()->getServiceProviderMetadata()), $spMetadataArrayHashSha256 ); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new SP Version, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -294,7 +299,7 @@ class Store extends AbstractStore implements DataStoreInterface $spId ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving SP Version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -323,7 +328,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($userId !== false) { return (int)$userId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -331,7 +336,7 @@ class Store extends AbstractStore implements DataStoreInterface // Create new try { $this->repository->insertUser($userIdentifierValue, $userIdentifierValueHashSha256); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new user, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -353,7 +358,7 @@ class Store extends AbstractStore implements DataStoreInterface $userIdentifierValueHashSha256 ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving user ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -374,7 +379,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($userVersionId !== false) { return (int)$userVersionId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -386,7 +391,7 @@ class Store extends AbstractStore implements DataStoreInterface serialize($hashDecoratedState->getState()->getAttributes()), $attributeArrayHashSha256 ); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new user version, however, continuing in case of race condition. Error was: %s.', $exception->getMessage() @@ -408,12 +413,15 @@ class Store extends AbstractStore implements DataStoreInterface $userId ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving user version ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } } + /** + * @throws StoreException + */ protected function resolveIdpSpUserVersionId(int $idpVersionId, int $spVersionId, int $userVersionId): int { // Check if it already exists. @@ -424,7 +432,7 @@ class Store extends AbstractStore implements DataStoreInterface if ($IdpSpUserVersionId !== false) { return (int)$IdpSpUserVersionId; } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving IdpSpUserVersion ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -432,7 +440,7 @@ class Store extends AbstractStore implements DataStoreInterface // Create new try { $this->repository->insertIdpSpUserVersion($idpVersionId, $spVersionId, $userVersionId); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error inserting new IdpSpUserVersion, however, continuing in case of race condition. ' . 'Error was: %s.', @@ -458,7 +466,7 @@ class Store extends AbstractStore implements DataStoreInterface $userVersionId ); throw new StoreException($message); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Error resolving IdpSpUserVersion ID. Error was: %s.', $exception->getMessage()); throw new StoreException($message, (int)$exception->getCode(), $exception); } @@ -497,7 +505,7 @@ class Store extends AbstractStore implements DataStoreInterface ) ); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error populating connected service provider bag. Error was: %s', $exception->getMessage() @@ -538,7 +546,7 @@ class Store extends AbstractStore implements DataStoreInterface ) ); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error populating activity bag. Error was: %s', $exception->getMessage() @@ -549,7 +557,10 @@ class Store extends AbstractStore implements DataStoreInterface return $activityBag; } - public function deleteDataOlderThan(\DateTimeImmutable $dateTime): void + /** + * @throws StoreException + */ + public function deleteDataOlderThan(DateTimeImmutable $dateTime): void { // Only delete authentication events. Versioned data (IdP / SP metadata, user attributes) remain. $this->repository->deleteAuthenticationEventsOlderThan($dateTime); diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTable.php index 66d8b08f2e4d861a0e5930cb5db719a08d58ec3e..4bddd2ae4c7eef75c74e323167a1a6e6902a3a28 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTable.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; @@ -7,6 +9,9 @@ use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000000CreateIdpTable extends AbstractMigration { @@ -23,6 +28,7 @@ class Version20220801000000CreateIdpTable extends AbstractMigration { $tableName = $this->preparePrefixedTableName('idp'); + /** @noinspection DuplicatedCode */ try { $table = new Table($tableName); @@ -44,9 +50,9 @@ class Version20220801000000CreateIdpTable extends AbstractMigration $table->addUniqueConstraint(['entity_id_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -62,8 +68,8 @@ class Version20220801000000CreateIdpTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTable.php index 4c18cf2929b4ace28d84c16d3a81211904e7a383..1151b3a2694efdb00e5b8599674aec830c25175b 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTable.php @@ -1,13 +1,15 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; class Version20220801000100CreateIdpVersionTable extends AbstractMigration { @@ -49,7 +51,7 @@ class Version20220801000100CreateIdpVersionTable extends AbstractMigration $table->addUniqueConstraint(['metadata_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( \sprintf('Error creating table \'%s.', $tableName), $exception @@ -67,7 +69,7 @@ class Version20220801000100CreateIdpVersionTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTable.php index b9418b6d1224d8597253b0f90c4e3ec06871bb3f..bee93ca8560670d1082ddba1af61f8454b528606 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTable.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; @@ -7,6 +9,9 @@ use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000200CreateSpTable extends AbstractMigration { @@ -23,6 +28,7 @@ class Version20220801000200CreateSpTable extends AbstractMigration { $tableName = $this->preparePrefixedTableName('sp'); + /** @noinspection DuplicatedCode */ try { $table = new Table($tableName); @@ -44,9 +50,9 @@ class Version20220801000200CreateSpTable extends AbstractMigration $table->addUniqueConstraint(['entity_id_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -62,8 +68,8 @@ class Version20220801000200CreateSpTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTable.php index 13a55358e0491d17099973de3f98ab9385c44136..e2e0028a57699ffb83d771e0a4bee7c47b223442 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTable.php @@ -1,13 +1,17 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000300CreateSpVersionTable extends AbstractMigration { @@ -49,9 +53,9 @@ class Version20220801000300CreateSpVersionTable extends AbstractMigration $table->addUniqueConstraint(['metadata_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -67,8 +71,8 @@ class Version20220801000300CreateSpVersionTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTable.php index 667d8ffa9e4d53a669005a49218d8b74ec9f98dd..ff14736d758230e7837ee4ae80d7c5e561d53645 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTable.php @@ -1,13 +1,17 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000400CreateUserTable extends AbstractMigration { @@ -45,9 +49,9 @@ class Version20220801000400CreateUserTable extends AbstractMigration $table->addUniqueConstraint(['identifier_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -63,8 +67,8 @@ class Version20220801000400CreateUserTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTable.php index fcb2b42ca0e72b02d561eb395aad33c1154cfe7c..a351c6a3c141c2fd13fe41cb09ff4e6102716593 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTable.php @@ -1,13 +1,17 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000500CreateUserVersionTable extends AbstractMigration { @@ -50,9 +54,9 @@ class Version20220801000500CreateUserVersionTable extends AbstractMigration $table->addUniqueConstraint(['attributes_hash_sha256']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -68,8 +72,8 @@ class Version20220801000500CreateUserVersionTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTable.php index 625e6512f4c8f3f23d8c249e82d477e323054152..5f23e4ecdec92d8dd71f171845ef4ae0ae8b7221 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTable.php @@ -5,11 +5,12 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; -use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000600CreateIdpSpUserVersionTable extends AbstractMigration { @@ -67,9 +68,9 @@ class Version20220801000600CreateIdpSpUserVersionTable extends AbstractMigration $table->addUniqueConstraint(['idp_version_id', 'sp_version_id', 'user_version_id']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -85,8 +86,8 @@ class Version20220801000600CreateIdpSpUserVersionTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTable.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTable.php index be8e304cd55d8db5d95093d454758b2f3503ae3b..b465f7d42a6e536542d8829988269a6c427ca937 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTable.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTable.php @@ -1,13 +1,17 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\TableConstants; +use Throwable; + +use function sprintf; class Version20220801000700CreateAuthenticationEventTable extends AbstractMigration { @@ -54,9 +58,9 @@ class Version20220801000700CreateAuthenticationEventTable extends AbstractMigrat $table->addIndex(['happened_at']); $this->schemaManager->createTable($table); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Error creating table \'%s.', $tableName), + sprintf('Error creating table \'%s.', $tableName), $exception ); } @@ -72,8 +76,8 @@ class Version20220801000700CreateAuthenticationEventTable extends AbstractMigrat try { $this->schemaManager->dropTable($tableName); - } catch (\Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + } catch (Throwable $exception) { + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } } diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivity.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivity.php index 17fb9e3528b47bd1e36b5a94cfabeda43328cf55..16bc1766fb73ccb6c37d5d40433de998f17570fc 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivity.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivity.php @@ -86,6 +86,7 @@ class RawActivity extends AbstractRawEntity } } + /** @noinspection DuplicatedCode */ if (! is_string($rawRow[TableConstants::ENTITY_ACTIVITY_COLUMN_NAME_SP_METADATA])) { $message = sprintf( 'Column %s must be string.', diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProvider.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProvider.php index f9ed95a75e80ed431f60db63c2d3c8dba120af3c..d730b3150a45c2b6c468f16d2f3acf10614fd282 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProvider.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProvider.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; use DateTimeImmutable; @@ -109,6 +111,7 @@ class RawConnectedServiceProvider extends AbstractRawEntity throw new UnexpectedValueException($message); } + /** @noinspection DuplicatedCode */ if (! is_string($rawRow[TableConstants::ENTITY_CONNECTED_ORGANIZATION_COLUMN_NAME_LAST_AUTHENTICATION_AT])) { $message = sprintf( 'Column %s must be string.', diff --git a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Repository.php b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Repository.php index 24c9b34492e51555959e33a3e482736b1ea7bd22..32103e019a8a5b1c5dfc3c3551bc4091d547e3ed 100644 --- a/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Repository.php +++ b/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Repository.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\Types; @@ -85,11 +86,11 @@ class Repository public function insertIdp( string $entityId, string $entityIdHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameIdp) ->values( @@ -172,11 +173,11 @@ class Repository int $idpId, string $metadata, string $metadataHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameIdpVersion) ->values( @@ -246,14 +247,17 @@ class Repository } } + /** + * @throws StoreException + */ public function insertSp( string $entityId, string $entityIdHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameSp) ->values( @@ -336,11 +340,11 @@ class Repository int $spId, string $metadata, string $metadataHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameSpVersion) ->values( @@ -416,11 +420,11 @@ class Repository public function insertUser( string $identifier, string $identifierHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameUser) ->values( @@ -503,11 +507,11 @@ class Repository int $userId, string $attributes, string $attributesHashSha256, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameUserVersion) ->values( @@ -603,11 +607,11 @@ class Repository int $idpVersionId, int $spVersionId, int $userVersionId, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameIdpSpUserVersion) ->values( @@ -653,14 +657,14 @@ class Repository */ public function insertAuthenticationEvent( int $IdpSpUserVersionId, - \DateTimeImmutable $happenedAt, + DateTimeImmutable $happenedAt, string $clientIpAddress = null, - \DateTimeImmutable $createdAt = null + DateTimeImmutable $createdAt = null ): void { try { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); - $createdAt = $createdAt ?? new \DateTimeImmutable(); + $createdAt = $createdAt ?? new DateTimeImmutable(); $queryBuilder->insert($this->tableNameAuthenticationEvent) ->values( @@ -945,7 +949,7 @@ class Repository $lastMetadataAndAttributesQueryBuilder->executeQuery()->fetchAllAssociativeIndexed(); return array_merge_recursive($numberOfAuthentications, $lastMetadataAndAttributes); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error executing query to get connected organizations. Error was: %s.', $exception->getMessage() @@ -1058,7 +1062,7 @@ class Repository ->setFirstResult($firstResult); return $authenticationEventsQueryBuilder->executeQuery()->fetchAllAssociative(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf( 'Error executing query to get connected organizations. Error was: %s.', $exception->getMessage() @@ -1070,7 +1074,7 @@ class Repository /** * @throws StoreException */ - public function deleteAuthenticationEventsOlderThan(\DateTimeImmutable $dateTime): void + public function deleteAuthenticationEventsOlderThan(DateTimeImmutable $dateTime): void { try { $queryBuilder = $this->connection->dbal()->createQueryBuilder(); diff --git a/src/Stores/Interfaces/DataStoreInterface.php b/src/Stores/Interfaces/DataStoreInterface.php index 6fefe9a744454ade4ae0ffecdcb4dd045589ea01..ce578f49c1382c9864535712b80801e58a221c58 100644 --- a/src/Stores/Interfaces/DataStoreInterface.php +++ b/src/Stores/Interfaces/DataStoreInterface.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Interfaces; +use DateTimeImmutable; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\ConnectedServiceProvider; @@ -25,5 +26,5 @@ interface DataStoreInterface extends StoreInterface public function getActivity(string $userIdentifierHashSha256, int $maxResults, int $firstResult): Activity\Bag; - public function deleteDataOlderThan(\DateTimeImmutable $dateTime): void; + public function deleteDataOlderThan(DateTimeImmutable $dateTime): void; } diff --git a/src/Stores/Jobs/DoctrineDbal/Store.php b/src/Stores/Jobs/DoctrineDbal/Store.php index 86107ec9ae979f9f921ff39a47ec45cc32ea94ab..0d5f8046a85f9064c232287a7369c4c3b7b90f8f 100644 --- a/src/Stores/Jobs/DoctrineDbal/Store.php +++ b/src/Stores/Jobs/DoctrineDbal/Store.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal; +use Doctrine\DBAL\Exception; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Interfaces\JobInterface; use SimpleSAML\Module\accounting\Exceptions\StoreException; @@ -58,6 +59,7 @@ class Store extends AbstractStore implements JobsStoreInterface /** * @throws StoreException + * @throws Exception|Exception */ public function dequeue(string $type): ?JobInterface { @@ -127,7 +129,6 @@ class Store extends AbstractStore implements JobsStoreInterface * @param ModuleConfiguration $moduleConfiguration * @param LoggerInterface $logger * @param string|null $connectionKey - * @param string $connectionType * @return self * @throws StoreException */ diff --git a/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Bases/AbstractCreateJobsTable.php b/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Bases/AbstractCreateJobsTable.php index 203afb8dfb7d2a0e09dbc3c2367f6da41032adee..d602ec68b4e279bdfcdf075710e7b107e89ff285 100644 --- a/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Bases/AbstractCreateJobsTable.php +++ b/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Bases/AbstractCreateJobsTable.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store\Migrations\Bases; use Doctrine\DBAL\Schema\Table; @@ -9,6 +11,8 @@ use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractM use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store\TableConstants; use Throwable; +use function sprintf; + abstract class AbstractCreateJobsTable extends AbstractMigration { /** @@ -36,7 +40,7 @@ abstract class AbstractCreateJobsTable extends AbstractMigration $this->schemaManager->createTable($table); } catch (Throwable $exception) { throw $this->prepareGenericMigrationException( - \sprintf('Could not create table %s.', $tableName), + sprintf('Could not create table %s.', $tableName), $exception ); } @@ -52,7 +56,7 @@ abstract class AbstractCreateJobsTable extends AbstractMigration try { $this->schemaManager->dropTable($tableName); } catch (Throwable $exception) { - throw $this->prepareGenericMigrationException(\sprintf('Could not drop table %s.', $tableName), $exception); + throw $this->prepareGenericMigrationException(sprintf('Could not drop table %s.', $tableName), $exception); } } diff --git a/src/Stores/Jobs/DoctrineDbal/Store/RawJob.php b/src/Stores/Jobs/DoctrineDbal/Store/RawJob.php index 5737b9230750963ae0c7bad7514d97deb1429261..b302feeba47c8ce5330e1afc9d2bd6c36f1fb9c0 100644 --- a/src/Stores/Jobs/DoctrineDbal/Store/RawJob.php +++ b/src/Stores/Jobs/DoctrineDbal/Store/RawJob.php @@ -6,13 +6,10 @@ namespace SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store; use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Types\Types; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\Stores\Bases\DoctrineDbal\AbstractRawEntity; use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store; -use Throwable; use function sprintf; diff --git a/src/Trackers/Authentication/DoctrineDbal/Versioned/Tracker.php b/src/Trackers/Authentication/DoctrineDbal/Versioned/Tracker.php index 9c1971a0ebdd4fb1de97db1bc0631ab1904cff99..a3e2076fc6af4ad8648382e760fc7e56698a8468 100644 --- a/src/Trackers/Authentication/DoctrineDbal/Versioned/Tracker.php +++ b/src/Trackers/Authentication/DoctrineDbal/Versioned/Tracker.php @@ -4,11 +4,14 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Trackers\Authentication\DoctrineDbal\Versioned; +use DateInterval; +use DateTimeImmutable; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Activity; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\ConnectedServiceProvider; use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Providers\Interfaces\AuthenticationDataProviderInterface; use SimpleSAML\Module\accounting\Services\HelpersManager; @@ -24,6 +27,9 @@ class Tracker implements AuthenticationDataTrackerInterface, AuthenticationDataP protected DataStoreInterface $dataStore; protected HelpersManager $helpersManager; + /** + * @throws StoreException + */ public function __construct( ModuleConfiguration $moduleConfiguration, LoggerInterface $logger, @@ -46,6 +52,9 @@ class Tracker implements AuthenticationDataTrackerInterface, AuthenticationDataP ); } + /** + * @throws StoreException + */ public static function build( ModuleConfiguration $moduleConfiguration, LoggerInterface $logger, @@ -86,9 +95,9 @@ class Tracker implements AuthenticationDataTrackerInterface, AuthenticationDataP return $this->dataStore->getActivity($userIdentifierHashSha256, $maxResults, $firstResult); } - public function enforceDataRetentionPolicy(\DateInterval $retentionPolicy): void + public function enforceDataRetentionPolicy(DateInterval $retentionPolicy): void { - $dateTime = (new \DateTimeImmutable())->sub($retentionPolicy); + $dateTime = (new DateTimeImmutable())->sub($retentionPolicy); if ($dateTime === false) { // @codeCoverageIgnoreStart diff --git a/src/Trackers/Builders/AuthenticationDataTrackerBuilder.php b/src/Trackers/Builders/AuthenticationDataTrackerBuilder.php index 388338d13de848a44b020c25d3d9131ac541738a..762109fd045b6ed82385a018eb69fc86648f9c2e 100644 --- a/src/Trackers/Builders/AuthenticationDataTrackerBuilder.php +++ b/src/Trackers/Builders/AuthenticationDataTrackerBuilder.php @@ -1,11 +1,12 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Module\accounting\Trackers\Builders; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\Exception; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; -use SimpleSAML\Module\accounting\Helpers\InstanceBuilderUsingModuleConfigurationHelper; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Trackers\Interfaces\AuthenticationDataTrackerInterface; diff --git a/src/Trackers/Interfaces/AuthenticationDataTrackerInterface.php b/src/Trackers/Interfaces/AuthenticationDataTrackerInterface.php index 9a1f826bd2420a0701b2289de541c2c89dddfd73..ca0fb42c11391c4adb30222f86eea9ad056633ff 100644 --- a/src/Trackers/Interfaces/AuthenticationDataTrackerInterface.php +++ b/src/Trackers/Interfaces/AuthenticationDataTrackerInterface.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Module\accounting\Trackers\Interfaces; +use DateInterval; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Interfaces\BuildableUsingModuleConfigurationInterface; use SimpleSAML\Module\accounting\Interfaces\SetupableInterface; use SimpleSAML\Module\accounting\ModuleConfiguration; -use SimpleSAML\Module\accounting\Providers\Interfaces\AuthenticationDataProviderInterface; interface AuthenticationDataTrackerInterface extends BuildableUsingModuleConfigurationInterface, SetupableInterface { @@ -17,5 +17,5 @@ interface AuthenticationDataTrackerInterface extends BuildableUsingModuleConfigu public function process(Event $authenticationEvent): void; - public function enforceDataRetentionPolicy(\DateInterval $retentionPolicy): void; + public function enforceDataRetentionPolicy(DateInterval $retentionPolicy): void; } diff --git a/tests/config-templates/config.php b/tests/config-templates/config.php index a6c0417abcb66585642837aa25834dd82109c006..7cc113e0db7498187b6805b65039bc5a6f394701 100644 --- a/tests/config-templates/config.php +++ b/tests/config-templates/config.php @@ -4,7 +4,11 @@ * The configuration of SimpleSAMLphp */ -$httpUtils = new \SimpleSAML\Utils\HTTP(); +declare(strict_types=1); + +use SimpleSAML\Utils\HTTP; + +$httpUtils = new HTTP(); $config = [ diff --git a/tests/src/Auth/Process/AccountingTest.php b/tests/src/Auth/Process/AccountingTest.php index 7e932e0856e83dfc5c9c624dbbda1d90df3ebb61..b10d9ad5d464cd13d53ff773f78fec968e44fa62 100644 --- a/tests/src/Auth/Process/AccountingTest.php +++ b/tests/src/Auth/Process/AccountingTest.php @@ -4,18 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Auth\Process; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Auth\Process\Accounting; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Authentication\Event; -use SimpleSAML\Module\accounting\Entities\Authentication\State; use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Stores\Builders\JobsStoreBuilder; -use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; -use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Factory; -use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Migrator; use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store; use SimpleSAML\Module\accounting\Trackers\Authentication\DoctrineDbal\Versioned\Tracker; use SimpleSAML\Module\accounting\Trackers\Builders\AuthenticationDataTrackerBuilder; @@ -36,13 +34,13 @@ use SimpleSAML\Test\Module\accounting\Constants\StateArrays; */ class AccountingTest extends TestCase { - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; - protected \PHPUnit\Framework\MockObject\MockObject $loggerMock; + protected Stub $moduleConfigurationStub; + protected MockObject $loggerMock; protected array $filterConfig; - protected \PHPUnit\Framework\MockObject\MockObject $jobsStoreBuilderMock; - protected \PHPUnit\Framework\MockObject\MockObject $authenticationDataTrackerBuilderMock; - protected \PHPUnit\Framework\MockObject\MockObject $jobsStoreMock; - protected \PHPUnit\Framework\MockObject\MockObject $trackerMock; + protected MockObject $jobsStoreBuilderMock; + protected MockObject $authenticationDataTrackerBuilderMock; + protected MockObject $jobsStoreMock; + protected MockObject $trackerMock; protected array $sampleState; protected HelpersManager $helpersManager; diff --git a/tests/src/Constants/SerializedJob.php b/tests/src/Constants/SerializedJob.php index 703c055d01c3264f3659957d3a30f23a0b544bef..700412b017d92e55efab052b4b179742adf4c9ae 100644 --- a/tests/src/Constants/SerializedJob.php +++ b/tests/src/Constants/SerializedJob.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Constants; use SimpleSAML\Module\accounting\Entities\Authentication\Event\Job; diff --git a/tests/src/Entities/Activity/BagTest.php b/tests/src/Entities/Activity/BagTest.php index 023dcf5dcea25d8712e996feb9fe69828e5ce77f..3d434166c553253b65517178e4b5d4ae27f05bd1 100644 --- a/tests/src/Entities/Activity/BagTest.php +++ b/tests/src/Entities/Activity/BagTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities\Activity; use SimpleSAML\Module\accounting\Entities\Activity; diff --git a/tests/src/Entities/ActivityTest.php b/tests/src/Entities/ActivityTest.php index 2a35bd27f87167858eb63debcb1409ef8db4a3e6..5199bfe60687c00bd3f2dac26af2aa21d94f2712 100644 --- a/tests/src/Entities/ActivityTest.php +++ b/tests/src/Entities/ActivityTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Entities; +use DateTimeImmutable; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Entities\Activity; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\ServiceProvider; @@ -15,21 +17,21 @@ use SimpleSAML\Module\accounting\Entities\User; class ActivityTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\Stub|ServiceProvider|ServiceProvider&\PHPUnit\Framework\MockObject\Stub + * @var Stub|ServiceProvider */ protected $serviceProviderStub; /** - * @var \PHPUnit\Framework\MockObject\Stub|User|User&\PHPUnit\Framework\MockObject\Stub + * @var Stub|User */ protected $userStub; - protected \DateTimeImmutable $happenedAt; + protected DateTimeImmutable $happenedAt; protected string $clientIpAddress; public function setUp(): void { $this->serviceProviderStub = $this->createStub(ServiceProvider::class); $this->userStub = $this->createStub(User::class); - $this->happenedAt = new \DateTimeImmutable(); + $this->happenedAt = new DateTimeImmutable(); $this->clientIpAddress = '123.123.123.123'; } diff --git a/tests/src/Entities/Authentication/Event/JobTest.php b/tests/src/Entities/Authentication/Event/JobTest.php index a43e3bf892e0dfa1a2c7baae9df31c7c1d8506aa..508118ecf21be2a4000c3a9ff6caedc80aa0a6f6 100644 --- a/tests/src/Entities/Authentication/Event/JobTest.php +++ b/tests/src/Entities/Authentication/Event/JobTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities\Authentication\Event; use PHPUnit\Framework\TestCase; diff --git a/tests/src/Entities/Authentication/EventTest.php b/tests/src/Entities/Authentication/EventTest.php index 58b063437fb3847f9b0d66bcf3876aa6c09b358a..28929d6a703d5fc6b372261366c50ebf973f60b8 100644 --- a/tests/src/Entities/Authentication/EventTest.php +++ b/tests/src/Entities/Authentication/EventTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities\Authentication; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Authentication\State; @@ -17,7 +20,7 @@ class EventTest extends TestCase { public function testCanGetState(): void { - $dateTime = new \DateTimeImmutable(); + $dateTime = new DateTimeImmutable(); $authenticationEvent = new Event(new State(StateArrays::FULL), $dateTime); $this->assertInstanceOf(State::class, $authenticationEvent->getState()); diff --git a/tests/src/Entities/Authentication/StateTest.php b/tests/src/Entities/Authentication/StateTest.php index 5be1a12aba53891e7236d765a45758532996f529..0965a1e57c4caf81f04cfc7a76cd69e43e35b889 100644 --- a/tests/src/Entities/Authentication/StateTest.php +++ b/tests/src/Entities/Authentication/StateTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Entities\Authentication; +use DateTimeImmutable; use SimpleSAML\Module\accounting\Entities\Authentication\State; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; @@ -183,6 +184,6 @@ class StateTest extends TestCase public function testCanGetCreatedAt(): void { $state = new State(StateArrays::FULL); - $this->assertInstanceOf(\DateTimeImmutable::class, $state->getCreatedAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $state->getCreatedAt()); } } diff --git a/tests/src/Entities/Bases/AbstractJobTest.php b/tests/src/Entities/Bases/AbstractJobTest.php index 22725b8079bf41a9070af20b1b4922af94b1270f..3e1990236f05b1a4ac0d925cc7d12de929ac8fa9 100644 --- a/tests/src/Entities/Bases/AbstractJobTest.php +++ b/tests/src/Entities/Bases/AbstractJobTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities\Bases; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Bases\AbstractJob; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; @@ -24,7 +27,7 @@ class AbstractJobTest extends TestCase public function testCanInitializeProperties(): void { $id = 1; - $createdAt = new \DateTimeImmutable(); + $createdAt = new DateTimeImmutable(); $job = new class ($this->payload, $id, $createdAt) extends AbstractJob { public function getType(): string { diff --git a/tests/src/Entities/ConnectedServiceProvider/BagTest.php b/tests/src/Entities/ConnectedServiceProvider/BagTest.php index 3d62a773c429d5a84e8df4de9d4bb817e5ab712f..396c455480eb156a92f6adea27cccd33b4c71093 100644 --- a/tests/src/Entities/ConnectedServiceProvider/BagTest.php +++ b/tests/src/Entities/ConnectedServiceProvider/BagTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities\ConnectedServiceProvider; use SimpleSAML\Module\accounting\Entities\ConnectedServiceProvider; diff --git a/tests/src/Entities/ConnectedServiceProviderTest.php b/tests/src/Entities/ConnectedServiceProviderTest.php index 186fb2e9a71b22c51e71de0be6ef6bb1b11bf406..f5df43bc2037300a4163e2dc00e9936a7d226a6b 100644 --- a/tests/src/Entities/ConnectedServiceProviderTest.php +++ b/tests/src/Entities/ConnectedServiceProviderTest.php @@ -1,7 +1,11 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities; +use DateTimeImmutable; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Entities\ConnectedServiceProvider; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\ServiceProvider; @@ -13,21 +17,21 @@ use SimpleSAML\Module\accounting\Entities\User; class ConnectedServiceProviderTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\Stub|ServiceProvider|ServiceProvider&\PHPUnit\Framework\MockObject\Stub + * @var Stub|ServiceProvider */ protected $serviceProviderStub; /** - * @var \PHPUnit\Framework\MockObject\Stub|User|User&\PHPUnit\Framework\MockObject\Stub + * @var Stub|User */ protected $userStub; - protected \DateTimeImmutable $dateTime; + protected DateTimeImmutable $dateTime; protected int $numberOfAuthentications; public function setUp(): void { $this->serviceProviderStub = $this->createStub(ServiceProvider::class); $this->userStub = $this->createStub(User::class); - $this->dateTime = new \DateTimeImmutable(); + $this->dateTime = new DateTimeImmutable(); $this->numberOfAuthentications = 1; } diff --git a/tests/src/Entities/GenericJobTest.php b/tests/src/Entities/GenericJobTest.php index 11aed48d0183f49e9204d63d734caa07a193322a..908daad66ecdb224836bb614318ba2056d4faaa7 100644 --- a/tests/src/Entities/GenericJobTest.php +++ b/tests/src/Entities/GenericJobTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; diff --git a/tests/src/Entities/ServiceProviderTest.php b/tests/src/Entities/ServiceProviderTest.php index 3c959231ab46acd593973adc08f81297e8aa2011..d414b1c53a860d2343066fd7ff178cca9d40e61f 100644 --- a/tests/src/Entities/ServiceProviderTest.php +++ b/tests/src/Entities/ServiceProviderTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Entities; use SimpleSAML\Module\accounting\Entities\ServiceProvider; diff --git a/tests/src/Helpers/ArrayHelperTest.php b/tests/src/Helpers/ArrayHelperTest.php index 204f2886889d694fec9808dffafa0d30bfc05a44..5d7c639b137202d338338c02ad7dfc77dba36bce 100644 --- a/tests/src/Helpers/ArrayHelperTest.php +++ b/tests/src/Helpers/ArrayHelperTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Helpers; use SimpleSAML\Module\accounting\Helpers\ArrayHelper; diff --git a/tests/src/Helpers/AttributesHelperTest.php b/tests/src/Helpers/AttributesHelperTest.php index 8400b1e042144da64a695aba893e89a5a4f65fde..c94e6fc6adaa56552fe8da42ddb4aaa872e2e5e2 100644 --- a/tests/src/Helpers/AttributesHelperTest.php +++ b/tests/src/Helpers/AttributesHelperTest.php @@ -1,8 +1,9 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Helpers; -use SimpleSAML\Module\accounting\Helpers\AttributesHelper; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\HelpersManager; diff --git a/tests/src/Helpers/DateTimeHelperTest.php b/tests/src/Helpers/DateTimeHelperTest.php index ad82ee7fc20d4ff429a104f1d4bb097246e68a1f..c9ff61a71bab27c08ec1c501978bdfe104a68eee 100644 --- a/tests/src/Helpers/DateTimeHelperTest.php +++ b/tests/src/Helpers/DateTimeHelperTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Helpers; +use DateInterval; use SimpleSAML\Module\accounting\Helpers\DateTimeHelper; use PHPUnit\Framework\TestCase; @@ -14,14 +15,14 @@ class DateTimeHelperTest extends TestCase { public function testCanConvertDateIntervalToSeconds(): void { - $interval = new \DateInterval('PT10S'); + $interval = new DateInterval('PT10S'); $this->assertSame(10, (new DateTimeHelper())->convertDateIntervalToSeconds($interval)); } public function testMinimumIntervalIsOneSecond(): void { - $interval = \DateInterval::createFromDateString('-10 seconds'); // Negative interval + $interval = DateInterval::createFromDateString('-10 seconds'); // Negative interval $this->assertSame(1, (new DateTimeHelper())->convertDateIntervalToSeconds($interval)); } diff --git a/tests/src/Helpers/FilesystemHelperTest.php b/tests/src/Helpers/FilesystemHelperTest.php index e6e76ab8221e7cd97cd931f465a2acfb3458cda5..afdf03118fb750691fd70e5aa7b994071ba28948 100644 --- a/tests/src/Helpers/FilesystemHelperTest.php +++ b/tests/src/Helpers/FilesystemHelperTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Helpers; use SimpleSAML\Module\accounting\Exceptions\InvalidValueException; diff --git a/tests/src/Helpers/HashHelperTest.php b/tests/src/Helpers/HashHelperTest.php index e0e620a9b35d3cf7e8fb709388281d9370365269..97778d344d5d41f572123d874858ceb82518d665 100644 --- a/tests/src/Helpers/HashHelperTest.php +++ b/tests/src/Helpers/HashHelperTest.php @@ -7,7 +7,6 @@ namespace SimpleSAML\Test\Module\accounting\Helpers; use SimpleSAML\Module\accounting\Helpers\ArrayHelper; use SimpleSAML\Module\accounting\Helpers\HashHelper; use PHPUnit\Framework\TestCase; -use SimpleSAML\Module\accounting\Services\HelpersManager; /** * @covers \SimpleSAML\Module\accounting\Helpers\HashHelper @@ -20,12 +19,12 @@ class HashHelperTest extends TestCase protected string $data; protected string $dataSha256; /** - * @var \int[][] + * @var int[][] */ protected array $unsortedArrayData; protected string $unsortedArraySha256; /** - * @var \int[][] + * @var int[][] */ protected array $sortedArrayData; protected string $sortedArrayDataSha256; diff --git a/tests/src/Helpers/InstanceBuilderUsingModuleConfigurationHelperTest.php b/tests/src/Helpers/InstanceBuilderUsingModuleConfigurationHelperTest.php index 63345edb3e418dadcc07be93790d4355498c8e22..7faea472dfcf7c9b7d6d3ebc721c39c3d30b6feb 100644 --- a/tests/src/Helpers/InstanceBuilderUsingModuleConfigurationHelperTest.php +++ b/tests/src/Helpers/InstanceBuilderUsingModuleConfigurationHelperTest.php @@ -1,14 +1,16 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Helpers; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\Exception; use SimpleSAML\Module\accounting\Helpers\InstanceBuilderUsingModuleConfigurationHelper; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Interfaces\BuildableUsingModuleConfigurationInterface; use SimpleSAML\Module\accounting\ModuleConfiguration; -use SimpleSAML\Module\accounting\Services\HelpersManager; /** * @covers \SimpleSAML\Module\accounting\Helpers\InstanceBuilderUsingModuleConfigurationHelper @@ -18,8 +20,8 @@ class InstanceBuilderUsingModuleConfigurationHelperTest extends TestCase protected BuildableUsingModuleConfigurationInterface $stub; /** @var class-string */ protected string $stubClass; - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; - protected \PHPUnit\Framework\MockObject\Stub $loggerStub; + protected Stub $moduleConfigurationStub; + protected Stub $loggerStub; protected function setUp(): void { @@ -38,6 +40,9 @@ class InstanceBuilderUsingModuleConfigurationHelperTest extends TestCase $this->loggerStub = $this->createStub(LoggerInterface::class); } + /** + * @throws Exception + */ public function testCanBuildClassInstance(): void { /** @psalm-suppress InvalidArgument */ diff --git a/tests/src/Helpers/ModuleRoutesHelperTest.php b/tests/src/Helpers/ModuleRoutesHelperTest.php index aa07c47da76c05a25980c69bbff698211f5c66b0..5698ed59c79c77e0c6ddf82c51bb892682ab660c 100644 --- a/tests/src/Helpers/ModuleRoutesHelperTest.php +++ b/tests/src/Helpers/ModuleRoutesHelperTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Helpers; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Helpers\ModuleRoutesHelper; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\ModuleConfiguration; @@ -16,7 +17,7 @@ class ModuleRoutesHelperTest extends TestCase { protected const BASE_URL = 'https://example.org/ssp/'; /** - * @var \PHPUnit\Framework\MockObject\Stub|HTTP + * @var Stub|HTTP */ protected $sspHttpUtilsStub; protected string $moduleUrl; diff --git a/tests/src/Helpers/RandomHelperTest.php b/tests/src/Helpers/RandomHelperTest.php index 538b3136906ca88b5744e959d252f5f57e665ab2..cfd0da18853a4a7d2bb899c1cce50f31a6a516f3 100644 --- a/tests/src/Helpers/RandomHelperTest.php +++ b/tests/src/Helpers/RandomHelperTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Helpers; use SimpleSAML\Module\accounting\Helpers\RandomHelper; diff --git a/tests/src/ModuleConfigurationTest.php b/tests/src/ModuleConfigurationTest.php index 50bc22290cc94da2e0769762d596448b3f460254..6c2fc0e622ce372b193565d9bd311f1b7c353aca 100644 --- a/tests/src/ModuleConfigurationTest.php +++ b/tests/src/ModuleConfigurationTest.php @@ -10,6 +10,7 @@ use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Stores; use SimpleSAML\Module\accounting\Trackers; +use stdClass; /** * @covers \SimpleSAML\Module\accounting\ModuleConfiguration @@ -59,6 +60,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsForInvalidConfig(): void { $this->expectException(InvalidConfigurationException::class); @@ -71,6 +75,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsForInvalidJobsStore(): void { $this->expectException(InvalidConfigurationException::class); @@ -104,6 +111,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsForNonStringAndNonArrayConnectionKey(): void { $this->expectException(InvalidConfigurationException::class); @@ -112,12 +122,15 @@ class ModuleConfigurationTest extends TestCase null, [ ModuleConfiguration::OPTION_CLASS_TO_CONNECTION_MAP => [ - 'invalid-object-value' => new \stdClass(), + 'invalid-object-value' => new stdClass(), ] ] ); } + /** + * @throws \Exception + */ public function testThrowsForNonMasterInArrayConnection(): void { $this->expectException(InvalidConfigurationException::class); @@ -199,6 +212,9 @@ class ModuleConfigurationTest extends TestCase $this->assertNull($this->moduleConfiguration->getJobRunnerMaximumExecutionTime()); } + /** + * @throws \Exception + */ public function testThrowsForNonStringJobRunnerMaximumExecutionTime(): void { $moduleConfiguration = new ModuleConfiguration( @@ -211,6 +227,9 @@ class ModuleConfigurationTest extends TestCase $moduleConfiguration->getJobRunnerMaximumExecutionTime(); } + /** + * @throws \Exception + */ public function testThrowsForInvalidStringJobRunnerMaximumExecutionTime(): void { $moduleConfiguration = new ModuleConfiguration( @@ -229,6 +248,9 @@ class ModuleConfigurationTest extends TestCase $this->assertSame(10, $this->moduleConfiguration->getJobRunnerShouldPauseAfterNumberOfJobsProcessed()); } + /** + * @throws \Exception + */ public function testCanGetNullForJobRunnerShouldPauseAfterNumberOfJobsProcessed(): void { $moduleConfiguration = new ModuleConfiguration( @@ -239,6 +261,9 @@ class ModuleConfigurationTest extends TestCase $this->assertNull($moduleConfiguration->getJobRunnerShouldPauseAfterNumberOfJobsProcessed()); } + /** + * @throws \Exception + */ public function testThrowsForNonIntegerJobRunnerShouldPauseAfterNumberOfJobsProcessed(): void { $moduleConfiguration = new ModuleConfiguration( @@ -251,6 +276,9 @@ class ModuleConfigurationTest extends TestCase $moduleConfiguration->getJobRunnerShouldPauseAfterNumberOfJobsProcessed(); } + /** + * @throws \Exception + */ public function testThrowsForNegativeIntegerJobRunnerShouldPauseAfterNumberOfJobsProcessed(): void { $moduleConfiguration = new ModuleConfiguration( @@ -263,6 +291,9 @@ class ModuleConfigurationTest extends TestCase $moduleConfiguration->getJobRunnerShouldPauseAfterNumberOfJobsProcessed(); } + /** + * @throws \Exception + */ public function testThrowsOnInvalidCronTag(): void { $this->expectException(InvalidConfigurationException::class); @@ -277,6 +308,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsOnInvalidDefaultDataTrackerAndProvider(): void { $this->expectException(InvalidConfigurationException::class); @@ -289,6 +323,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsOnInvalidAdditionalTrackers(): void { $this->expectException(InvalidConfigurationException::class); @@ -301,6 +338,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsOnNonStringAdditionalTracker(): void { $this->expectException(InvalidConfigurationException::class); @@ -313,6 +353,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsWhenClassHasNoConnectionParametersSet(): void { $this->expectException(InvalidConfigurationException::class); @@ -325,6 +368,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsForInvalidTrackerDataRetentionPolicy(): void { $this->expectException(InvalidConfigurationException::class); @@ -337,6 +383,9 @@ class ModuleConfigurationTest extends TestCase ); } + /** + * @throws \Exception + */ public function testThrowsForInvalidCronTagForTrackerDataRetentionPolicy(): void { $this->expectException(InvalidConfigurationException::class); diff --git a/tests/src/Providers/Builders/AuthenticationDataProviderBuilderTest.php b/tests/src/Providers/Builders/AuthenticationDataProviderBuilderTest.php index 497fd3a69221b9222a367ce3c6e70f7acaa03ad2..612351fdead76ecfc83f6497bb0894b189ef2c28 100644 --- a/tests/src/Providers/Builders/AuthenticationDataProviderBuilderTest.php +++ b/tests/src/Providers/Builders/AuthenticationDataProviderBuilderTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Providers\Builders; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\Exception; use SimpleSAML\Module\accounting\ModuleConfiguration; @@ -31,9 +32,9 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; */ class AuthenticationDataProviderBuilderTest extends TestCase { - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; + protected Stub $moduleConfigurationStub; - protected \PHPUnit\Framework\MockObject\Stub $loggerStub; + protected Stub $loggerStub; protected HelpersManager $helpersManager; protected function setUp(): void @@ -60,6 +61,9 @@ class AuthenticationDataProviderBuilderTest extends TestCase ); } + /** + * @throws Exception + */ public function testCanBuildDataProvider(): void { /** @psalm-suppress InvalidArgument */ diff --git a/tests/src/Services/HelpersManagerTest.php b/tests/src/Services/HelpersManagerTest.php index a199731970637389a04830557f170b4805735799..19915bbd4e19470121490a15191dbf4b47def8e1 100644 --- a/tests/src/Services/HelpersManagerTest.php +++ b/tests/src/Services/HelpersManagerTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Services; use SimpleSAML\Module\accounting\Helpers\ArrayHelper; diff --git a/tests/src/Services/JobRunner/RateLimiterTest.php b/tests/src/Services/JobRunner/RateLimiterTest.php index 19a98c64aa60f6ef32a6e0bf6a4c8855c3be0762..966609048606b28d972fa32a52c1b4c9fcb34498 100644 --- a/tests/src/Services/JobRunner/RateLimiterTest.php +++ b/tests/src/Services/JobRunner/RateLimiterTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Services\JobRunner; +use DateInterval; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Services\JobRunner\RateLimiter; @@ -26,18 +28,18 @@ class RateLimiterTest extends TestCase public function testCanDoPause(): void { $rateLimiter = new RateLimiter(); - $startTimeInSeconds = (new \DateTimeImmutable())->getTimestamp(); + $startTimeInSeconds = (new DateTimeImmutable())->getTimestamp(); $rateLimiter->doPause(); - $endTimeInSeconds = (new \DateTimeImmutable())->getTimestamp(); + $endTimeInSeconds = (new DateTimeImmutable())->getTimestamp(); $this->assertTrue(($endTimeInSeconds - $startTimeInSeconds) >= 1); } public function testCanSetMaxPause(): void { - $rateLimiter = new RateLimiter(new \DateInterval('PT1S')); + $rateLimiter = new RateLimiter(new DateInterval('PT1S')); $this->assertSame(1, $rateLimiter->getMaxPauseInSeconds()); - $splitSecondInterval = \DateInterval::createFromDateString('10000 microsecond'); // 10 milliseconds + $splitSecondInterval = DateInterval::createFromDateString('10000 microsecond'); // 10 milliseconds $rateLimiter = new RateLimiter($splitSecondInterval); $this->assertSame(1, $rateLimiter->getMaxPauseInSeconds()); $rateLimiter->doPause(); @@ -46,9 +48,9 @@ class RateLimiterTest extends TestCase public function testCanDoBackoffPause(): void { $rateLimiter = new RateLimiter(); - $startTimeInSeconds = (new \DateTimeImmutable())->getTimestamp(); + $startTimeInSeconds = (new DateTimeImmutable())->getTimestamp(); $rateLimiter->doBackoffPause(); - $endTimeInSeconds = (new \DateTimeImmutable())->getTimestamp(); + $endTimeInSeconds = (new DateTimeImmutable())->getTimestamp(); $this->assertTrue(($endTimeInSeconds - $startTimeInSeconds) >= 1); $this->assertTrue($rateLimiter->getCurrentBackoffPauseInSeconds() > 1); $rateLimiter->resetBackoffPause(); @@ -57,10 +59,10 @@ class RateLimiterTest extends TestCase public function testCanSetMaxBackoffPause(): void { - $rateLimiter = new RateLimiter(null, new \DateInterval('PT1S')); + $rateLimiter = new RateLimiter(null, new DateInterval('PT1S')); $this->assertSame(1, $rateLimiter->getMaxBackoffPauseInSeconds()); - $splitSecondInterval = \DateInterval::createFromDateString('10000 microsecond'); // 10 milliseconds - $rateLimiter = new \SimpleSAML\Module\accounting\Services\JobRunner\RateLimiter(null, $splitSecondInterval); + $splitSecondInterval = DateInterval::createFromDateString('10000 microsecond'); // 10 milliseconds + $rateLimiter = new RateLimiter(null, $splitSecondInterval); $this->assertSame(1, $rateLimiter->getMaxBackoffPauseInSeconds()); $rateLimiter->doBackoffPause(); } diff --git a/tests/src/Services/JobRunner/StateTest.php b/tests/src/Services/JobRunner/StateTest.php index 533030e6ec26da4c65dbfdc67239401e21b815fd..ff4c0b7ba9405ef342cbd9bd9e0faa3ec5b79533 100644 --- a/tests/src/Services/JobRunner/StateTest.php +++ b/tests/src/Services/JobRunner/StateTest.php @@ -1,7 +1,11 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Services\JobRunner; +use DateInterval; +use DateTimeImmutable; use SimpleSAML\Module\accounting\Services\JobRunner\State; use PHPUnit\Framework\TestCase; @@ -19,7 +23,7 @@ class StateTest extends TestCase public function testCanCreateInstance(): void { - $startedAt = $updatedAt = new \DateTimeImmutable(); + $startedAt = $updatedAt = new DateTimeImmutable(); $state = new State($this->jobRunnerId); $this->assertInstanceOf(State::class, $state); @@ -37,11 +41,11 @@ class StateTest extends TestCase public function testCanWorkWithTimestamps(): void { - $startedAt = $updatedAt = $endedAt = new \DateTimeImmutable(); + $startedAt = $updatedAt = $endedAt = new DateTimeImmutable(); $state = new State($this->jobRunnerId); $this->assertNull($state->getStartedAt()); - $this->assertInstanceOf(\DateTimeImmutable::class, $state->getUpdatedAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $state->getUpdatedAt()); $this->assertNull($state->getEndedAt()); $this->assertTrue($state->setStartedAt($startedAt)); @@ -78,11 +82,11 @@ class StateTest extends TestCase public function testCanCheckIfStateIsStale(): void { $state = new State($this->jobRunnerId); - $freshnessDuration = new \DateInterval('PT5M'); + $freshnessDuration = new DateInterval('PT5M'); $this->assertFalse($state->isStale($freshnessDuration)); - $dateTimeInHistory = new \DateTimeImmutable('-9 minutes'); + $dateTimeInHistory = new DateTimeImmutable('-9 minutes'); $state->setUpdatedAt($dateTimeInHistory); $this->assertTrue($state->isStale($freshnessDuration)); diff --git a/tests/src/Services/JobRunnerTest.php b/tests/src/Services/JobRunnerTest.php index ceddecc0c39a2ba53366c228814bb14116268c2a..04af8e49a012c3dc459de696fb8d24c7ae64942d 100644 --- a/tests/src/Services/JobRunnerTest.php +++ b/tests/src/Services/JobRunnerTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Services; +use DateInterval; +use DateTimeImmutable; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; @@ -13,6 +15,7 @@ use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; use SimpleSAML\Module\accounting\Entities\Interfaces\JobInterface; use SimpleSAML\Module\accounting\Exceptions\Exception; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Helpers\DateTimeHelper; use SimpleSAML\Module\accounting\Helpers\EnvironmentHelper; use SimpleSAML\Module\accounting\Helpers\RandomHelper; @@ -117,6 +120,9 @@ class JobRunnerTest extends TestCase $this->payloadStub = $this->createStub(Event::class); } + /** + * @throws Exception + */ public function testCanCreateInstance(): void { $this->randomHelperStub->method('getRandomInt')->willReturn(123); @@ -138,6 +144,10 @@ class JobRunnerTest extends TestCase ); } + /** + * @throws StoreException + * @throws Exception + */ public function testPreRunValidationFailsForSameJobRunnerId(): void { $this->randomHelperStub->method('getRandomInt')->willReturn(123); @@ -171,6 +181,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testPreRunValidationFailsForStaleState(): void { $this->randomHelperStub->method('getRandomInt')->willReturn(123); @@ -204,6 +218,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testPreRunValidationPassesWhenStateIsNull(): void { $this->randomHelperStub->method('getRandomInt')->willReturn(123); @@ -233,6 +251,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateRunConditionsFailsIfAnotherJobRunnerIsActive(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -267,6 +289,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testAssumeTrueOnJobRunnerActivityIfThrown(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -304,6 +330,9 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + */ public function testCanLogCacheClearingError(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -336,6 +365,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateRunConditionsSuccessIfStaleStateEncountered(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -374,20 +407,24 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testShouldRunCheckFailsIfMaximumExecutionTimeIsReached(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') ->willReturn(ModuleConfiguration\AccountingProcessingType::VALUE_ASYNCHRONOUS); $this->moduleConfigurationStub->method('getJobRunnerMaximumExecutionTime') - ->willReturn(new \DateInterval('PT1S')); + ->willReturn(new DateInterval('PT1S')); $this->randomHelperStub->method('getRandomInt')->willReturn(123); $this->helpersManagerStub->method('getRandomHelper')->willReturn($this->randomHelperStub); $this->cacheMock->method('get')->willReturn(null); - $this->stateStub->method('getStartedAt')->willReturn(new \DateTimeImmutable('-2 seconds')); + $this->stateStub->method('getStartedAt')->willReturn(new DateTimeImmutable('-2 seconds')); $this->cacheMock->expects($this->once())->method('delete'); @@ -412,13 +449,17 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanUseIniSettingForMaximumExecutionTime(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') ->willReturn(ModuleConfiguration\AccountingProcessingType::VALUE_ASYNCHRONOUS); $this->moduleConfigurationStub->method('getJobRunnerMaximumExecutionTime') - ->willReturn(new \DateInterval('PT20S')); + ->willReturn(new DateInterval('PT20S')); $this->randomHelperStub->method('getRandomInt')->willReturn(123); $this->helpersManagerStub->method('getRandomHelper')->willReturn($this->randomHelperStub); @@ -431,7 +472,7 @@ class JobRunnerTest extends TestCase $this->cacheMock->method('get')->willReturn(null); - $this->stateStub->method('getStartedAt')->willReturn(new \DateTimeImmutable('-30 seconds')); + $this->stateStub->method('getStartedAt')->willReturn(new DateTimeImmutable('-30 seconds')); $this->cacheMock->expects($this->once())->method('delete'); @@ -457,6 +498,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testShouldRunCheckFailsIfMaximumNumberOfProcessedJobsIsReached(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -492,6 +537,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateSelfStateFailsIfRunHasNotStartedButCachedStateExists(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -529,6 +578,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateSelfStateFailsIfRunHasStartedButCachedStateDoesNotExist(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -566,6 +619,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateSelfStateFailsIfRunHasStartedButDifferentJobRunnerIdEncountered(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -605,6 +662,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateSelfStateFailsIfRunHasStartedButStaleCachedStateEncountered(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -645,6 +706,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testValidateSelfStateFailsIfRunHasStartedButGracefulInterruptIsInitiated(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -686,6 +751,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanDoBackoffPauseIfNoJobsInCli(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -737,6 +806,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanBreakImmediatelyIfNoJobsInWeb(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -785,6 +858,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanProcessJob(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -849,6 +926,9 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + */ public function testCanLogCacheUpdateError(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -907,6 +987,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanPauseProcessingBasedOnConfiguration(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -976,6 +1060,10 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanMarkFailedJobOnError(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') @@ -1039,6 +1127,9 @@ class JobRunnerTest extends TestCase $jobRunner->run(); } + /** + * @throws StoreException + */ public function testThrowsOnAlreadyInitializedState(): void { $this->moduleConfigurationStub->method('getAccountingProcessingType') diff --git a/tests/src/Services/LoggerServiceTest.php b/tests/src/Services/LoggerServiceTest.php index 241dfeb4a106a5d05bb64ea84d048dc431dcd7e5..323c83237447b13883de44323b780833a820576c 100644 --- a/tests/src/Services/LoggerServiceTest.php +++ b/tests/src/Services/LoggerServiceTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Services; use SimpleSAML\Module\accounting\Services\Logger; diff --git a/tests/src/Stores/Bases/AbstractStoreTest.php b/tests/src/Stores/Bases/AbstractStoreTest.php index 5580ba7d68e59ff158034f425aac2a101f991d5f..bf839e0ba2799276aaf3d6aefeda0b273f963e7a 100644 --- a/tests/src/Stores/Bases/AbstractStoreTest.php +++ b/tests/src/Stores/Bases/AbstractStoreTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Bases; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Stores\Bases\AbstractStore; @@ -12,16 +15,13 @@ use PHPUnit\Framework\TestCase; */ class AbstractStoreTest extends TestCase { + protected AbstractStore $abstractStore; /** - * @var AbstractStore - */ - protected $abstractStore; - /** - * @var \PHPUnit\Framework\MockObject\Stub|ModuleConfiguration + * @var Stub|ModuleConfiguration */ protected $moduleConfigurationStub; /** - * @var \PHPUnit\Framework\MockObject\Stub|LoggerInterface + * @var Stub|LoggerInterface */ protected $loggerStub; diff --git a/tests/src/Stores/Bases/DoctrineDbal/AbstractRawEntityTest.php b/tests/src/Stores/Bases/DoctrineDbal/AbstractRawEntityTest.php index 9f8ae4cf8bc0acc63e322a7c73a7875d52932652..768798786ff189f6add12888fff054ca96c99025 100644 --- a/tests/src/Stores/Bases/DoctrineDbal/AbstractRawEntityTest.php +++ b/tests/src/Stores/Bases/DoctrineDbal/AbstractRawEntityTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Bases\DoctrineDbal; use Doctrine\DBAL\Platforms\AbstractPlatform; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\Stores\Bases\DoctrineDbal\AbstractRawEntity; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ use SimpleSAML\Test\Module\accounting\Constants\DateTime; class AbstractRawEntityTest extends TestCase { /** - * @var AbstractPlatform|AbstractPlatform&\PHPUnit\Framework\MockObject\Stub|\PHPUnit\Framework\MockObject\Stub + * @var AbstractPlatform|Stub */ protected $abstractPlatformStub; /** diff --git a/tests/src/Stores/Builders/DataStoreBuilderTest.php b/tests/src/Stores/Builders/DataStoreBuilderTest.php index c007b8897c6c638c953ba2c0aeeda2beb875e0df..8a51c7b82e07e7187f0c79d54ce7dd6ad4026739 100644 --- a/tests/src/Stores/Builders/DataStoreBuilderTest.php +++ b/tests/src/Stores/Builders/DataStoreBuilderTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Builders; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\ModuleConfiguration; @@ -27,8 +30,8 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; */ class DataStoreBuilderTest extends TestCase { - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; - protected \PHPUnit\Framework\MockObject\Stub $loggerStub; + protected Stub $moduleConfigurationStub; + protected Stub $loggerStub; protected DataStoreBuilder $dataStoreBuilder; protected HelpersManager $helpersManager; @@ -50,6 +53,9 @@ class DataStoreBuilderTest extends TestCase ); } + /** + * @throws StoreException + */ public function testCanBuildDataStore(): void { $this->assertInstanceOf(Store::class, $this->dataStoreBuilder->build(Store::class)); diff --git a/tests/src/Stores/Builders/JobsStoreBuilderTest.php b/tests/src/Stores/Builders/JobsStoreBuilderTest.php index 02166c883e30d3d6168705053a1c85ecce05d78d..47bb15e896d7c74055702e781e7e808a46a218c6 100644 --- a/tests/src/Stores/Builders/JobsStoreBuilderTest.php +++ b/tests/src/Stores/Builders/JobsStoreBuilderTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Builders; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\StoreException; @@ -31,8 +32,8 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; */ class JobsStoreBuilderTest extends TestCase { - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; - protected \PHPUnit\Framework\MockObject\Stub $loggerStub; + protected Stub $moduleConfigurationStub; + protected Stub $loggerStub; protected JobsStoreBuilder $jobsStoreBuilder; protected HelpersManager $helpersManager; @@ -55,6 +56,9 @@ class JobsStoreBuilderTest extends TestCase ); } + /** + * @throws StoreException + */ public function testCanBuildJobsStore(): void { $this->assertInstanceOf(Store::class, $this->jobsStoreBuilder->build(Store::class)); diff --git a/tests/src/Stores/Connections/Bases/AbstractMigratorTest.php b/tests/src/Stores/Connections/Bases/AbstractMigratorTest.php index 0fb3fda9f697c817da1f36fe9d763f1fc89f091e..3a33be72bb515f9d9c20795ab43ed7ea1832864d 100644 --- a/tests/src/Stores/Connections/Bases/AbstractMigratorTest.php +++ b/tests/src/Stores/Connections/Bases/AbstractMigratorTest.php @@ -5,6 +5,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Connections\Bases; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Exception; +use PHPUnit\Framework\MockObject\MockObject; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\Logger; @@ -33,13 +36,12 @@ class AbstractMigratorTest extends TestCase protected Connection $connection; protected AbstractSchemaManager $schemaManager; protected string $tableName; + protected MockObject $loggerServiceMock; + protected ModuleConfiguration $moduleConfiguration; /** - * @var \PHPUnit\Framework\MockObject\MockObject + * @throws \Doctrine\DBAL\Exception */ - protected $loggerServiceMock; - protected ModuleConfiguration $moduleConfiguration; - protected function setUp(): void { parent::setUp(); @@ -54,6 +56,9 @@ class AbstractMigratorTest extends TestCase $this->moduleConfiguration = new ModuleConfiguration('module_accounting.php'); } + /** + * @throws StoreException + */ public function testCanGatherMigrationClassesFromDirectory(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ @@ -68,6 +73,11 @@ class AbstractMigratorTest extends TestCase $this->assertTrue(in_array($namespace . '\Version20220601000000CreateJobTable', $migrationClasses)); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + * @throws MigrationException + */ public function testCanRunMigrationClasses(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ @@ -90,6 +100,9 @@ class AbstractMigratorTest extends TestCase $this->assertTrue($this->schemaManager->tablesExist($jobsTableName)); } + /** + * @throws StoreException + */ public function testCanGatherOnlyMigrationClasses(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ @@ -101,13 +114,16 @@ class AbstractMigratorTest extends TestCase $this->assertEmpty($migrator->gatherMigrationClassesFromDirectory($directory, $namespace)); } + /** + * @throws StoreException + */ public function testMigrationExceptionHaltsExecution(): void { $migration = new class ($this->connection) extends AbstractMigration { public function run(): void { - throw new \Exception('Something went wrong.'); + throw new Exception('Something went wrong.'); } public function revert(): void @@ -123,6 +139,9 @@ class AbstractMigratorTest extends TestCase $migrator->runMigrationClasses([get_class($migration)]); } + /** + * @throws StoreException + */ public function testCanGetNonImplementedMigrationClasses(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ @@ -141,6 +160,9 @@ class AbstractMigratorTest extends TestCase )); } + /** + * @throws StoreException + */ public function testCanFindOutIfNonImplementedMigrationClassesExist(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ @@ -154,6 +176,10 @@ class AbstractMigratorTest extends TestCase )); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testCanRunNonImplementedMigrationClasses(): void { /** @psalm-suppress InvalidArgument Using mock instead of Logger instance */ diff --git a/tests/src/Stores/Connections/DoctrineDbal/Bases/AbstractMigrationTest.php b/tests/src/Stores/Connections/DoctrineDbal/Bases/AbstractMigrationTest.php index 68db88bdeed0a9453949a55c4ae639363b2e008f..8709e6e6594be9410aee6a8528b647c1413d136c 100644 --- a/tests/src/Stores/Connections/DoctrineDbal/Bases/AbstractMigrationTest.php +++ b/tests/src/Stores/Connections/DoctrineDbal/Bases/AbstractMigrationTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Connections\DoctrineDbal\Bases; +use Exception; use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Bases\AbstractMigration; use PHPUnit\Framework\TestCase; @@ -24,6 +27,9 @@ class AbstractMigrationTest extends TestCase $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); } + /** + * @throws StoreException + */ public function testCanInstantiateMigrationClass(): void { $this->assertInstanceOf( @@ -50,7 +56,7 @@ class AbstractMigrationTest extends TestCase $migration = new class ($this->connection) extends AbstractMigration { public function run(): void { - throw $this->prepareGenericMigrationException('test', new \Exception('test')); + throw $this->prepareGenericMigrationException('test', new Exception('test')); } public function revert(): void @@ -72,7 +78,7 @@ class AbstractMigrationTest extends TestCase $migration = new class ($connectionStub) extends AbstractMigration { public function run(): void { - throw new \Exception($this->preparePrefixedTableName('table-name')); + throw new Exception($this->preparePrefixedTableName('table-name')); } public function revert(): void { @@ -85,7 +91,7 @@ class AbstractMigrationTest extends TestCase try { $migration->run(); - } catch (\Exception $exception) { + } catch (Exception $exception) { $this->assertStringContainsString('prefix-connection', $exception->getMessage()); } } @@ -99,7 +105,7 @@ class AbstractMigrationTest extends TestCase $migration = new class ($connectionStub) extends AbstractMigration { public function run(): void { - throw new \Exception($this->getLocalTablePrefix()); + throw new Exception($this->getLocalTablePrefix()); } public function revert(): void { @@ -108,7 +114,7 @@ class AbstractMigrationTest extends TestCase try { $migration->run(); - } catch (\Exception $exception) { + } catch (Exception $exception) { $this->assertEmpty($exception->getMessage()); } } diff --git a/tests/src/Stores/Connections/DoctrineDbal/ConnectionTest.php b/tests/src/Stores/Connections/DoctrineDbal/ConnectionTest.php index cbc1f869dfb10fdabf9299c0d265eec401388b63..98ff0dd1fcfc7afde76d1e3bc10e2160cb421d11 100644 --- a/tests/src/Stores/Connections/DoctrineDbal/ConnectionTest.php +++ b/tests/src/Stores/Connections/DoctrineDbal/ConnectionTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Connections\DoctrineDbal; use PHPUnit\Framework\TestCase; diff --git a/tests/src/Stores/Connections/DoctrineDbal/FactoryTest.php b/tests/src/Stores/Connections/DoctrineDbal/FactoryTest.php index 07dab2dbfcd72e2a5b750e9edec9b0a581d9c290..bd91d5cf096cb680977838421954268743347299 100644 --- a/tests/src/Stores/Connections/DoctrineDbal/FactoryTest.php +++ b/tests/src/Stores/Connections/DoctrineDbal/FactoryTest.php @@ -1,7 +1,11 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Connections\DoctrineDbal; +use PHPUnit\Framework\MockObject\MockObject; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\Logger; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; @@ -22,10 +26,7 @@ class FactoryTest extends TestCase { protected ModuleConfiguration $moduleConfiguration; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - protected $loggerServiceMock; + protected MockObject $loggerServiceMock; protected function setUp(): void { @@ -42,6 +43,9 @@ class FactoryTest extends TestCase $this->assertInstanceOf(Connection::class, $factory->buildConnection('doctrine_dbal_pdo_sqlite')); } + /** + * @throws StoreException + */ public function testCanBuildMigrator(): void { /** @psalm-suppress InvalidArgument */ diff --git a/tests/src/Stores/Connections/DoctrineDbal/MigratorTest.php b/tests/src/Stores/Connections/DoctrineDbal/MigratorTest.php index 907e83c6b66d26e1865453145d63b11e1dc02729..223dfc3ad35b1d93a8fd1df471f86994afb8cb14 100644 --- a/tests/src/Stores/Connections/DoctrineDbal/MigratorTest.php +++ b/tests/src/Stores/Connections/DoctrineDbal/MigratorTest.php @@ -1,12 +1,17 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Connections\DoctrineDbal; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Query\QueryBuilder; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Doctrine\DBAL\Schema\AbstractSchemaManager; use SimpleSAML\Module\accounting\Exceptions\InvalidValueException; use SimpleSAML\Module\accounting\Exceptions\StoreException; +use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\Logger; use SimpleSAML\Module\accounting\Stores\Connections\Bases\AbstractMigrator; @@ -36,12 +41,12 @@ class MigratorTest extends TestCase protected AbstractSchemaManager $schemaManager; protected string $tableName; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - protected $loggerServiceMock; + protected MockObject $loggerServiceMock; protected ModuleConfiguration $moduleConfiguration; + /** + * @throws Exception + */ protected function setUp(): void { parent::setUp(); @@ -56,6 +61,10 @@ class MigratorTest extends TestCase $this->moduleConfiguration = new ModuleConfiguration('module_accounting.php'); } + /** + * @throws StoreException + * @throws Exception + */ public function testCanCreateMigrationsTable(): void { $this->assertFalse($this->schemaManager->tablesExist([$this->tableName])); @@ -71,6 +80,9 @@ class MigratorTest extends TestCase $this->assertTrue($this->schemaManager->tablesExist([$this->tableName])); } + /** + * @throws StoreException + */ public function testRunningMigratorSetupMultipleTimesLogsWarning(): void { $this->loggerServiceMock @@ -87,6 +99,11 @@ class MigratorTest extends TestCase $migrator->runSetup(); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanRunMigrationClasses(): void { /** @psalm-suppress InvalidArgument */ @@ -102,6 +119,10 @@ class MigratorTest extends TestCase $this->assertTrue($this->schemaManager->tablesExist($tableNameJobs)); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testCanOnlyRunDoctrineDbalMigrationClasses(): void { $migration = new class implements MigrationInterface { @@ -123,6 +144,10 @@ class MigratorTest extends TestCase $migrator->runMigrationClasses([get_class($migration)]); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testCanGetImplementedMigrationClasses(): void { /** @psalm-suppress InvalidArgument */ @@ -143,7 +168,7 @@ class MigratorTest extends TestCase public function testThrowsStoreExceptionOnInitialization(): void { $dbalStub = $this->createStub(\Doctrine\DBAL\Connection::class); - $dbalStub->method('createSchemaManager')->willThrowException(new \Doctrine\DBAL\Exception('test')); + $dbalStub->method('createSchemaManager')->willThrowException(new Exception('test')); $connectionStub = $this->createStub(Connection::class); $connectionStub->method('dbal')->willReturn($dbalStub); @@ -153,11 +178,14 @@ class MigratorTest extends TestCase (new Migrator($connectionStub, $this->loggerServiceMock)); } + /** + * @throws StoreException + */ public function testThrowsStoreExceptionOnNeedsSetup(): void { $schemaManagerStub = $this->createStub(AbstractSchemaManager::class); $schemaManagerStub->method('tablesExist') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $dbalStub = $this->createStub(\Doctrine\DBAL\Connection::class); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $connectionStub = $this->createStub(Connection::class); @@ -171,6 +199,9 @@ class MigratorTest extends TestCase $migrator->needsSetup(); } + /** + * @throws StoreException + */ public function testThrowsStoreExceptionOnCreateMigrationsTable(): void { $schemaManagerStub = $this->createStub(AbstractSchemaManager::class); @@ -189,11 +220,15 @@ class MigratorTest extends TestCase $migrator->runSetup(); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testThrowsStoreExceptionOnMarkingImplementedClass(): void { $queryBuilderStub = $this->createStub(QueryBuilder::class); $queryBuilderStub->method('insert') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $dbalStub = $this->createStub(\Doctrine\DBAL\Connection::class); $dbalStub->method('createQueryBuilder')->willReturn($queryBuilderStub); $connectionStub = $this->createStub(Connection::class); @@ -213,7 +248,7 @@ class MigratorTest extends TestCase { $schemaManagerStub = $this->createStub(AbstractSchemaManager::class); $dbalStub = $this->createStub(\Doctrine\DBAL\Connection::class); - $dbalStub->method('createQueryBuilder')->willThrowException(new \Doctrine\DBAL\Exception('test')); + $dbalStub->method('createQueryBuilder')->willThrowException(new Exception('test')); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $connectionStub = $this->createStub(Connection::class); $connectionStub->method('dbal')->willReturn($dbalStub); diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/HashDecoratedStateTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/HashDecoratedStateTest.php index 23cb877c07e19c1100077af13a76191ae585fdd0..95861de836376e7478b74c120a43dd8b62f573c8 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/HashDecoratedStateTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/HashDecoratedStateTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Entities\Authentication\State; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\HashDecoratedState; use PHPUnit\Framework\TestCase; @@ -17,7 +18,7 @@ use PHPUnit\Framework\TestCase; class HashDecoratedStateTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\Stub|State|State&\PHPUnit\Framework\MockObject\Stub + * @var Stub|State */ protected $stateStub; protected string $identityProviderEntityId; diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTableTest.php index 2b99a6106c635b609e386f119f3f3ee5b733d47f..53c288b8ee126a2c056e0f310f57140f94573daa 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000000CreateIdpTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000000CreateIdpTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000000CreateIdpTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000000CreateIdpTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000000CreateIdpTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000000CreateIdpTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTableTest.php index 525d7ef8226b7848679136175706122fcc92842f..6505b8c6bab1f4d24539e3fc7f10b99b46515c68 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000100CreateIdpVersionTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000100CreateIdpVersionTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000100CreateIdpVersionTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000100CreateIdpVersionTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000100CreateIdpVersionTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000100CreateIdpVersionTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTableTest.php index 11d7874bb33138093b49fb518f595dd9e8350c06..fd6506f1d65cd19b8f4f856b3765527bd6c907b6 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000200CreateSpTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000200CreateSpTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000200CreateSpTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000200CreateSpTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000200CreateSpTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000200CreateSpTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTableTest.php index a839507c55379830055302d14a59ad639c16b344..f51a394fe36b190dcf97cf9124b036c39fc781ad 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000300CreateSpVersionTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000300CreateSpVersionTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000300CreateSpVersionTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000300CreateSpVersionTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000300CreateSpVersionTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000300CreateSpVersionTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTableTest.php index eca699c62deb3ea3a84fa044b90ba0b58b59cbe0..1631c0843a031680df53d25aa3a753d2a9fab4cb 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000400CreateUserTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000400CreateUserTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000400CreateUserTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000400CreateUserTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000400CreateUserTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000400CreateUserTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTableTest.php index 42384894bdc8596fbcc51848d600c09ec02c112a..4c99e35a32950a7290bd1117b8055a2b1b6e2ae1 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000500CreateUserVersionTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000500CreateUserVersionTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000500CreateUserVersionTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000500CreateUserVersionTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000500CreateUserVersionTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000500CreateUserVersionTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTableTest.php index ce214e658f70dbdeb91a971cc25c95f7769a7ed5..61b3f2611688775875c6241ed746824aafd77cb3 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000600CreateIdpSpUserVersionTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000600CreateIdpSpUserVersionTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000600CreateIdpSpUserVersionTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -45,11 +58,14 @@ class Version20220801000600CreateIdpSpUserVersionTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -60,10 +76,13 @@ class Version20220801000600CreateIdpSpUserVersionTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -74,6 +93,9 @@ class Version20220801000600CreateIdpSpUserVersionTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTableTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTableTest.php index 004b1923c03af384e30e1e941861fdddd665f20f..12d0b922421ff49918ddaaaf6e1ca67aa65f4852 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTableTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/Migrations/Version20220801000700CreateAuthenticationEventTableTest.php @@ -1,8 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use PHPUnit\Framework\MockObject\Stub; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use PHPUnit\Framework\TestCase; @@ -17,12 +22,15 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220801000700CreateAuthenticationEventTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; - protected \PHPUnit\Framework\MockObject\Stub $connectionStub; - protected \PHPUnit\Framework\MockObject\Stub $dbalStub; - protected \PHPUnit\Framework\MockObject\Stub $schemaManagerStub; + protected Stub $connectionStub; + protected Stub $dbalStub; + protected Stub $schemaManagerStub; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -34,6 +42,11 @@ class Version20220801000700CreateAuthenticationEventTableTest extends TestCase $this->schemaManagerStub = $this->createStub(AbstractSchemaManager::class); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -44,11 +57,14 @@ class Version20220801000700CreateAuthenticationEventTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $this->connectionStub->method('preparePrefixedTableName')->willReturn($this->tableName); $this->schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -58,10 +74,13 @@ class Version20220801000700CreateAuthenticationEventTableTest extends TestCase $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $this->schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $this->dbalStub->method('createSchemaManager')->willReturn($this->schemaManagerStub); $this->connectionStub->method('dbal')->willReturn($this->dbalStub); @@ -71,6 +90,9 @@ class Version20220801000700CreateAuthenticationEventTableTest extends TestCase $migration->revert(); } + /** + * @throws StoreException + */ public function testRunThrowsOnIvalidTableNameIdp(): void { $this->connectionStub->method('preparePrefixedTableName') diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivityTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivityTest.php index 5c9febc08f268e4dd751e41f9cd521d596fbb991..a672fcb2ddaefc43f58db7e5cc481ddba1f0b9ba 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivityTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawActivityTest.php @@ -1,8 +1,12 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\RawActivity; use PHPUnit\Framework\TestCase; @@ -28,7 +32,7 @@ class RawActivityTest extends TestCase protected array $rawRow; /** - * @var AbstractPlatform|AbstractPlatform&\PHPUnit\Framework\MockObject\Stub|\PHPUnit\Framework\MockObject\Stub + * @var AbstractPlatform|Stub */ protected $abstractPlatformStub; @@ -62,7 +66,7 @@ class RawActivityTest extends TestCase /** @psalm-suppress PossiblyInvalidArgument */ $rawActivity = new RawActivity($this->rawRow, $this->abstractPlatformStub); - $this->assertInstanceOf(\DateTimeImmutable::class, $rawActivity->getHappenedAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $rawActivity->getHappenedAt()); $this->assertSame($this->serviceProviderMetadata, $rawActivity->getServiceProviderMetadata()); $this->assertSame($this->userAttributes, $rawActivity->getUserAttributes()); $this->assertSame($this->clientIpAddress, $rawActivity->getClientIpAddress()); diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProviderTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProviderTest.php index 68fe4ed768439f1b39228591cdb6e8ef1c898d84..3da4ab6484afa412d679a3ee5a0cbef9b9052cc9 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProviderTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RawConnectedServiceProviderTest.php @@ -1,8 +1,12 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use PHPUnit\Framework\MockObject\Stub; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store\RawConnectedServiceProvider; use PHPUnit\Framework\TestCase; @@ -28,7 +32,7 @@ class RawConnectedServiceProviderTest extends TestCase protected array $userAttributes; protected array $rawRow; /** - * @var AbstractPlatform|AbstractPlatform&\PHPUnit\Framework\MockObject\Stub|\PHPUnit\Framework\MockObject\Stub + * @var AbstractPlatform|Stub */ protected $abstractPlatformStub; protected string $dateTimeFormat; @@ -73,12 +77,12 @@ class RawConnectedServiceProviderTest extends TestCase $rawConnectedServiceProvider = new RawConnectedServiceProvider($this->rawRow, $this->abstractPlatformStub); $this->assertSame($this->numberOfAuthentications, $rawConnectedServiceProvider->getNumberOfAuthentications()); - $this->assertInstanceOf(\DateTimeImmutable::class, $rawConnectedServiceProvider->getLastAuthenticationAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $rawConnectedServiceProvider->getLastAuthenticationAt()); $this->assertSame( $this->lastAuthenticationAt, $rawConnectedServiceProvider->getLastAuthenticationAt()->format($this->dateTimeFormat) ); - $this->assertInstanceOf(\DateTimeImmutable::class, $rawConnectedServiceProvider->getFirstAuthenticationAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $rawConnectedServiceProvider->getFirstAuthenticationAt()); $this->assertSame( $this->firstAuthenticationAt, $rawConnectedServiceProvider->getFirstAuthenticationAt()->format($this->dateTimeFormat) diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RepositoryTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RepositoryTest.php index 63144f4399de5686a7c2eb91673614d5cb7e6018..80b1137afae1445d20fddb5ac45c32736fefe732 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RepositoryTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/Store/RepositoryTest.php @@ -4,8 +4,13 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; +use DateInterval; +use DateTimeImmutable; +use Exception; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Exceptions\StoreException; +use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Stores\Connections\Bases\AbstractMigrator; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; @@ -41,7 +46,7 @@ class RepositoryTest extends TestCase protected Connection $connection; protected \Doctrine\DBAL\Connection $dbal; /** - * @var \PHPUnit\Framework\MockObject\Stub|LoggerInterface|LoggerInterface&\PHPUnit\Framework\MockObject\Stub + * @var Stub|LoggerInterface */ protected $loggerStub; protected Migrator $migrator; @@ -57,15 +62,19 @@ class RepositoryTest extends TestCase protected string $userAttributes; protected string $userAttributesHash; protected Repository $repository; - protected \DateTimeImmutable $createdAt; + protected DateTimeImmutable $createdAt; /** - * @var \PHPUnit\Framework\MockObject\Stub|Connection|Connection&\PHPUnit\Framework\MockObject\Stub + * @var Stub|Connection */ protected $connectionStub; protected string $spEntityIdHash; protected string $spMetadata; protected string $clientIpAddress; + /** + * @throws StoreException + * @throws MigrationException + */ protected function setUp(): void { // For stubbing. @@ -108,7 +117,7 @@ class RepositoryTest extends TestCase $this->userAttributes = 'user-attributes'; $this->userAttributesHash = 'user-attributes-hash'; - $this->createdAt = new \DateTimeImmutable(); + $this->createdAt = new DateTimeImmutable(); $this->clientIpAddress = '123.123.123.123'; } @@ -120,6 +129,10 @@ class RepositoryTest extends TestCase ); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanInsertAndGetIdp(): array { $this->repository->insertIdp($this->idpEntityId, $this->idpEntityIdHash, $this->createdAt); @@ -150,7 +163,7 @@ class RepositoryTest extends TestCase public function testGetIdpThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); @@ -159,6 +172,9 @@ class RepositoryTest extends TestCase /** * @depends testCanInsertAndGetIdp + * @throws StoreException + * @throws StoreException + * @throws \Doctrine\DBAL\Exception */ public function testCanInsertAndGetIdpVersion(array $idpResult): array { @@ -191,13 +207,17 @@ class RepositoryTest extends TestCase public function testGetIdpVersionThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); $repository->getIdpVersion(1, $this->idpMetadataHash); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanInsertAndGetSp(): array { $this->repository->insertSp($this->spEntityId, $this->spEntityIdHash, $this->createdAt); @@ -227,7 +247,7 @@ class RepositoryTest extends TestCase public function testGetSpThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); @@ -236,6 +256,9 @@ class RepositoryTest extends TestCase /** * @depends testCanInsertAndGetSp + * @throws StoreException + * @throws StoreException + * @throws \Doctrine\DBAL\Exception */ public function testCanInsertAndGetSpVersion(array $spResult): array { @@ -268,13 +291,17 @@ class RepositoryTest extends TestCase public function testGetSpVersionThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); $repository->getSpVersion(1, $this->spMetadataHash); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanInsertAndGetUser(): array { $this->repository->insertUser($this->userIdentifier, $this->userIdentifierHash, $this->createdAt); @@ -303,7 +330,7 @@ class RepositoryTest extends TestCase public function testGetUserThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); @@ -312,6 +339,9 @@ class RepositoryTest extends TestCase /** * @depends testCanInsertAndGetUser + * @throws StoreException + * @throws StoreException + * @throws \Doctrine\DBAL\Exception */ public function testCanInsertAndGetUserVersion(array $userResult): array { @@ -349,7 +379,7 @@ class RepositoryTest extends TestCase public function testGetUserVersionThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); @@ -360,6 +390,9 @@ class RepositoryTest extends TestCase * @depends testCanInsertAndGetIdpVersion * @depends testCanInsertAndGetSpVersion * @depends testCanInsertAndGetUserVersion + * @throws StoreException + * @throws StoreException + * @throws \Doctrine\DBAL\Exception */ public function testCanInsertAndGetIdpSpUserVersion( array $idpVersionResult, @@ -403,7 +436,7 @@ class RepositoryTest extends TestCase public function testGetIdpSpUserVersionThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); @@ -412,12 +445,17 @@ class RepositoryTest extends TestCase /** * @depends testCanInsertAndGetIdpSpUserVersion + * @throws \Doctrine\DBAL\Exception + * @throws \Doctrine\DBAL\Exception + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + * @throws \Doctrine\DBAL\Exception */ public function testCanInsertAuthenticationEvent(array $idpSpUserVersionResult): void { $idpSpUserVersionId = (int)$idpSpUserVersionResult[Store\TableConstants::TABLE_IDP_SP_USER_VERSION_COLUMN_NAME_ID]; - $createdAt = $happenedAt = new \DateTimeImmutable(); + $createdAt = $happenedAt = new DateTimeImmutable(); $authenticationEventCounterQueryBuilder = $this->connection->dbal()->createQueryBuilder(); $authenticationEventCounterQueryBuilder->select('COUNT(id) as authenticationEventCount') @@ -436,13 +474,17 @@ class RepositoryTest extends TestCase public function testInsertAuthenticationEventThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); $repository->insertAuthenticationEvent(1, $this->createdAt); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanGetConnectedServiceProviders(): void { $this->repository->insertIdp($this->idpEntityId, $this->idpEntityIdHash, $this->createdAt); @@ -485,7 +527,7 @@ class RepositoryTest extends TestCase $resultArray = $this->repository->getConnectedServiceProviders($this->userIdentifierHash); $this->assertCount(1, $resultArray); - $this->assertSame( + $this->assertEquals( '1', $resultArray[$this->spEntityId] [Store\TableConstants::ENTITY_CONNECTED_ORGANIZATION_COLUMN_NAME_NUMBER_OF_AUTHENTICATIONS] @@ -512,7 +554,7 @@ class RepositoryTest extends TestCase ); $resultArray = $this->repository->getConnectedServiceProviders($this->userIdentifierHash); $this->assertCount(1, $resultArray); - $this->assertSame( + $this->assertEquals( '2', $resultArray[$this->spEntityId] [Store\TableConstants::ENTITY_CONNECTED_ORGANIZATION_COLUMN_NAME_NUMBER_OF_AUTHENTICATIONS] @@ -555,7 +597,7 @@ class RepositoryTest extends TestCase $resultArray = $this->repository->getConnectedServiceProviders($this->userIdentifierHash); $this->assertCount(2, $resultArray); - $this->assertSame( + $this->assertEquals( '1', $resultArray[$spEntityIdNew] [Store\TableConstants::ENTITY_CONNECTED_ORGANIZATION_COLUMN_NAME_NUMBER_OF_AUTHENTICATIONS] @@ -594,7 +636,7 @@ class RepositoryTest extends TestCase $resultArray = $this->repository->getConnectedServiceProviders($this->userIdentifierHash); $this->assertCount(2, $resultArray); - $this->assertSame( + $this->assertEquals( '2', $resultArray[$spEntityIdNew] [Store\TableConstants::ENTITY_CONNECTED_ORGANIZATION_COLUMN_NAME_NUMBER_OF_AUTHENTICATIONS] @@ -621,13 +663,17 @@ class RepositoryTest extends TestCase public function testGetConnectedServiceProvidersThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); $repository->getConnectedServiceProviders($this->userIdentifierHash); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanGetActivity(): void { $this->repository->insertIdp($this->idpEntityId, $this->idpEntityIdHash, $this->createdAt); @@ -721,13 +767,17 @@ class RepositoryTest extends TestCase public function testGetActivityThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); $repository->getActivity($this->userIdentifierHash, 10, 0); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + */ public function testCanDeleteAuthenticationEventsOlderThan(): void { $this->repository->insertIdp($this->idpEntityId, $this->idpEntityIdHash, $this->createdAt); @@ -770,7 +820,7 @@ class RepositoryTest extends TestCase $resultArray = $this->repository->getActivity($this->userIdentifierHash, 10, 0); $this->assertCount(1, $resultArray); - $dateTimeInFuture = $this->createdAt->add(new \DateInterval('P1D')); + $dateTimeInFuture = $this->createdAt->add(new DateInterval('P1D')); $this->repository->deleteAuthenticationEventsOlderThan($dateTimeInFuture); @@ -780,10 +830,10 @@ class RepositoryTest extends TestCase public function testDeleteAuthenticationEventsOlderThanThrowsOnInvalidDbal(): void { - $this->connectionStub->method('dbal')->willThrowException(new \Exception('test')); + $this->connectionStub->method('dbal')->willThrowException(new Exception('test')); $repository = new Repository($this->connectionStub, $this->loggerStub); $this->expectException(StoreException::class); - $repository->deleteAuthenticationEventsOlderThan(new \DateTimeImmutable()); + $repository->deleteAuthenticationEventsOlderThan(new DateTimeImmutable()); } } diff --git a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/StoreTest.php b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/StoreTest.php index 8910b95cb28b90cb2d2387dd057e7d13d929e110..3af28aa7a6541bb28645da3f548ac7f72cfcc3dd 100644 --- a/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/StoreTest.php +++ b/tests/src/Stores/Data/Authentication/DoctrineDbal/Versioned/StoreTest.php @@ -4,11 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned; +use DateTimeImmutable; use Doctrine\DBAL\Result; +use Exception; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Authentication\State; use SimpleSAML\Module\accounting\Exceptions\StoreException; +use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Exceptions\UnexpectedValueException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; @@ -61,26 +66,29 @@ use SimpleSAML\Test\Module\accounting\Constants\StateArrays; */ class StoreTest extends TestCase { - protected \PHPUnit\Framework\MockObject\Stub $moduleConfigurationStub; + protected Stub $moduleConfigurationStub; protected Migrator $migrator; - protected \PHPUnit\Framework\MockObject\Stub $factoryStub; + protected Stub $factoryStub; protected Connection $connection; protected State $state; protected Event $authenticationEvent; protected Store\HashDecoratedState $hashDecoratedState; /** - * @var \PHPUnit\Framework\MockObject\MockObject|Store\Repository + * @var MockObject|Store\Repository */ protected $repositoryMock; /** - * @var Result|\PHPUnit\Framework\MockObject\Stub + * @var Result|Stub */ protected $resultStub; /** - * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + * @var MockObject|LoggerInterface */ protected $loggerMock; + /** + * @throws StoreException + */ protected function setUp(): void { $connectionParams = ConnectionParameters::DBAL_SQLITE_MEMORY; @@ -110,6 +118,9 @@ class StoreTest extends TestCase $this->resultStub = $this->createStub(Result::class); } + /** + * @throws StoreException + */ public function testCanConstructInstance(): void { /** @psalm-suppress InvalidArgument */ @@ -125,6 +136,9 @@ class StoreTest extends TestCase ); } + /** + * @throws StoreException + */ public function testCanBuildInstance(): void { /** @psalm-suppress InvalidArgument */ @@ -134,6 +148,11 @@ class StoreTest extends TestCase ); } + /** + * @throws StoreException + * @throws \Doctrine\DBAL\Exception + * @throws MigrationException + */ public function testCanPersistAuthenticationEvent(): void { /** @psalm-suppress InvalidArgument */ @@ -238,9 +257,12 @@ class StoreTest extends TestCase $this->assertSame(2, (int)$authenticationEventCountQueryBuilder->executeQuery()->fetchOne()); } + /** + * @throws StoreException + */ public function testResolveIdpIdThrowsOnFirstGetIdpFailure(): void { - $this->repositoryMock->method('getIdp')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getIdp')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -256,11 +278,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveIdpIdThrowsOnInsertAndGetIdpFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getIdp')->willReturn($this->resultStub); - $this->repositoryMock->method('insertIdp')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertIdp')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -278,9 +303,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveIdpVersionIdThrowsOnFirstGetIdpVersionFailure(): void { - $this->repositoryMock->method('getIdpVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getIdpVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -296,11 +324,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveIdpVersionIdThrowsOnInsertAndGetIdpVersionFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getIdpVersion')->willReturn($this->resultStub); - $this->repositoryMock->method('insertIdpVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertIdpVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -318,9 +349,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveSpIdThrowsOnFirstGetSpFailure(): void { - $this->repositoryMock->method('getSp')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getSp')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -336,11 +370,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveSpIdThrowsOnInsertAndGetSpFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getSp')->willReturn($this->resultStub); - $this->repositoryMock->method('insertSp')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertSp')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -358,9 +395,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveSpVersionIdThrowsOnFirstGetSpVersionFailure(): void { - $this->repositoryMock->method('getSpVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getSpVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -376,11 +416,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveSpVersionIdThrowsOnInsertAndGetSpVersionFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getSpVersion')->willReturn($this->resultStub); - $this->repositoryMock->method('insertSpVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertSpVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -398,6 +441,9 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveUserIdThrowsOnInvalidUserIdentifierValue(): void { $moduleConfigurationStub = $this->createStub(ModuleConfiguration::class); @@ -418,9 +464,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveUserIdThrowsOnFirstGetUserFailure(): void { - $this->repositoryMock->method('getUser')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getUser')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -436,11 +485,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveUserIdThrowsOnInsertAndGetUserFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getUser')->willReturn($this->resultStub); - $this->repositoryMock->method('insertUser')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertUser')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -458,9 +510,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveUserVersionIdThrowsOnFirstGetUserVersionFailure(): void { - $this->repositoryMock->method('getUserVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getUserVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -476,11 +531,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveUserVersionIdThrowsOnInsertAndGetUserVersionFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getUserVersion')->willReturn($this->resultStub); - $this->repositoryMock->method('insertUserVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertUserVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -498,9 +556,12 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveIdpSpUserVersionIdThrowsOnFirstGetIdpSpUserVersionFailure(): void { - $this->repositoryMock->method('getIdpSpUserVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('getIdpSpUserVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( $this->moduleConfigurationStub, @@ -516,11 +577,14 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testResolveIdpSpUserVersionIdThrowsOnInsertAndGetIdpSpUserVersionFailure(): void { $this->resultStub->method('fetchOne')->willReturn(false); $this->repositoryMock->method('getIdpSpUserVersion')->willReturn($this->resultStub); - $this->repositoryMock->method('insertIdpSpUserVersion')->willThrowException(new \Exception('test')); + $this->repositoryMock->method('insertIdpSpUserVersion')->willThrowException(new Exception('test')); /** @psalm-suppress InvalidArgument */ $store = new Store( @@ -538,6 +602,9 @@ class StoreTest extends TestCase $store->persist($this->authenticationEvent); } + /** + * @throws StoreException + */ public function testGetConnectedOrganizationsReturnsEmptyBagIfNoResults(): void { $this->repositoryMock->method('getConnectedServiceProviders')->willReturn([]); @@ -557,6 +624,9 @@ class StoreTest extends TestCase $this->assertEmpty($connectedServiceProviderBag->getAll()); } + /** + * @throws StoreException + */ public function testCanGetConnectedOrganizationsBag(): void { $this->repositoryMock->method('getConnectedServiceProviders') @@ -577,6 +647,9 @@ class StoreTest extends TestCase $this->assertNotEmpty($connectedServiceProviderBag->getAll()); } + /** + * @throws StoreException + */ public function testGetConnectedOrganizationsThrowsForInvalidResult(): void { $rawResult = RawRowResult::CONNECTED_ORGANIZATION; @@ -599,6 +672,9 @@ class StoreTest extends TestCase $store->getConnectedOrganizations('test'); } + /** + * @throws StoreException + */ public function testGetActivityReturnsEmptyBagIfNoResults(): void { $this->repositoryMock->method('getActivity')->willReturn([]); @@ -618,6 +694,9 @@ class StoreTest extends TestCase $this->assertEmpty($activityBag->getAll()); } + /** + * @throws StoreException + */ public function testCanGetActivityBag(): void { $this->repositoryMock->method('getActivity') @@ -638,6 +717,9 @@ class StoreTest extends TestCase $this->assertNotEmpty($activityBag->getAll()); } + /** + * @throws StoreException + */ public function testGetActivityThrowsForInvalidResult(): void { $rawResult = RawRowResult::ACTIVITY; @@ -660,9 +742,12 @@ class StoreTest extends TestCase $store->getActivity('test', 10, 0); } + /** + * @throws StoreException + */ public function testCanDeleteDataOlderThan(): void { - $dateTime = new \DateTimeImmutable(); + $dateTime = new DateTimeImmutable(); $this->repositoryMock->expects($this->once()) ->method('deleteAuthenticationEventsOlderThan') diff --git a/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000000CreateJobTableTest.php b/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000000CreateJobTableTest.php index b56de0e42d4ff53ea3c72c71ff6d81fa7e67fb40..c346d8b1fa81251e14a21a32704400320e16cdc3 100644 --- a/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000000CreateJobTableTest.php +++ b/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000000CreateJobTableTest.php @@ -1,8 +1,12 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\DoctrineDbal\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store; @@ -19,9 +23,12 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220601000000CreateJobTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -29,6 +36,11 @@ class Version20220601000000CreateJobTableTest extends TestCase $this->tableName = $this->connection->preparePrefixedTableName(Store\TableConstants::TABLE_NAME_JOB); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -39,6 +51,9 @@ class Version20220601000000CreateJobTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $connectionStub = $this->createStub(Connection::class); @@ -48,13 +63,16 @@ class Version20220601000000CreateJobTableTest extends TestCase $connectionStub->method('dbal')->willReturn($dbalStub); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $migration = new Version20220601000000CreateJobTable($connectionStub); $this->expectException(MigrationException::class); $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $connectionStub = $this->createStub(Connection::class); @@ -64,7 +82,7 @@ class Version20220601000000CreateJobTableTest extends TestCase $connectionStub->method('dbal')->willReturn($dbalStub); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $migration = new Version20220601000000CreateJobTable($connectionStub); $this->expectException(MigrationException::class); diff --git a/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000100CreateJobFailedTableTest.php b/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000100CreateJobFailedTableTest.php index 0240fc6c4d035d518df04978980ba707761477c0..f4fcabdf0fba07cdd0158e1e86cb0d4846b39e01 100644 --- a/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000100CreateJobFailedTableTest.php +++ b/tests/src/Stores/Jobs/DoctrineDbal/Store/Migrations/Version20220601000100CreateJobFailedTableTest.php @@ -1,8 +1,12 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\DoctrineDbal\Store\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; use SimpleSAML\Module\accounting\Stores\Jobs\DoctrineDbal\Store; @@ -19,9 +23,12 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class Version20220601000100CreateJobFailedTableTest extends TestCase { protected Connection $connection; - protected \Doctrine\DBAL\Schema\AbstractSchemaManager $schemaManager; + protected AbstractSchemaManager $schemaManager; protected string $tableName; + /** + * @throws Exception + */ protected function setUp(): void { $this->connection = new Connection(ConnectionParameters::DBAL_SQLITE_MEMORY); @@ -29,6 +36,11 @@ class Version20220601000100CreateJobFailedTableTest extends TestCase $this->tableName = $this->connection->preparePrefixedTableName(Store\TableConstants::TABLE_NAME_JOB_FAILED); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanRunMigration(): void { $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); @@ -39,6 +51,9 @@ class Version20220601000100CreateJobFailedTableTest extends TestCase $this->assertFalse($this->schemaManager->tablesExist($this->tableName)); } + /** + * @throws StoreException + */ public function testRunThrowsMigrationException(): void { $connectionStub = $this->createStub(Connection::class); @@ -48,13 +63,16 @@ class Version20220601000100CreateJobFailedTableTest extends TestCase $connectionStub->method('dbal')->willReturn($dbalStub); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $schemaManagerStub->method('createTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $migration = new Migrations\Version20220601000100CreateJobFailedTable($connectionStub); $this->expectException(MigrationException::class); $migration->run(); } + /** + * @throws StoreException + */ public function testRevertThrowsMigrationException(): void { $connectionStub = $this->createStub(Connection::class); @@ -64,7 +82,7 @@ class Version20220601000100CreateJobFailedTableTest extends TestCase $connectionStub->method('dbal')->willReturn($dbalStub); $dbalStub->method('createSchemaManager')->willReturn($schemaManagerStub); $schemaManagerStub->method('dropTable') - ->willThrowException(new \Doctrine\DBAL\Exception('test')); + ->willThrowException(new Exception('test')); $migration = new Migrations\Version20220601000100CreateJobFailedTable($connectionStub); $this->expectException(MigrationException::class); diff --git a/tests/src/Stores/Jobs/DoctrineDbal/Store/RawJobTest.php b/tests/src/Stores/Jobs/DoctrineDbal/Store/RawJobTest.php index fa92aa61cf55074ef500e06aff7b025775bbdcf4..61370f28f93c72577400cc8df80b2703217144dd 100644 --- a/tests/src/Stores/Jobs/DoctrineDbal/Store/RawJobTest.php +++ b/tests/src/Stores/Jobs/DoctrineDbal/Store/RawJobTest.php @@ -1,9 +1,13 @@ <?php +declare(strict_types=1); + namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\DoctrineDbal\Store; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Authentication\State; @@ -24,11 +28,15 @@ class RawJobTest extends TestCase { protected Event $authenticationEvent; protected array $validRawRow; - protected \PHPUnit\Framework\MockObject\Stub $abstractPlatformStub; + protected Stub $abstractPlatformStub; protected function setUp(): void { $this->abstractPlatformStub = $this->createStub(AbstractPlatform::class); + + $this->abstractPlatformStub->method('getDateTimeFormatString') + ->willReturn('YYYY-MM-DD HH:MM:SS'); + $this->authenticationEvent = new Event(new State(StateArrays::FULL)); $this->validRawRow = [ Store\TableConstants::COLUMN_NAME_ID => 1, @@ -45,7 +53,7 @@ class RawJobTest extends TestCase $this->assertSame($rawJob->getId(), $this->validRawRow[Store\TableConstants::COLUMN_NAME_ID]); $this->assertEquals($rawJob->getPayload(), $this->authenticationEvent); $this->assertSame($rawJob->getType(), $this->validRawRow[Store\TableConstants::COLUMN_NAME_TYPE]); - $this->assertInstanceOf(\DateTimeImmutable::class, $rawJob->getCreatedAt()); + $this->assertInstanceOf(DateTimeImmutable::class, $rawJob->getCreatedAt()); } public function testThrowsOnEmptyColumn(): void diff --git a/tests/src/Stores/Jobs/DoctrineDbal/Store/RepositoryTest.php b/tests/src/Stores/Jobs/DoctrineDbal/Store/RepositoryTest.php index 3241e834c0cc1fe56c45b1fc1e8f33fdad015f35..d12416aded079a1da57b969f8dfe7474441d583b 100644 --- a/tests/src/Stores/Jobs/DoctrineDbal/Store/RepositoryTest.php +++ b/tests/src/Stores/Jobs/DoctrineDbal/Store/RepositoryTest.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\DoctrineDbal\Store; +use DateTimeImmutable; +use Exception; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Authentication\State; @@ -11,6 +14,7 @@ use SimpleSAML\Module\accounting\Entities\Bases\AbstractJob; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; use SimpleSAML\Module\accounting\Entities\GenericJob; use SimpleSAML\Module\accounting\Exceptions\StoreException; +use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\Logger; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; @@ -48,14 +52,17 @@ class RepositoryTest extends TestCase { protected ModuleConfiguration $moduleConfiguration; protected Connection $connection; - protected \PHPUnit\Framework\MockObject\Stub $loggerServiceStub; + protected Stub $loggerServiceStub; protected Migrator $migrator; - protected \PHPUnit\Framework\MockObject\Stub $factoryStub; - protected \PHPUnit\Framework\MockObject\Stub $payloadStub; - protected \PHPUnit\Framework\MockObject\Stub $jobStub; + protected Stub $factoryStub; + protected Stub $payloadStub; + protected Stub $jobStub; protected Store $jobsStore; protected string $jobsTableName; + /** + * @throws StoreException + */ protected function setUp(): void { // Configuration directory is set by phpunit using php ENV setting feature (check phpunit.xml). @@ -75,7 +82,7 @@ class RepositoryTest extends TestCase $this->jobStub = $this->createStub(GenericJob::class); $this->jobStub->method('getPayload')->willReturn($this->payloadStub); $this->jobStub->method('getType')->willReturn(GenericJob::class); - $this->jobStub->method('getCreatedAt')->willReturn(new \DateTimeImmutable()); + $this->jobStub->method('getCreatedAt')->willReturn(new DateTimeImmutable()); /** @psalm-suppress InvalidArgument */ $this->jobsStore = new Store( @@ -89,6 +96,10 @@ class RepositoryTest extends TestCase $this->jobsTableName = $this->connection->preparePrefixedTableName(Store\TableConstants::TABLE_NAME_JOB); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testCanInsertAndGetJob(): void { /** @psalm-suppress InvalidArgument */ @@ -104,6 +115,9 @@ class RepositoryTest extends TestCase $this->assertNotNull($repository->getNext()); } + /** + * @throws StoreException + */ public function testInsertThrowsIfJobsStoreSetupNotRan(): void { /** @psalm-suppress InvalidArgument */ @@ -117,6 +131,10 @@ class RepositoryTest extends TestCase $repository->insert($this->jobStub); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testInsertThrowsForInvalidJobType(): void { /** @psalm-suppress InvalidArgument */ @@ -130,12 +148,15 @@ class RepositoryTest extends TestCase $jobStub = $this->createStub(GenericJob::class); $jobStub->method('getPayload')->willReturn($this->payloadStub); $jobStub->method('getType')->willReturn($invalidType); - $jobStub->method('getCreatedAt')->willReturn(new \DateTimeImmutable()); + $jobStub->method('getCreatedAt')->willReturn(new DateTimeImmutable()); /** @psalm-suppress InvalidArgument */ $repository->insert($jobStub); } + /** + * @throws StoreException + */ public function testGetNextThrowsIfJobsStoreSetupNotRan(): void { /** @psalm-suppress InvalidArgument */ @@ -148,6 +169,10 @@ class RepositoryTest extends TestCase $repository->getNext(); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testGetNextThrowsForInvalidJobType(): void { /** @psalm-suppress InvalidArgument */ @@ -159,7 +184,7 @@ class RepositoryTest extends TestCase $jobStub = $this->createStub(AbstractJob::class); // Abstract classes can't be initialized.. $jobStub->method('getPayload')->willReturn($payloadStub); $jobStub->method('getType')->willReturn(AbstractJob::class); - $jobStub->method('getCreatedAt')->willReturn(new \DateTimeImmutable()); + $jobStub->method('getCreatedAt')->willReturn(new DateTimeImmutable()); /** @psalm-suppress InvalidArgument */ $repository->insert($jobStub); @@ -169,6 +194,11 @@ class RepositoryTest extends TestCase $repository->getNext(); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanDeleteJob(): void { /** @psalm-suppress InvalidArgument */ @@ -181,16 +211,19 @@ class RepositoryTest extends TestCase $repository->insert($this->jobStub); $job = $repository->getNext(); if ($job === null) { - throw new \Exception('Invalid job.'); + throw new Exception('Invalid job.'); } $jobId = $job->getId(); if ($jobId === null) { - throw new \Exception('Invalid job ID.'); + throw new Exception('Invalid job ID.'); } $this->assertTrue($repository->delete($jobId)); $this->assertFalse($repository->delete($jobId)); } + /** + * @throws StoreException + */ public function testDeleteThrowsWhenJobsStoreSetupNotRan(): void { /** @psalm-suppress InvalidArgument */ @@ -203,6 +236,10 @@ class RepositoryTest extends TestCase $repository->delete(1); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testCanGetSpecificJobType(): void { /** @psalm-suppress InvalidArgument */ diff --git a/tests/src/Stores/Jobs/DoctrineDbal/StoreTest.php b/tests/src/Stores/Jobs/DoctrineDbal/StoreTest.php index 3aca1188d80cec61b7f6cbbf24c225bd4c96736e..dfaea6d37ee461b9ddf9a10691321427b6897546 100644 --- a/tests/src/Stores/Jobs/DoctrineDbal/StoreTest.php +++ b/tests/src/Stores/Jobs/DoctrineDbal/StoreTest.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\DoctrineDbal; +use DateTimeImmutable; +use Doctrine\DBAL\Exception; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\Authentication\State; @@ -11,6 +14,7 @@ use SimpleSAML\Module\accounting\Entities\Bases\AbstractJob; use SimpleSAML\Module\accounting\Entities\Bases\AbstractPayload; use SimpleSAML\Module\accounting\Entities\GenericJob; use SimpleSAML\Module\accounting\Exceptions\StoreException; +use SimpleSAML\Module\accounting\Exceptions\StoreException\MigrationException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\Logger; use SimpleSAML\Module\accounting\Stores\Connections\DoctrineDbal\Connection; @@ -47,13 +51,16 @@ use SimpleSAML\Test\Module\accounting\Constants\StateArrays; class StoreTest extends TestCase { protected ModuleConfiguration $moduleConfiguration; - protected \PHPUnit\Framework\MockObject\Stub $factoryStub; + protected Stub $factoryStub; protected Connection $connection; - protected \PHPUnit\Framework\MockObject\Stub $loggerStub; + protected Stub $loggerStub; protected Migrator $migrator; - protected \PHPUnit\Framework\MockObject\Stub $payloadStub; - protected \PHPUnit\Framework\MockObject\Stub $jobStub; + protected Stub $payloadStub; + protected Stub $jobStub; + /** + * @throws StoreException + */ protected function setUp(): void { // Configuration directory is set by phpunit using php ENV setting feature (check phpunit.xml). @@ -73,10 +80,14 @@ class StoreTest extends TestCase $this->jobStub = $this->createStub(GenericJob::class); $this->jobStub->method('getPayload')->willReturn($this->payloadStub); $this->jobStub->method('getType')->willReturn(GenericJob::class); - $this->jobStub->method('getCreatedAt')->willReturn(new \DateTimeImmutable()); + $this->jobStub->method('getCreatedAt')->willReturn(new DateTimeImmutable()); $this->jobStub->method('getId')->willReturn(1); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testSetupDependsOnMigratorSetup(): void { /** @psalm-suppress InvalidArgument */ @@ -97,6 +108,10 @@ class StoreTest extends TestCase $this->assertFalse($this->migrator->needsSetup()); } + /** + * @throws StoreException + * @throws MigrationException + */ public function testSetupDependsOnMigrations(): void { /** @psalm-suppress InvalidArgument */ @@ -117,6 +132,9 @@ class StoreTest extends TestCase $this->assertFalse($jobsStore->needsSetup()); } + /** + * @throws StoreException + */ public function testCanGetPrefixedTableNames(): void { /** @psalm-suppress InvalidArgument */ @@ -137,6 +155,9 @@ class StoreTest extends TestCase $this->assertSame($tableNameFailedJobs, $jobsStore->getPrefixedTableNameFailedJobs()); } + /** + * @throws StoreException + */ public function testCanBuildInstanceStatically(): void { $moduleConfiguration = $this->createStub(ModuleConfiguration::class); @@ -146,6 +167,11 @@ class StoreTest extends TestCase $this->assertInstanceOf(Store::class, Store::build($moduleConfiguration, $this->loggerStub)); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanEnqueueJob(): void { /** @psalm-suppress InvalidArgument */ @@ -176,6 +202,9 @@ class StoreTest extends TestCase $this->assertSame(3, (int) $queryBuilder->executeQuery()->fetchOne()); } + /** + * @throws StoreException + */ public function testEnqueueThrowsStoreExceptionOnNonSetupRun(): void { /** @psalm-suppress InvalidArgument */ @@ -198,6 +227,11 @@ class StoreTest extends TestCase $jobsStore->enqueue($jobStub); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanDequeueJob(): void { /** @psalm-suppress InvalidArgument */ @@ -228,6 +262,11 @@ class StoreTest extends TestCase $this->assertSame(1, (int) $queryBuilder->executeQuery()->fetchOne()); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanDequeueSpecificJobType(): void { /** @psalm-suppress InvalidArgument */ @@ -263,6 +302,10 @@ class StoreTest extends TestCase $this->assertSame(1, (int) $queryBuilder->executeQuery()->fetchOne()); } + /** + * @throws StoreException + * @throws Exception + */ public function testDequeueThrowsWhenSetupNotRun(): void { /** @psalm-suppress InvalidArgument */ @@ -284,12 +327,17 @@ class StoreTest extends TestCase $jobsStore->dequeue('test-type'); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testDequeueThrowsForJobWithInvalidId(): void { $repositoryStub = $this->createStub(Store\Repository::class); $jobStub = $this->createStub(GenericJob::class); $jobStub->method('getPayload')->willReturn($this->payloadStub); - $jobStub->method('getCreatedAt')->willReturn(new \DateTimeImmutable()); + $jobStub->method('getCreatedAt')->willReturn(new DateTimeImmutable()); $jobStub->method('getType')->willReturn(GenericJob::class); $jobStub->method('getId')->willReturn(null); // Invalid ID value... @@ -312,6 +360,11 @@ class StoreTest extends TestCase $jobsStore->dequeue($this->jobStub->getType()); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testDequeThrowsAfterMaxDeleteAttempts(): void { $repositoryStub = $this->createStub(Store\Repository::class); @@ -335,6 +388,11 @@ class StoreTest extends TestCase $jobsStore->dequeue($this->jobStub->getType()); } + /** + * @throws StoreException + * @throws MigrationException + * @throws Exception + */ public function testCanContinueSearchingInCaseOfJobDeletion(): void { $repositoryStub = $this->createStub(Store\Repository::class); @@ -356,6 +414,11 @@ class StoreTest extends TestCase $this->assertNotNull($jobsStore->dequeue($this->jobStub->getType())); } + /** + * @throws StoreException + * @throws Exception + * @throws MigrationException + */ public function testCanMarkFailedJob(): void { /** @psalm-suppress InvalidArgument */ diff --git a/tests/src/Stores/Jobs/PhpRedis/RedisStoreTest.php b/tests/src/Stores/Jobs/PhpRedis/RedisStoreTest.php index f29ce0c1f90d22febd3fa47ed7f1cafef71e1352..03ee2d235514df8a57e021d239cf6682eb34e4b9 100644 --- a/tests/src/Stores/Jobs/PhpRedis/RedisStoreTest.php +++ b/tests/src/Stores/Jobs/PhpRedis/RedisStoreTest.php @@ -1,11 +1,16 @@ <?php +/** @noinspection PhpComposerExtensionStubsInspection ext-redis should only be installed if used. */ + declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Stores\Jobs\PhpRedis; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use Redis; +use RedisException; use SimpleSAML\Module\accounting\Entities\GenericJob; use SimpleSAML\Module\accounting\Entities\Interfaces\JobInterface; use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; @@ -21,19 +26,19 @@ use PHPUnit\Framework\TestCase; class RedisStoreTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\Stub|ModuleConfiguration + * @var Stub|ModuleConfiguration */ protected $moduleConfigurationStub; /** - * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + * @var MockObject|LoggerInterface */ protected $loggerMock; /** - * @var \PHPUnit\Framework\MockObject\MockObject|Redis + * @var MockObject|Redis */ protected $redisMock; /** - * @var \PHPUnit\Framework\MockObject\Stub|JobInterface + * @var Stub|JobInterface */ protected $jobStub; @@ -46,6 +51,9 @@ class RedisStoreTest extends TestCase $this->jobStub->method('getType')->willReturn(GenericJob::class); } + /** + * @throws StoreException + */ public function testCanCreateInstance(): void { /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -65,6 +73,9 @@ class RedisStoreTest extends TestCase ); } + /** + * @throws StoreException + */ public function testThrowsIfHostConnectionParameterNotSet(): void { $this->expectException(InvalidConfigurationException::class); @@ -96,7 +107,7 @@ class RedisStoreTest extends TestCase ->willReturn(['host' => 'sample']); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ - $this->redisMock->method('connect')->willThrowException(new \RedisException('test')); + $this->redisMock->method('connect')->willThrowException(new RedisException('test')); /** @psalm-suppress PossiblyInvalidArgument */ $this->assertInstanceOf( @@ -125,7 +136,7 @@ class RedisStoreTest extends TestCase ->willReturn(['host' => 'sample', 'auth' => 'test']); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ - $this->redisMock->method('auth')->willThrowException(new \RedisException('test')); + $this->redisMock->method('auth')->willThrowException(new RedisException('test')); /** @psalm-suppress PossiblyInvalidArgument */ $this->assertInstanceOf( @@ -153,7 +164,7 @@ class RedisStoreTest extends TestCase ->willReturn(['host' => 'sample']); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ - $this->redisMock->method('setOption')->willThrowException(new \RedisException('test')); + $this->redisMock->method('setOption')->willThrowException(new RedisException('test')); /** @psalm-suppress PossiblyInvalidArgument */ $this->assertInstanceOf( @@ -168,6 +179,9 @@ class RedisStoreTest extends TestCase ); } + /** + * @throws StoreException + */ public function testCanCallRPushMethod(): void { /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -206,7 +220,7 @@ class RedisStoreTest extends TestCase ->with($this->stringContains('Could not add job to Redis list.')); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ - $this->redisMock->method('rPush')->willThrowException(new \RedisException('test')); + $this->redisMock->method('rPush')->willThrowException(new RedisException('test')); /** @psalm-suppress PossiblyInvalidArgument */ $redisStore = new RedisStore( @@ -221,6 +235,9 @@ class RedisStoreTest extends TestCase $redisStore->enqueue($this->jobStub); } + /** + * @throws StoreException + */ public function testCanDequeueJob(): void { /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -252,7 +269,7 @@ class RedisStoreTest extends TestCase /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ $this->redisMock->method('lPop') - ->willThrowException(new \RedisException('test')); + ->willThrowException(new RedisException('test')); $this->expectException(StoreException::class); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -303,6 +320,9 @@ class RedisStoreTest extends TestCase @$redisStore->dequeue($this->jobStub->getType()); } + /** + * @throws StoreException + */ public function testCanMarkFailedJob(): void { /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -335,7 +355,7 @@ class RedisStoreTest extends TestCase /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ $this->redisMock->method('rPush') - ->willThrowException(new \RedisException('test')); + ->willThrowException(new RedisException('test')); $this->expectException(StoreException::class); /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ @@ -356,6 +376,9 @@ class RedisStoreTest extends TestCase $redisStore->markFailedJob($this->jobStub); } + /** + * @throws StoreException + */ public function testSetupIsNotNeeded(): void { /** @psalm-suppress PossiblyUndefinedMethod, MixedMethodCall */ diff --git a/tests/src/Trackers/Authentication/DoctrineDbal/Versioned/TrackerTest.php b/tests/src/Trackers/Authentication/DoctrineDbal/Versioned/TrackerTest.php index a6800b562b5af0da2cc92d900c5c5438929284fc..ebd98ad04d7994717a0768ee8ca13d1ff223db9b 100644 --- a/tests/src/Trackers/Authentication/DoctrineDbal/Versioned/TrackerTest.php +++ b/tests/src/Trackers/Authentication/DoctrineDbal/Versioned/TrackerTest.php @@ -4,11 +4,14 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Trackers\Authentication\DoctrineDbal\Versioned; +use DateInterval; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Activity; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Entities\ConnectedServiceProvider; -use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; +use SimpleSAML\Module\accounting\Exceptions\StoreException; use SimpleSAML\Module\accounting\ModuleConfiguration; use SimpleSAML\Module\accounting\Services\HelpersManager; use SimpleSAML\Module\accounting\Stores\Data\Authentication\DoctrineDbal\Versioned\Store; @@ -37,19 +40,19 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class TrackerTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\Stub|ModuleConfiguration + * @var Stub|ModuleConfiguration */ protected $moduleConfigurationStub; /** - * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + * @var MockObject|LoggerInterface */ protected $loggerMock; /** - * @var \PHPUnit\Framework\MockObject\MockObject|Store + * @var MockObject|Store */ protected $dataStoreMock; /** - * @var \PHPUnit\Framework\MockObject\Stub|HelpersManager + * @var Stub|HelpersManager */ protected $helpersManagerStub; @@ -65,6 +68,7 @@ class TrackerTest extends TestCase /** * @psalm-suppress PossiblyInvalidArgument + * @throws StoreException */ public function testCanCreateInstance(): void { @@ -90,6 +94,9 @@ class TrackerTest extends TestCase ); } + /** + * @throws StoreException + */ public function testProcessCallsPersistOnDataStore(): void { $authenticationEventStub = $this->createStub(Event::class); @@ -110,6 +117,9 @@ class TrackerTest extends TestCase $tracker->process($authenticationEventStub); } + /** + * @throws StoreException + */ public function testSetupDependsOnDataStore(): void { $this->dataStoreMock->expects($this->exactly(2)) @@ -133,6 +143,9 @@ class TrackerTest extends TestCase $tracker->runSetup(); } + /** + * @throws StoreException + */ public function testRunningSetupIfNotNeededLogsWarning(): void { $this->dataStoreMock->method('needsSetup') @@ -153,6 +166,9 @@ class TrackerTest extends TestCase $tracker->runSetup(); } + /** + * @throws StoreException + */ public function testGetConnectedServiceProviders(): void { $connectedOrganizationsBagStub = $this->createStub(ConnectedServiceProvider\Bag::class); @@ -175,6 +191,9 @@ class TrackerTest extends TestCase ); } + /** + * @throws StoreException + */ public function testGetActivity(): void { $activityBag = $this->createStub(Activity\Bag::class); @@ -196,9 +215,12 @@ class TrackerTest extends TestCase ); } + /** + * @throws StoreException + */ public function testCanEnforceDataRetentionPolicy(): void { - $retentionPolicy = new \DateInterval('P10D'); + $retentionPolicy = new DateInterval('P10D'); $this->dataStoreMock->expects($this->once()) ->method('deleteDataOlderThan'); diff --git a/tests/src/Trackers/Builders/AuthenticationDataTrackerBuilderTest.php b/tests/src/Trackers/Builders/AuthenticationDataTrackerBuilderTest.php index 8a27f1a4ab3c306b1e80521439bd976068449873..a4612238a43bc346ce0512ae09cb66c6b6915e61 100644 --- a/tests/src/Trackers/Builders/AuthenticationDataTrackerBuilderTest.php +++ b/tests/src/Trackers/Builders/AuthenticationDataTrackerBuilderTest.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Test\Module\accounting\Trackers\Builders; +use DateInterval; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Log\LoggerInterface; use SimpleSAML\Module\accounting\Entities\Authentication\Event; use SimpleSAML\Module\accounting\Exceptions\Exception; @@ -24,11 +27,11 @@ use SimpleSAML\Test\Module\accounting\Constants\ConnectionParameters; class AuthenticationDataTrackerBuilderTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface|LoggerInterface&\PHPUnit\Framework\MockObject\MockObject + * @var MockObject|LoggerInterface */ protected $loggerMock; /** - * @var \PHPUnit\Framework\MockObject\Stub|ModuleConfiguration|ModuleConfiguration&\PHPUnit\Framework\MockObject\Stub + * @var Stub|ModuleConfiguration */ protected $moduleConfigurationStub; @@ -65,7 +68,7 @@ class AuthenticationDataTrackerBuilderTest extends TestCase { } - public function enforceDataRetentionPolicy(\DateInterval $retentionPolicy): void + public function enforceDataRetentionPolicy(DateInterval $retentionPolicy): void { } }; @@ -83,6 +86,9 @@ class AuthenticationDataTrackerBuilderTest extends TestCase ); } + /** + * @throws Exception + */ public function testCanBuildAuthenticationDataTracker(): void { $authenticationDataTrackerBuilder = new AuthenticationDataTrackerBuilder(