122 lines
2.8 KiB
PHP
122 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Domain\Models\ValueObjects\ContactFormData;
|
|
use Domain\Models\ValueObjects\OrderReference;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
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 = new OrderReference(Uuid::uuid7());
|
|
$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);
|
|
});
|
|
});
|