ldc-boutique-cnc-sable/tests/Unit/Domain/Models/ValueObjects/DeliveryAddressTest.php

75 lines
2.3 KiB
PHP
Raw Permalink 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\DeliveryAddress;
describe('DeliveryAddress', function (): void {
it('can instantiate and convert to array', function (): void {
// GIVEN
$address = new DeliveryAddress(
'Name',
'1 rue',
'75001',
'Paris',
'0123456789',
'48.8',
'2.3'
// WHEN
);
// THEN
expect($address->toArray())->toBe([
'name' => 'Name',
'address' => '1 rue',
'postcode' => '75001',
'city' => 'Paris',
'phone' => '0123456789',
'latitude' => '48.8',
'longitude' => '2.3',
]);
});
it('throws exception if name is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new DeliveryAddress('', '1 rue', '75001', 'Paris');
// THEN
expect($action)->toThrow(\DomainException::class, 'Store name cannot be empty.');
});
it('throws exception if address is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new DeliveryAddress('Name', '', '75001', 'Paris');
// THEN
expect($action)->toThrow(\DomainException::class, 'Address cannot be empty.');
});
it('throws exception if postcode is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new DeliveryAddress('Name', '1 rue', '', 'Paris');
// THEN
expect($action)->toThrow(\DomainException::class, 'Postcode cannot be empty.');
});
it('throws exception if city is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new DeliveryAddress('Name', '1 rue', '75001', '');
// THEN
expect($action)->toThrow(\DomainException::class, 'City cannot be empty.');
});
it('throws exception if latitude is set without longitude', function (): void {
// GIVEN
// WHEN
$action = fn () => new DeliveryAddress('Name', '1 rue', '75001', 'Paris', null, '48.8', null);
// THEN
expect($action)->toThrow(\DomainException::class, 'Longitude must be provided if latitude is.');
});
});