2026-09-30 11:20:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Shops\UpdateShopInput;
|
2026-09-30 11:20:39 +02:00
|
|
|
use App\Models\Shop;
|
|
|
|
|
use Domain\Models\ValueObjects\Coordinates;
|
|
|
|
|
use Domain\Models\ValueObjects\PhoneNumber;
|
|
|
|
|
|
|
|
|
|
describe('UpdateShopInput', function () {
|
|
|
|
|
test('it can be instantiated with valid data', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
$name = 'Boutique Mise à jour';
|
|
|
|
|
$address = '12 Boulevard Haussmann';
|
|
|
|
|
$postcode = '75009';
|
|
|
|
|
$city = 'Paris';
|
|
|
|
|
$phone = new PhoneNumber('+33140506070');
|
|
|
|
|
$coordinates = new Coordinates(48.8738, 2.3319);
|
|
|
|
|
$default = false;
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$input = new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: $name,
|
|
|
|
|
address: $address,
|
|
|
|
|
postcode: $postcode,
|
|
|
|
|
city: $city,
|
|
|
|
|
phone: $phone,
|
|
|
|
|
coordinates: $coordinates,
|
|
|
|
|
default: $default,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($input->shop)->toBe($shop)
|
|
|
|
|
->and($input->name)->toBe($name)
|
|
|
|
|
->and($input->address)->toBe($address)
|
|
|
|
|
->and($input->postcode)->toBe($postcode)
|
|
|
|
|
->and($input->city)->toBe($city)
|
|
|
|
|
->and($input->phone)->toBe($phone)
|
|
|
|
|
->and($input->coordinates)->toBe($coordinates)
|
|
|
|
|
->and($input->default)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when name is empty', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: ' ',
|
|
|
|
|
address: '1 rue de Paris',
|
|
|
|
|
postcode: '75000',
|
|
|
|
|
city: 'Paris',
|
|
|
|
|
phone: null,
|
|
|
|
|
coordinates: null,
|
|
|
|
|
default: false,
|
2026-10-02 10:53:21 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot be empty.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when address is empty', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: 'Boutique',
|
|
|
|
|
address: ' ',
|
|
|
|
|
postcode: '75000',
|
|
|
|
|
city: 'Paris',
|
|
|
|
|
phone: null,
|
|
|
|
|
coordinates: null,
|
|
|
|
|
default: false,
|
2026-10-02 10:53:21 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Shop address cannot be empty.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when postcode is empty', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: 'Boutique',
|
|
|
|
|
address: '1 rue de Paris',
|
|
|
|
|
postcode: ' ',
|
|
|
|
|
city: 'Paris',
|
|
|
|
|
phone: null,
|
|
|
|
|
coordinates: null,
|
|
|
|
|
default: false,
|
2026-10-02 10:53:21 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Shop postcode cannot be empty.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when city is empty', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: 'Boutique',
|
|
|
|
|
address: '1 rue de Paris',
|
|
|
|
|
postcode: '75000',
|
|
|
|
|
city: ' ',
|
|
|
|
|
phone: null,
|
|
|
|
|
coordinates: null,
|
|
|
|
|
default: false,
|
2026-10-02 10:53:21 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Shop city cannot be empty.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when name exceeds 255 characters', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new UpdateShopInput(
|
|
|
|
|
shop: $shop,
|
|
|
|
|
name: str_repeat('a', 256),
|
|
|
|
|
address: '1 rue de Paris',
|
|
|
|
|
postcode: '75000',
|
|
|
|
|
city: 'Paris',
|
|
|
|
|
phone: null,
|
|
|
|
|
coordinates: null,
|
|
|
|
|
default: false,
|
2026-10-02 10:53:21 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
|
2026-09-30 11:20:39 +02:00
|
|
|
});
|
|
|
|
|
});
|