87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\IncoSheets;
|
||
|
|
|
||
|
|
use Domain\Models\ValueObjects\IncoSheets\IncoIdQuery;
|
||
|
|
|
||
|
|
covers(IncoIdQuery::class);
|
||
|
|
|
||
|
|
describe('IncoIdQuery Value Object Instantiation', function (): void {
|
||
|
|
it('can be instantiated with a valid string of digits', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$validValue = '12345';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$incoIdQuery = new IncoIdQuery($validValue);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($incoIdQuery->value)->toBe('12345');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can be instantiated with a string of digits prefixed with %', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$validValue = '%12345';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$incoIdQuery = new IncoIdQuery($validValue);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($incoIdQuery->value)->toBe('%12345');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can be instantiated with a string of digits suffixed with %', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$validValue = '12345%';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$incoIdQuery = new IncoIdQuery($validValue);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($incoIdQuery->value)->toBe('12345%');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can be instantiated with a string of digits prefixed and suffixed with %', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$validValue = '%12345%';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$incoIdQuery = new IncoIdQuery($validValue);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($incoIdQuery->value)->toBe('%12345%');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can be instantiated with wildcards anywhere in the digit string', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$validValue = '%12%345%';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$incoIdQuery = new IncoIdQuery($validValue);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($incoIdQuery->value)->toBe('%12%345%');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('IncoIdQuery Value Object Domain Rules', function (): void {
|
||
|
|
it('throws DomainException when instantiated with an empty string', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$invalidValue = '';
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new IncoIdQuery($invalidValue))
|
||
|
|
->toThrow(\DomainException::class, 'value cannot be empty');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('throws DomainException when instantiated with a non-digit string', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$invalidValue = 'abc123';
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new IncoIdQuery($invalidValue))
|
||
|
|
->toThrow(\DomainException::class, 'value must be a string of digits optionally prefixed and/or suffixed with a % sign');
|
||
|
|
});
|
||
|
|
});
|