74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Dto;
|
|
|
|
use App\Dto\ShopDto;
|
|
use App\Models\PickupException;
|
|
use App\Models\Shop;
|
|
|
|
describe('ShopDto Integration', function () {
|
|
test('it maps from Shop Eloquent model correctly', function () {
|
|
// GIVEN
|
|
$shop = new Shop();
|
|
$shop->name = 'Boutique Centre';
|
|
$shop->address = '10 rue Centrale';
|
|
$shop->postcode = '69002';
|
|
$shop->city = 'Lyon';
|
|
$shop->phone = '+33472000000';
|
|
$shop->default = true;
|
|
$shop->save();
|
|
|
|
// WHEN
|
|
$dto = ShopDto::fromModel($shop);
|
|
|
|
// THEN
|
|
expect($dto->id)->toBe($shop->id)
|
|
->and($dto->name)->toBe('Boutique Centre')
|
|
->and($dto->address)->toBe('10 rue Centrale')
|
|
->and($dto->postcode)->toBe('69002')
|
|
->and($dto->city)->toBe('Lyon')
|
|
->and($dto->phone)->toBe('+33472000000')
|
|
->and($dto->default)->toBeTrue()
|
|
->and($dto->getRouteKey())->toBe($shop->id)
|
|
->and($dto->getRouteKeyName())->toBe('id')
|
|
->and($dto->toArray())->toBe([
|
|
'id' => $shop->id,
|
|
'name' => 'Boutique Centre',
|
|
'address' => '10 rue Centrale',
|
|
'postcode' => '69002',
|
|
'city' => 'Lyon',
|
|
'phone' => '+33472000000',
|
|
'latitude' => null,
|
|
'longitude' => null,
|
|
'default' => true,
|
|
]);
|
|
});
|
|
|
|
test('it maps loaded pickupExceptions relation correctly', function () {
|
|
// GIVEN
|
|
$shop = Shop::factory()->create();
|
|
$exception = PickupException::factory()->create();
|
|
$shop->pickupExceptions()->attach($exception->id, [
|
|
'replacement_date' => '2026-06-01',
|
|
'order_deadline_at' => '2026-05-31 12:00:00',
|
|
]);
|
|
$shop->load('pickupExceptions');
|
|
|
|
// WHEN
|
|
$dto = ShopDto::fromModel($shop);
|
|
|
|
// THEN
|
|
$pickupExceptions = $dto->pickupExceptions;
|
|
assert($pickupExceptions !== null);
|
|
$firstException = $pickupExceptions->first();
|
|
assert($firstException !== null);
|
|
$pivot = $firstException->pivot;
|
|
assert($pivot !== null);
|
|
|
|
expect($pickupExceptions)->toHaveCount(1)
|
|
->and($firstException->id)->toBe($exception->id)
|
|
->and($pivot->replacement_date?->format('Y-m-d'))->toBe('2026-06-01');
|
|
});
|
|
});
|