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

135 lines
3 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;
describe('ContactFormData', function () {
function getNewContactFormData(array $overrides = []): ContactFormData
{
$data = array_merge([
'lastName' => 'Doe',
'firstName' => 'John',
'email' => 'john@example.com',
'subject' => 'Inquiry',
'message' => 'This is a message.',
'orderRef' => null,
'file' => null,
], $overrides);
return new ContactFormData(...$data);
}
it('can instantiate', function () {
// GIVEN
$lastName = 'Doe';
$firstName = 'John';
$email = 'john@example.com';
$subject = 'Inquiry';
$message = 'This is a message.';
$orderRef = 'REF-123';
$file = null;
// WHEN
$vo = new ContactFormData(
lastName: $lastName,
firstName: $firstName,
email: $email,
subject: $subject,
message: $message,
orderRef: $orderRef,
file: $file
);
// THEN
expect($vo)->toBeInstanceOf(ContactFormData::class);
});
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);
});
});
it('throws exception if orderRef is provided but empty', function () {
// GIVEN
$orderRef = ' ';
// WHEN
$action = fn () => getNewContactFormData([
'orderRef' => $orderRef,
]);
// THEN
expect($action)->toThrow(\DomainException::class);
});