ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/CampaignRequest/ApplicantTest.php
2026-10-02 12:47:27 +02:00

94 lines
3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\CampaignRequest;
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
use Shared\ValueObjects\Email;
covers(Applicant::class);
describe('applicant', function (): void {
it('creates a valid applicant', function (): void {
// GIVEN
$firstname = 'John';
$lastname = 'Doe';
$email = new Email('john.doe@example.com');
// WHEN
$applicant = new Applicant($firstname, $lastname, $email);
// THEN
expect($applicant)->toBeInstanceOf(Applicant::class)
->and($applicant->firstname)->toBe($firstname)
->and($applicant->lastname)->toBe($lastname)
->and($applicant->email)->toBe($email);
});
it('rejects an empty or whitespace-only firstname', function (string $firstname): void {
// WHEN
$action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant firstname cannot be empty.');
})->with([
'empty' => '',
'spaces' => ' ',
]);
it('rejects a firstname that exceeds the maximum allowed length', function (): void {
// GIVEN
$firstname = str_repeat('a', 201);
// WHEN
$action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant firstname exceeds the maximum allowed length.');
});
it('accepts a firstname of exactly the maximum length', function (): void {
// GIVEN
$firstname = str_repeat('a', 200);
// WHEN
$applicant = new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect(mb_strlen($applicant->firstname))->toBe(200);
});
it('rejects an empty or whitespace-only lastname', function (string $lastname): void {
// WHEN
$action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant lastname cannot be empty.');
})->with([
'empty' => '',
'spaces' => ' ',
]);
it('rejects a lastname that exceeds the maximum allowed length', function (): void {
// GIVEN
$lastname = str_repeat('a', 201);
// WHEN
$action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant lastname exceeds the maximum allowed length.');
});
it('accepts a lastname of exactly the maximum length', function (): void {
// GIVEN
$lastname = str_repeat('a', 200);
// WHEN
$applicant = new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect(mb_strlen($applicant->lastname))->toBe(200);
});
});