75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain;
|
|
|
|
use Domain\Models\ValueObjects\Employees\ArcadiaEmployeeId;
|
|
|
|
covers(ArcadiaEmployeeId::class);
|
|
|
|
describe('ArcadiaEmployeeId Value Object Instantiation', function (): void {
|
|
it('instantiates successfully with a valid 7-digit matricule', function (): void {
|
|
// GIVEN
|
|
$validMatricule = '0115590';
|
|
|
|
// WHEN
|
|
$employeeId = new ArcadiaEmployeeId($validMatricule);
|
|
|
|
// THEN
|
|
expect($employeeId->value)
|
|
->toBe('0115590')
|
|
->and((string) $employeeId)->toBe('0115590');
|
|
});
|
|
|
|
it('instantiates successfully with a valid 8-digit matricule', function (): void {
|
|
// GIVEN
|
|
$validMatricule = '01155902';
|
|
|
|
// WHEN
|
|
$employeeId = new ArcadiaEmployeeId($validMatricule);
|
|
|
|
// THEN
|
|
expect($employeeId->value)
|
|
->toBe('01155902')
|
|
->and((string) $employeeId)->toBe('01155902');
|
|
});
|
|
|
|
it('supports equality check with another ArcadiaEmployeeId instance', function (): void {
|
|
// GIVEN
|
|
$firstId = new ArcadiaEmployeeId('01155902');
|
|
$sameId = new ArcadiaEmployeeId('01155902');
|
|
$differentId = new ArcadiaEmployeeId('01155901');
|
|
|
|
// WHEN & THEN
|
|
expect($firstId->equals($sameId))
|
|
->toBeTrue()
|
|
->and($firstId->equals($differentId))
|
|
->toBeFalse();
|
|
});
|
|
|
|
it('can be converted to a string representation', function (): void {
|
|
// GIVEN
|
|
$employeeId = new ArcadiaEmployeeId('01155902');
|
|
|
|
// WHEN
|
|
$stringRepresentation = (string) $employeeId;
|
|
|
|
// THEN
|
|
expect($stringRepresentation)->toBe('01155902');
|
|
});
|
|
});
|
|
|
|
describe('ArcadiaEmployeeId Value Object Domain Rules', function (): void {
|
|
it('throws a DomainException when given an invalid matricule pattern', function (string $invalidMatricule): void {
|
|
expect(fn () => new ArcadiaEmployeeId($invalidMatricule))
|
|
->toThrow(\DomainException::class);
|
|
})->with([
|
|
'too short' => '12345',
|
|
'too long' => '123456789',
|
|
'comment with hash' => '# s996008',
|
|
'alphanumeric d prefix' => 'd05600013',
|
|
'alphanumeric P prefix' => 'P99900029',
|
|
'empty string' => '',
|
|
]);
|
|
});
|