test(ValueObjects): add unit tests for BrandCode, EstablishmentCode, IncoCompoId, IncoId, ServiceId, and SiteId value objects
Add comprehensive unit tests to validate the behavior of various value objects.
This commit is contained in:
parent
742476bdcb
commit
3ba74409ff
6 changed files with 168 additions and 0 deletions
28
tests/Unit/Domain/Models/ValueObjects/BrandCodeTest.php
Normal file
28
tests/Unit/Domain/Models/ValueObjects/BrandCodeTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\BrandCode;
|
||||
|
||||
covers(BrandCode::class);
|
||||
|
||||
describe('BrandCode Value Object', function (): void {
|
||||
it('accepts valid positive brand codes', function (int $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$brandCode = new BrandCode($value);
|
||||
|
||||
// THEN
|
||||
expect($brandCode->value)->toBe($value);
|
||||
})->with([13, 1, 9999]);
|
||||
|
||||
it('rejects zero or negative brand codes', function (int $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new BrandCode($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with([0, -1, -9999]);
|
||||
});
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\EstablishmentCode;
|
||||
|
||||
covers(EstablishmentCode::class);
|
||||
|
||||
describe('EstablishmentCode Value Object', function (): void {
|
||||
it('accepts valid establishment codes matching pattern', function (string $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$establishmentCode = new EstablishmentCode($value);
|
||||
|
||||
// THEN
|
||||
expect($establishmentCode->value)->toBe($value);
|
||||
})->with(['EST01', '01', 'ESTABLISHMENT', 'A1']);
|
||||
|
||||
it('rejects invalid, lowercase, short or empty establishment codes', function (string $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new EstablishmentCode($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with(['est01', 'A', '', 'EST 01', 'EST-01']);
|
||||
});
|
||||
28
tests/Unit/Domain/Models/ValueObjects/IncoCompoIdTest.php
Normal file
28
tests/Unit/Domain/Models/ValueObjects/IncoCompoIdTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\IncoCompoId;
|
||||
|
||||
covers(IncoCompoId::class);
|
||||
|
||||
describe('IncoCompoId Value Object', function (): void {
|
||||
it('accepts valid numeric values', function (string $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$vo = new IncoCompoId($value);
|
||||
|
||||
// THEN
|
||||
expect($vo->value)->toBe($value);
|
||||
})->with(['123', '0', '999999']);
|
||||
|
||||
it('rejects invalid non-numeric or empty values', function (string $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new IncoCompoId($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with(['abc', '12a', '', ' 123 ', '-5']);
|
||||
});
|
||||
28
tests/Unit/Domain/Models/ValueObjects/IncoIdTest.php
Normal file
28
tests/Unit/Domain/Models/ValueObjects/IncoIdTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\IncoId;
|
||||
|
||||
covers(IncoId::class);
|
||||
|
||||
describe('IncoId Value Object', function (): void {
|
||||
it('accepts valid numeric values', function (string $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$vo = new IncoId($value);
|
||||
|
||||
// THEN
|
||||
expect($vo->value)->toBe($value);
|
||||
})->with(['100', '1', '88888']);
|
||||
|
||||
it('rejects invalid non-numeric or empty values', function (string $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new IncoId($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with(['invalid', '12b', '', ' ', '-1']);
|
||||
});
|
||||
28
tests/Unit/Domain/Models/ValueObjects/ServiceIdTest.php
Normal file
28
tests/Unit/Domain/Models/ValueObjects/ServiceIdTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\ServiceId;
|
||||
|
||||
covers(ServiceId::class);
|
||||
|
||||
describe('ServiceId Value Object', function (): void {
|
||||
it('accepts valid numeric service identifiers', function (string $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$vo = new ServiceId($value);
|
||||
|
||||
// THEN
|
||||
expect($vo->value)->toBe($value);
|
||||
})->with(['097', '1', '12345']);
|
||||
|
||||
it('rejects non-numeric service identifiers', function (string $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new ServiceId($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with(['SERV01', 'abc', '', ' 097 ', '-10']);
|
||||
});
|
||||
28
tests/Unit/Domain/Models/ValueObjects/SiteIdTest.php
Normal file
28
tests/Unit/Domain/Models/ValueObjects/SiteIdTest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\SiteId;
|
||||
|
||||
covers(SiteId::class);
|
||||
|
||||
describe('SiteId Value Object', function (): void {
|
||||
it('accepts valid uppercase alphabetical site identifiers', function (string $input): void {
|
||||
// GIVEN
|
||||
$value = $input;
|
||||
|
||||
// WHEN
|
||||
$vo = new SiteId($value);
|
||||
|
||||
// THEN
|
||||
expect($vo->value)->toBe($value);
|
||||
})->with(['LDCSER', 'SLELA', 'DDE', 'SITE']);
|
||||
|
||||
it('rejects lowercase, numeric, or too short site identifiers', function (string $invalid): void {
|
||||
// GIVEN / WHEN / THEN
|
||||
expect(fn () => new SiteId($invalid))
|
||||
->toThrow(\DomainException::class);
|
||||
})->with(['site', 'LDCSER01', 'A', '123', '', 'LD CSER']);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue