94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Application\Arcadia\Config;
|
||
|
|
|
||
|
|
use Application\Arcadia\Config\AppConfig;
|
||
|
|
use Application\Arcadia\Config\ThrottlingConfig;
|
||
|
|
use Infra\Config\ArcadiaStorageConfig;
|
||
|
|
use Shared\ValueObjects\Config\AppName;
|
||
|
|
use Shared\ValueObjects\Config\AppTimezone;
|
||
|
|
use Shared\ValueObjects\Config\Locale;
|
||
|
|
use Shared\ValueObjects\Config\RequestsPerMinute;
|
||
|
|
|
||
|
|
covers(
|
||
|
|
ThrottlingConfig::class,
|
||
|
|
AppConfig::class,
|
||
|
|
ArcadiaStorageConfig::class,
|
||
|
|
);
|
||
|
|
|
||
|
|
describe('Arcadia Config Objects Unit Tests', function (): void {
|
||
|
|
it('instantiates ThrottlingConfig with typed RequestsPerMinute VOs', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$webLimit = new RequestsPerMinute(120);
|
||
|
|
$apiV1Limit = new RequestsPerMinute(60);
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$config = new ThrottlingConfig(
|
||
|
|
webLimit: $webLimit,
|
||
|
|
apiV1Limit: $apiV1Limit,
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($config->webLimit->toInt())->toBe(120)
|
||
|
|
->and($config->apiV1Limit->toInt())->toBe(60);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('instantiates AppConfig with typed name, timezone and locale VOs', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$config = new AppConfig(
|
||
|
|
name: new AppName('Arcadia API'),
|
||
|
|
timezone: AppTimezone::utc(),
|
||
|
|
locale: new Locale('fr'),
|
||
|
|
fallbackLocale: new Locale('en'),
|
||
|
|
isDebug: true,
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($config->name->value)->toBe('Arcadia API')
|
||
|
|
->and($config->timezone->name)->toBe('UTC')
|
||
|
|
->and($config->locale->value())->toBe('fr')
|
||
|
|
->and($config->fallbackLocale->value())->toBe('en')
|
||
|
|
->and($config->isDebug)->toBeTrue();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('instantiates ArcadiaStorageConfig with valid connection and store names', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$config = new ArcadiaStorageConfig(
|
||
|
|
cacheStore: 'redis',
|
||
|
|
databaseConnection: 'arcadia_custom',
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($config->cacheStore)->toBe('redis')
|
||
|
|
->and($config->databaseConnection)->toBe('arcadia_custom');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('rejects invalid cache store in ArcadiaStorageConfig', function (string $invalidStore): void {
|
||
|
|
// GIVEN & WHEN & THEN
|
||
|
|
expect(fn () => new ArcadiaStorageConfig(
|
||
|
|
cacheStore: $invalidStore,
|
||
|
|
databaseConnection: 'arcadia',
|
||
|
|
))->toThrow(\InvalidArgumentException::class);
|
||
|
|
})->with([
|
||
|
|
'',
|
||
|
|
' ',
|
||
|
|
'invalid store name with spaces',
|
||
|
|
'invalid$store',
|
||
|
|
]);
|
||
|
|
|
||
|
|
it('rejects invalid database connection in ArcadiaStorageConfig', function (string $invalidDb): void {
|
||
|
|
// GIVEN & WHEN & THEN
|
||
|
|
expect(fn () => new ArcadiaStorageConfig(
|
||
|
|
cacheStore: 'redis',
|
||
|
|
databaseConnection: $invalidDb,
|
||
|
|
))->toThrow(\InvalidArgumentException::class);
|
||
|
|
})->with([
|
||
|
|
'',
|
||
|
|
' ',
|
||
|
|
'invalid connection with spaces',
|
||
|
|
'invalid;connection',
|
||
|
|
]);
|
||
|
|
});
|