ldc-cocotte/tests/Integration/WithApp/Directories/EloquentCustomerDirectoryTest.php
2026-10-27 09:58:24 +01:00

68 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Directories\EloquentCustomerDirectory;
use App\Models\Customer;
use Domain\Models\ValueObjects\Email;
use Ramsey\Uuid\Uuid;
describe('EloquentCustomerDirectory', function () {
it('finds a customer by uuid', function () {
// GIVEN
$directory = new EloquentCustomerDirectory();
$customer = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => new Email('test@example.com'),
]);
// WHEN
$result = $directory->find(Uuid::fromString($customer->id));
// THEN
expect($result)->not->toBeNull();
expect($result->id)->toBe($customer->id);
});
it('returns null if customer not found', function () {
// GIVEN
$directory = new EloquentCustomerDirectory();
// WHEN
$result = $directory->find(Uuid::uuid7());
// THEN
expect($result)->toBeNull();
});
it('gets a customer by email', function () {
// GIVEN
$directory = new EloquentCustomerDirectory();
$email = new Email('testfind@example.com');
$customer = Customer::forceCreate([
'id' => Uuid::uuid7()->toString(),
'hashcode' => Uuid::uuid4()->toString(),
'email' => $email,
]);
// WHEN
$result = $directory->getCustomerByEmail($email);
// THEN
expect($result)->not->toBeNull();
expect($result->id)->toBe($customer->id);
});
it('returns null if customer by email not found', function () {
// GIVEN
$directory = new EloquentCustomerDirectory();
$email = new Email('notfound@example.com');
// WHEN
$result = $directory->getCustomerByEmail($email);
// THEN
expect($result)->toBeNull();
});
});