124 lines
3.9 KiB
PHP
124 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Shops\CreateShopInput;
|
|
use Domain\Models\ValueObjects\Coordinates;
|
|
use Domain\Models\ValueObjects\PhoneNumber;
|
|
use InvalidArgumentException;
|
|
|
|
describe('CreateShopInput', function () {
|
|
test('it can be instantiated with valid data', function () {
|
|
// GIVEN
|
|
$name = 'Boutique Paris';
|
|
$address = '10 rue Royale';
|
|
$postcode = '75008';
|
|
$city = 'Paris';
|
|
$phone = new PhoneNumber('+33102030405');
|
|
$coordinates = new Coordinates(48.8566, 2.3522);
|
|
$default = true;
|
|
|
|
// WHEN
|
|
$input = new CreateShopInput(
|
|
name: $name,
|
|
address: $address,
|
|
postcode: $postcode,
|
|
city: $city,
|
|
phone: $phone,
|
|
coordinates: $coordinates,
|
|
default: $default,
|
|
);
|
|
|
|
// THEN
|
|
expect($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)->toBeTrue();
|
|
});
|
|
|
|
test('it can be instantiated with null optional values', function () {
|
|
// GIVEN & WHEN
|
|
$input = new CreateShopInput(
|
|
name: 'Boutique Lyon',
|
|
address: '1 Place Bellecour',
|
|
postcode: '69002',
|
|
city: 'Lyon',
|
|
phone: null,
|
|
coordinates: null,
|
|
default: false,
|
|
);
|
|
|
|
// THEN
|
|
expect($input->phone)->toBeNull()
|
|
->and($input->coordinates)->toBeNull()
|
|
->and($input->default)->toBeFalse();
|
|
});
|
|
|
|
test('it throws when name is empty', function () {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn () => new CreateShopInput(
|
|
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 & WHEN & THEN
|
|
expect(fn () => new CreateShopInput(
|
|
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 & WHEN & THEN
|
|
expect(fn () => new CreateShopInput(
|
|
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 & WHEN & THEN
|
|
expect(fn () => new CreateShopInput(
|
|
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 & WHEN & THEN
|
|
expect(fn () => new CreateShopInput(
|
|
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.');
|
|
});
|
|
});
|