93 lines
2.6 KiB
PHP
93 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\Entities;
|
|
|
|
use Domain\Models\Entities\Shop;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('Shop', function (): void {
|
|
it('can instantiate correctly', function (): void {
|
|
// GIVEN
|
|
$id = new ShopId(Uuid::uuid7());
|
|
$name = 'Boutique';
|
|
$address = '123 Rue de Paris';
|
|
$postcode = '75001';
|
|
$city = 'Paris';
|
|
$phone = '0123456789';
|
|
$lat = '48.8566';
|
|
$lon = '2.3522';
|
|
$isDefault = true;
|
|
|
|
// WHEN
|
|
$entity = new Shop(
|
|
$id,
|
|
$name,
|
|
$address,
|
|
$postcode,
|
|
$city,
|
|
$phone,
|
|
$lat,
|
|
$lon,
|
|
$isDefault
|
|
);
|
|
|
|
// THEN
|
|
expect($entity->id())->toBe($id)
|
|
->and($entity->id)->toBe($id)
|
|
->and($entity->name)->toBe($name)
|
|
->and($entity->address)->toBe($address)
|
|
->and($entity->postcode)->toBe($postcode)
|
|
->and($entity->city)->toBe($city)
|
|
->and($entity->phone)->toBe($phone)
|
|
->and($entity->latitude)->toBe($lat)
|
|
->and($entity->longitude)->toBe($lon)
|
|
->and($entity->isDefault)->toBe($isDefault);
|
|
});
|
|
|
|
it('throws exception if name is empty', function (): void {
|
|
// GIVEN
|
|
$id = new ShopId(Uuid::uuid7());
|
|
|
|
// WHEN
|
|
$action = fn () => new Shop($id, '', 'Address', '12345', 'City');
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'name cannot be empty');
|
|
});
|
|
|
|
it('throws exception if address is empty', function (): void {
|
|
// GIVEN
|
|
$id = new ShopId(Uuid::uuid7());
|
|
|
|
// WHEN
|
|
$action = fn () => new Shop($id, 'Name', '', '12345', 'City');
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'address cannot be empty');
|
|
});
|
|
|
|
it('throws exception if postcode is empty', function (): void {
|
|
// GIVEN
|
|
$id = new ShopId(Uuid::uuid7());
|
|
|
|
// WHEN
|
|
$action = fn () => new Shop($id, 'Name', 'Address', '', 'City');
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'postcode cannot be empty');
|
|
});
|
|
|
|
it('throws exception if city is empty', function (): void {
|
|
// GIVEN
|
|
$id = new ShopId(Uuid::uuid7());
|
|
|
|
// WHEN
|
|
$action = fn () => new Shop($id, 'Name', 'Address', '12345', '');
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'city cannot be empty');
|
|
});
|
|
});
|