134 lines
3.4 KiB
PHP
134 lines
3.4 KiB
PHP
<?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;
|
|
|
|
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
|
|
*/
|
|
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,
|
|
);
|
|
}
|
|
|
|
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());
|
|
$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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|