93 lines
2.9 KiB
PHP
93 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Security\ValueObjects;
|
|
|
|
use Application\Security\Models\ValueObjects\ClientIdentifier;
|
|
|
|
covers(ClientIdentifier::class);
|
|
|
|
describe('ClientIdentifier Value Object Instantiation', function (): void {
|
|
it('instantiates successfully with a valid client identifier', function (string $input): void {
|
|
// GIVEN
|
|
$validClientIdentifier = $input;
|
|
|
|
// WHEN
|
|
$clientIdentifier = new ClientIdentifier($validClientIdentifier);
|
|
|
|
// THEN
|
|
expect($clientIdentifier->value)->toBe($validClientIdentifier)
|
|
->and($clientIdentifier->value())->toBe($validClientIdentifier);
|
|
})->with([
|
|
'arcadia_id_' . str_repeat('a', 32),
|
|
str_repeat('c', 43),
|
|
str_repeat('x', 255),
|
|
'client-identifier_with-valid_chars-1234567890123456',
|
|
]);
|
|
});
|
|
|
|
describe('ClientIdentifier Value Object Validation Rules', function (): void {
|
|
it('throws InvalidArgumentException when given an empty client identifier', function (string $invalid): void {
|
|
// GIVEN
|
|
$input = $invalid;
|
|
|
|
// WHEN
|
|
$execution = fn () => new ClientIdentifier($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'ClientIdentifier cannot be empty.'
|
|
);
|
|
})->with(['', ' ']);
|
|
|
|
it('throws InvalidArgumentException when client identifier format contains invalid characters', function (string $invalid): void {
|
|
// GIVEN
|
|
$input = $invalid;
|
|
|
|
// WHEN
|
|
$execution = fn () => new ClientIdentifier($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'ClientIdentifier can only contain alphanumeric characters, dashes, and underscores.'
|
|
);
|
|
})->with([
|
|
'arcadia_id_with_invalid_char_@_' . str_repeat('a', 20),
|
|
'arcadia_id with spaces in between' . str_repeat('a', 20),
|
|
'arcadia_id!@#$%^&*()_+' . str_repeat('a', 30),
|
|
]);
|
|
|
|
it('throws InvalidArgumentException when client identifier is too short', function (string $invalid): void {
|
|
// GIVEN
|
|
$input = $invalid;
|
|
|
|
// WHEN
|
|
$execution = fn () => new ClientIdentifier($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'ClientIdentifier must be at least 43 characters long.'
|
|
);
|
|
})->with([
|
|
str_repeat('a', 42),
|
|
'arcadia_id_short',
|
|
]);
|
|
|
|
it('throws InvalidArgumentException when client identifier exceeds 255 characters', function (): void {
|
|
// GIVEN
|
|
$input = str_repeat('a', 256);
|
|
|
|
// WHEN
|
|
$execution = fn () => new ClientIdentifier($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'ClientIdentifier cannot exceed 255 characters.'
|
|
);
|
|
});
|
|
});
|