ldc-cocotte/tests/Unit/Domain/Models/ValueObjects/ContactFormDataTest.php

135 lines
3.4 KiB
PHP
Raw Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\ContactFormData;
use Domain\Models\ValueObjects\OrderReference;
use Shared\Helpers\UuidHelper;
2026-06-14 21:32:07 +02:00
describe('ContactFormData', function () {
/**
* @param array{
* lastName?: string,
* firstName?: string,
* email?: string,
* subject?: string,
* message?: string,
* orderRef?: \Domain\Models\ValueObjects\OrderReference|null,
* file?: \Domain\Models\ValueObjects\AttachedFile|null,
* } $overrides
*/
2026-06-14 21:32:07 +02:00
function getNewContactFormData(array $overrides = []): ContactFormData
{
return new ContactFormData(
lastName: $overrides['lastName'] ?? 'Doe',
firstName: $overrides['firstName'] ?? 'John',
email: $overrides['email'] ?? 'john@example.com',
subject: $overrides['subject'] ?? 'Inquiry',
message: $overrides['message'] ?? 'This is a message.',
orderRef: $overrides['orderRef'] ?? null,
file: $overrides['file'] ?? null,
);
2026-06-14 21:32:07 +02:00
}
it('can instantiate', function () {
// GIVEN
$lastName = 'Doe';
$firstName = 'John';
$email = 'john@example.com';
$subject = 'Inquiry';
$message = 'This is a message.';
$orderRef = new OrderReference(UuidHelper::v7());
2026-06-14 21:32:07 +02:00
$file = null;
// WHEN
$vo = new ContactFormData(
lastName: $lastName,
firstName: $firstName,
email: $email,
subject: $subject,
message: $message,
orderRef: $orderRef,
file: $file
);
// THEN
expect($vo->lastName)->toBe($lastName)
->and($vo->firstName)->toBe($firstName)
->and($vo->email)->toBe($email)
->and($vo->orderRef)->toBe($orderRef);
2026-06-14 21:32:07 +02:00
});
it('throws exception if lastName is empty', function () {
// GIVEN
$lastName = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'lastName' => $lastName,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if firstName is empty', function () {
// GIVEN
$firstName = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'firstName' => $firstName,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if email is empty', function () {
// GIVEN
$email = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'email' => $email,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if subject is empty', function () {
// GIVEN
$subject = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'subject' => $subject,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if message is empty', function () {
// GIVEN
$message = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'message' => $message,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
});