ldc-cocotte/tests/Unit/App/Actions/Shops/UpdateShopInputTest.php
Jérémy Munsch 3398aacc86
refactor(casts): update exception handling to use fully qualified class names
Refactored exception handling in various cast classes to use fully qualified class names for InvalidArgumentException and UnexpectedValueException.
2026-10-27 09:58:45 +01:00

129 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Shops\UpdateShopInput;
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,
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot be empty.');
});
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,
))->toThrow(\InvalidArgumentException::class, 'Shop address cannot be empty.');
});
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,
))->toThrow(\InvalidArgumentException::class, 'Shop postcode cannot be empty.');
});
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,
))->toThrow(\InvalidArgumentException::class, 'Shop city cannot be empty.');
});
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,
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
});
});