74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Dto\ShopDto;
|
|
use Domain\Models\Entities\Shop;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('ShopDto', function () {
|
|
test('it can be instantiated directly and converts to array', function () {
|
|
// GIVEN & WHEN
|
|
$dto = new ShopDto(
|
|
id: '018f4a2b-3c4d-7e8f-9a0b-1c2d3e4f5a6b',
|
|
name: 'Boutique Principale',
|
|
address: '1 rue de Paris',
|
|
postcode: '75001',
|
|
city: 'Paris',
|
|
phone: '+33102030405',
|
|
latitude: '48.8566',
|
|
longitude: '2.3522',
|
|
default: true,
|
|
);
|
|
|
|
// THEN
|
|
expect($dto->id)->toBe('018f4a2b-3c4d-7e8f-9a0b-1c2d3e4f5a6b')
|
|
->and($dto->name)->toBe('Boutique Principale')
|
|
->and($dto->getRouteKey())->toBe('018f4a2b-3c4d-7e8f-9a0b-1c2d3e4f5a6b')
|
|
->and($dto->getRouteKeyName())->toBe('id')
|
|
->and($dto->default)->toBeTrue()
|
|
->and($dto->toArray())->toBe([
|
|
'id' => '018f4a2b-3c4d-7e8f-9a0b-1c2d3e4f5a6b',
|
|
'name' => 'Boutique Principale',
|
|
'address' => '1 rue de Paris',
|
|
'postcode' => '75001',
|
|
'city' => 'Paris',
|
|
'phone' => '+33102030405',
|
|
'latitude' => '48.8566',
|
|
'longitude' => '2.3522',
|
|
'default' => true,
|
|
]);
|
|
});
|
|
|
|
test('it can be created from domain Shop entity', function () {
|
|
// GIVEN
|
|
$uuid = Uuid::uuid7();
|
|
$shopId = new ShopId($uuid);
|
|
$domainShop = new Shop(
|
|
id: $shopId,
|
|
name: 'Boutique Domain',
|
|
address: '10 avenue de la Gare',
|
|
postcode: '69001',
|
|
city: 'Lyon',
|
|
phone: '0478000000',
|
|
latitude: '45.75',
|
|
longitude: '4.85',
|
|
isDefault: true,
|
|
);
|
|
|
|
// WHEN
|
|
$dto = ShopDto::fromDomain($domainShop);
|
|
|
|
// THEN
|
|
expect($dto->id)->toBe($uuid->toString())
|
|
->and($dto->name)->toBe('Boutique Domain')
|
|
->and($dto->address)->toBe('10 avenue de la Gare')
|
|
->and($dto->postcode)->toBe('69001')
|
|
->and($dto->city)->toBe('Lyon')
|
|
->and($dto->phone)->toBe('0478000000')
|
|
->and($dto->latitude)->toBe('45.75')
|
|
->and($dto->longitude)->toBe('4.85')
|
|
->and($dto->default)->toBeTrue();
|
|
});
|
|
});
|