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.
This commit is contained in:
parent
6b649a8e7d
commit
3398aacc86
23 changed files with 67 additions and 88 deletions
|
|
@ -8,7 +8,6 @@ use Domain\Models\ValueObjects\DeliveryAddress;
|
|||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/** @implements CastsAttributes<DeliveryAddress,DeliveryAddress> */
|
||||
class DeliveryAddressCast implements CastsAttributes
|
||||
|
|
@ -30,7 +29,7 @@ class DeliveryAddressCast implements CastsAttributes
|
|||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new InvalidArgumentException('The value must be a string.');
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
|
@ -53,10 +52,10 @@ class DeliveryAddressCast implements CastsAttributes
|
|||
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
||||
{
|
||||
if (! $value instanceof DeliveryAddress) {
|
||||
throw new InvalidArgumentException('The value must be an instance of DeliveryAddress.');
|
||||
throw new \InvalidArgumentException('The value must be an instance of DeliveryAddress.');
|
||||
}
|
||||
|
||||
return json_encode($value->toArray(), JSON_UNESCAPED_UNICODE) ?:
|
||||
throw new InvalidArgumentException('Cannot encode DeliveryAddress to JSON.');
|
||||
throw new \InvalidArgumentException('Cannot encode DeliveryAddress to JSON.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ use Domain\Enums\DiscountType;
|
|||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use InvalidArgumentException;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/** @implements CastsAttributes<DiscountValue, DiscountValue> */
|
||||
class DiscountValueCast implements CastsAttributes
|
||||
|
|
@ -22,17 +20,17 @@ class DiscountValueCast implements CastsAttributes
|
|||
$typeRaw = $attributes['type'] ?? null;
|
||||
|
||||
if ($typeRaw === null || (! is_int($typeRaw) && ! is_string($typeRaw))) {
|
||||
throw new UnexpectedValueException('The discount type attribute is missing to cast the value.');
|
||||
throw new \UnexpectedValueException('The discount type attribute is missing to cast the value.');
|
||||
}
|
||||
|
||||
if ($value === null || (! is_int($value) && ! (is_string($value) && ctype_digit($value)))) {
|
||||
throw new UnexpectedValueException('The discount value must be an integer or a numeric string.');
|
||||
throw new \UnexpectedValueException('The discount value must be an integer or a numeric string.');
|
||||
}
|
||||
|
||||
$type = DiscountType::tryFrom((int) $typeRaw);
|
||||
|
||||
if ($type === null) {
|
||||
throw new UnexpectedValueException("Unknown discount type raw value: {$typeRaw}");
|
||||
throw new \UnexpectedValueException("Unknown discount type raw value: {$typeRaw}");
|
||||
}
|
||||
|
||||
// Instanciation selon le type
|
||||
|
|
@ -49,11 +47,11 @@ class DiscountValueCast implements CastsAttributes
|
|||
public function set(Model $model, string $key, mixed $value, array $attributes): int
|
||||
{
|
||||
if ($value === null) {
|
||||
throw new InvalidArgumentException('The value cannot be null.');
|
||||
throw new \InvalidArgumentException('The value cannot be null.');
|
||||
}
|
||||
|
||||
if (! ($value instanceof DiscountValue)) {
|
||||
throw new InvalidArgumentException('The value must be an instance of DiscountValue.');
|
||||
throw new \InvalidArgumentException('The value must be an instance of DiscountValue.');
|
||||
}
|
||||
|
||||
$discountValue = $value->value();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use Domain\Models\ValueObjects\NutritionalValues;
|
|||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/** @implements CastsAttributes<NutritionalValues|null,NutritionalValues|null> */
|
||||
class NutritionalValuesCast implements CastsAttributes
|
||||
|
|
@ -59,7 +58,7 @@ class NutritionalValuesCast implements CastsAttributes
|
|||
}
|
||||
|
||||
if (! $value instanceof NutritionalValues) {
|
||||
throw new InvalidArgumentException('The given value is not a NutritionalValues instance.');
|
||||
throw new \InvalidArgumentException('The given value is not a NutritionalValues instance.');
|
||||
}
|
||||
|
||||
return $value->toArray();
|
||||
|
|
@ -80,7 +79,7 @@ class NutritionalValuesCast implements CastsAttributes
|
|||
|
||||
throw_if(
|
||||
$value !== null,
|
||||
InvalidArgumentException::class,
|
||||
\InvalidArgumentException::class,
|
||||
"Expected `{$key}` to be numeric of null"
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use Domain\Models\ValueObjects\ShopperSiteCode;
|
|||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/** @implements CastsAttributes<OrderEmployee|null,OrderEmployee|null> */
|
||||
class OrderEmployeeCast implements CastsAttributes
|
||||
|
|
@ -25,7 +24,7 @@ class OrderEmployeeCast implements CastsAttributes
|
|||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new InvalidArgumentException('The value must be a string.');
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
|
@ -48,7 +47,7 @@ class OrderEmployeeCast implements CastsAttributes
|
|||
}
|
||||
|
||||
if (! $value instanceof OrderEmployee) {
|
||||
throw new InvalidArgumentException('The given value is not an instance of OrderEmployee.');
|
||||
throw new \InvalidArgumentException('The given value is not an instance of OrderEmployee.');
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use Domain\Models\ValueObjects\ProductWeight;
|
|||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\Uid\Uuid as SymfonyUuid;
|
||||
|
||||
|
|
@ -27,11 +26,11 @@ class OrderLineProductCast implements CastsAttributes
|
|||
public function get(Model $model, string $key, mixed $value, array $attributes): OrderLineProduct
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new InvalidArgumentException('The value cannot be null.');
|
||||
throw new \InvalidArgumentException('The value cannot be null.');
|
||||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new InvalidArgumentException('The value must be a string.');
|
||||
throw new \InvalidArgumentException('The value must be a string.');
|
||||
}
|
||||
|
||||
$data = Arr::wrap(json_decode($value, true));
|
||||
|
|
@ -67,7 +66,7 @@ class OrderLineProductCast implements CastsAttributes
|
|||
{
|
||||
|
||||
if (! ($value instanceof OrderLineProduct)) {
|
||||
throw new InvalidArgumentException('The given value is not an instance of OrderLineProduct.');
|
||||
throw new \InvalidArgumentException('The given value is not an instance of OrderLineProduct.');
|
||||
}
|
||||
|
||||
/** @var OrderLineProduct $value */
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ use Domain\Models\ValueObjects\PictureMetadata;
|
|||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('CreateRange action', function () {
|
||||
test('it creates and persists a range in database', function () {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
Storage::fake('public');
|
||||
$action = new CreateRange();
|
||||
|
|
@ -56,6 +56,6 @@ describe('CreateRange action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ use App\Actions\Ranges\DeleteRangeInput;
|
|||
use App\Contracts\ActionInput;
|
||||
use App\Models\Range;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('DeleteRange action', function () {
|
||||
test('it deletes an existing range from database', function () {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
$range = new Range();
|
||||
$range->name = 'Gamme Temporaire';
|
||||
|
|
@ -43,6 +43,6 @@ describe('DeleteRange action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ use Domain\Models\ValueObjects\PictureMetadata;
|
|||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('UpdateRange action', function () {
|
||||
test('it updates an existing range in database', function () {
|
||||
/** @var \Tests\TestCase $this */
|
||||
// GIVEN
|
||||
Storage::fake('public');
|
||||
$range = new Range();
|
||||
|
|
@ -64,6 +64,6 @@ describe('UpdateRange action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use App\Models\Shop;
|
|||
use Domain\Models\ValueObjects\Coordinates;
|
||||
use Domain\Models\ValueObjects\PhoneNumber;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
|
|
@ -58,6 +57,6 @@ describe('CreateShop action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use App\Actions\Shops\DeleteShopInput;
|
|||
use App\Contracts\ActionInput;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
|
|
@ -38,6 +37,6 @@ describe('DeleteShop action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use App\Contracts\ActionInput;
|
|||
use App\Models\PickupException;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
|
|
@ -62,6 +61,6 @@ describe('UpdateShopPickupExceptions action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use App\Models\Shop;
|
|||
use Domain\Models\ValueObjects\Coordinates;
|
||||
use Domain\Models\ValueObjects\PhoneNumber;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
|
|
@ -66,6 +65,6 @@ describe('UpdateShop action', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => $action($invalidInput))
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use App\Queries\Shops\GetShopQueryInput;
|
|||
use Carbon\Carbon;
|
||||
use Domain\Enums\RepeatFrequency;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('GetShopQuery', function (): void {
|
||||
it('returns the default shop mapped as ShopDto with pickup exceptions', function (): void {
|
||||
|
|
@ -77,6 +76,6 @@ describe('GetShopQuery', function (): void {
|
|||
expect(
|
||||
/** @phpstan-ignore argument.type */
|
||||
fn () => $query($invalidInput)
|
||||
)->toThrow(InvalidArgumentException::class);
|
||||
)->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use App\Actions\Discounts\CreateDiscountInput;
|
|||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use InvalidArgumentException;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
|
||||
|
|
@ -67,7 +66,7 @@ describe('CreateDiscountInput', function (): void {
|
|||
is_old_price_displayed: true,
|
||||
))
|
||||
// THEN
|
||||
->toThrow(InvalidArgumentException::class, 'The discount value type must match the discount type.');
|
||||
->toThrow(\InvalidArgumentException::class, 'The discount value type must match the discount type.');
|
||||
});
|
||||
|
||||
it('throws when associatedProductsIds contains non-string items', function (): void {
|
||||
|
|
@ -83,6 +82,6 @@ describe('CreateDiscountInput', function (): void {
|
|||
associatedProductsIds: [123], // @phpstan-ignore argument.type
|
||||
))
|
||||
// THEN
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use App\Models\Discount;
|
|||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
use InvalidArgumentException;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ describe('UpdateDiscountInput', function (): void {
|
|||
is_old_price_displayed: true,
|
||||
))
|
||||
// THEN
|
||||
->toThrow(InvalidArgumentException::class, 'The discount value type must match the discount type.');
|
||||
->toThrow(\InvalidArgumentException::class, 'The discount value type must match the discount type.');
|
||||
});
|
||||
|
||||
it('throws when associatedProductsIds contains non-string items', function (): void {
|
||||
|
|
@ -93,6 +92,6 @@ describe('UpdateDiscountInput', function (): void {
|
|||
associatedProductsIds: [123], // @phpstan-ignore argument.type
|
||||
))
|
||||
// THEN
|
||||
->toThrow(InvalidArgumentException::class);
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
use App\Actions\Ranges\CreateRangeInput;
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('CreateRangeInput', function () {
|
||||
test('it can be instantiated with valid data without picture', function () {
|
||||
|
|
@ -62,7 +61,7 @@ describe('CreateRangeInput', function () {
|
|||
picture: null,
|
||||
pictureMetadata: new PictureMetadata(),
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'The range name cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'The range name cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when name is shorter than 2 characters', function () {
|
||||
|
|
@ -76,7 +75,7 @@ describe('CreateRangeInput', function () {
|
|||
picture: null,
|
||||
pictureMetadata: new PictureMetadata(),
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'The range name must be at least 2 characters.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'The range name must be at least 2 characters.');
|
||||
});
|
||||
|
||||
test('it throws when name exceeds 45 characters', function () {
|
||||
|
|
@ -90,7 +89,7 @@ describe('CreateRangeInput', function () {
|
|||
picture: null,
|
||||
pictureMetadata: new PictureMetadata(),
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'The range name cannot exceed 45 characters.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'The range name cannot exceed 45 characters.');
|
||||
});
|
||||
|
||||
test('it throws when picture is provided without alt', function () {
|
||||
|
|
@ -105,7 +104,7 @@ describe('CreateRangeInput', function () {
|
|||
picture: $picture,
|
||||
pictureMetadata: $pictureMetadata,
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'Picture alt is required when picture is provided.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Picture alt is required when picture is provided.');
|
||||
});
|
||||
|
||||
test('it throws when picture is provided without title', function () {
|
||||
|
|
@ -120,6 +119,6 @@ describe('CreateRangeInput', function () {
|
|||
picture: $picture,
|
||||
pictureMetadata: $pictureMetadata,
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'Picture title is required when picture is provided.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Picture title is required when picture is provided.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use App\Actions\Ranges\UpdateRangeInput;
|
|||
use App\Models\Range;
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('UpdateRangeInput', function () {
|
||||
test('it can be instantiated with valid data', function () {
|
||||
|
|
@ -46,7 +45,7 @@ describe('UpdateRangeInput', function () {
|
|||
picture: null,
|
||||
pictureMetadata: new PictureMetadata(),
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'The range name cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'The range name cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when picture is provided without alt or title', function () {
|
||||
|
|
@ -62,6 +61,6 @@ describe('UpdateRangeInput', function () {
|
|||
picture: $picture,
|
||||
pictureMetadata: new PictureMetadata(alt: null, title: 'Title'),
|
||||
status: true,
|
||||
))->toThrow(InvalidArgumentException::class, 'Picture alt is required when picture is provided.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Picture alt is required when picture is provided.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ 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 () {
|
||||
|
|
@ -67,7 +66,7 @@ describe('CreateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop name cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when address is empty', function () {
|
||||
|
|
@ -80,7 +79,7 @@ describe('CreateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop address cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop address cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when postcode is empty', function () {
|
||||
|
|
@ -93,7 +92,7 @@ describe('CreateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop postcode cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop postcode cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when city is empty', function () {
|
||||
|
|
@ -106,7 +105,7 @@ describe('CreateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop city cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop city cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when name exceeds 255 characters', function () {
|
||||
|
|
@ -119,6 +118,6 @@ describe('CreateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use App\Actions\Shops\UpdateShopInput;
|
|||
use App\Models\Shop;
|
||||
use Domain\Models\ValueObjects\Coordinates;
|
||||
use Domain\Models\ValueObjects\PhoneNumber;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('UpdateShopInput', function () {
|
||||
test('it can be instantiated with valid data', function () {
|
||||
|
|
@ -57,7 +56,7 @@ describe('UpdateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop name cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when address is empty', function () {
|
||||
|
|
@ -74,7 +73,7 @@ describe('UpdateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop address cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop address cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when postcode is empty', function () {
|
||||
|
|
@ -91,7 +90,7 @@ describe('UpdateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop postcode cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop postcode cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when city is empty', function () {
|
||||
|
|
@ -108,7 +107,7 @@ describe('UpdateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop city cannot be empty.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop city cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when name exceeds 255 characters', function () {
|
||||
|
|
@ -125,6 +124,6 @@ describe('UpdateShopInput', function () {
|
|||
phone: null,
|
||||
coordinates: null,
|
||||
default: false,
|
||||
))->toThrow(InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
|
||||
))->toThrow(\InvalidArgumentException::class, 'Shop name cannot exceed 255 characters.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
use App\Actions\Shops\UpdateShopPickupExceptionsInput;
|
||||
use App\Models\Shop;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('UpdateShopPickupExceptionsInput', function () {
|
||||
test('it can be instantiated with shop and valid sync data', function () {
|
||||
|
|
@ -57,7 +56,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
// WHEN & THEN
|
||||
/** @phpstan-ignore-next-line */
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'Each sync item must be an array.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Each sync item must be an array.');
|
||||
});
|
||||
|
||||
test('it throws when replacement_date key is missing', function () {
|
||||
|
|
@ -72,7 +71,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
// WHEN & THEN
|
||||
/** @phpstan-ignore-next-line */
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'Sync item must contain replacement_date key.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Sync item must contain replacement_date key.');
|
||||
});
|
||||
|
||||
test('it throws when order_deadline_at key is missing', function () {
|
||||
|
|
@ -87,7 +86,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
// WHEN & THEN
|
||||
/** @phpstan-ignore-next-line */
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'Sync item must contain order_deadline_at key.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Sync item must contain order_deadline_at key.');
|
||||
});
|
||||
|
||||
test('it throws when replacement_date is not string or null', function () {
|
||||
|
|
@ -103,7 +102,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
// WHEN & THEN
|
||||
/** @phpstan-ignore-next-line */
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'replacement_date must be a string or null.');
|
||||
->toThrow(\InvalidArgumentException::class, 'replacement_date must be a string or null.');
|
||||
});
|
||||
|
||||
test('it throws when order_deadline_at is not string or null', function () {
|
||||
|
|
@ -119,7 +118,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
// WHEN & THEN
|
||||
/** @phpstan-ignore-next-line */
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'order_deadline_at must be a string or null.');
|
||||
->toThrow(\InvalidArgumentException::class, 'order_deadline_at must be a string or null.');
|
||||
});
|
||||
|
||||
test('it throws when order_deadline_at is set but replacement_date is null', function () {
|
||||
|
|
@ -134,7 +133,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'A replacement date is required when an order deadline is set.');
|
||||
->toThrow(\InvalidArgumentException::class, 'A replacement date is required when an order deadline is set.');
|
||||
});
|
||||
|
||||
test('it throws when order_deadline_at is after replacement_date', function () {
|
||||
|
|
@ -149,7 +148,7 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
||||
});
|
||||
|
||||
test('it throws when order_deadline_at is equal to replacement_date', function () {
|
||||
|
|
@ -164,6 +163,6 @@ describe('UpdateShopPickupExceptionsInput', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new UpdateShopPickupExceptionsInput(shop: $shop, syncData: $invalidSyncData))
|
||||
->toThrow(InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Order deadline must be strictly before the replacement date.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('PictureMetadata Value Object', function () {
|
||||
test('it can be instantiated with null values', function () {
|
||||
|
|
@ -34,7 +33,7 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(alt: $invalidAlt))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture alt cannot be empty when provided.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot be empty when provided.');
|
||||
});
|
||||
|
||||
test('it throws when alt is shorter than 4 characters', function () {
|
||||
|
|
@ -43,7 +42,7 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(alt: $shortAlt))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture alt must be at least 4 characters.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture alt must be at least 4 characters.');
|
||||
});
|
||||
|
||||
test('it throws when alt exceeds 75 characters', function () {
|
||||
|
|
@ -52,7 +51,7 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(alt: $longAlt))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture alt cannot exceed 75 characters.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot exceed 75 characters.');
|
||||
});
|
||||
|
||||
test('it throws when title is empty string', function () {
|
||||
|
|
@ -61,7 +60,7 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(title: $invalidTitle))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture title cannot be empty when provided.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture title cannot be empty when provided.');
|
||||
});
|
||||
|
||||
test('it throws when title is shorter than 4 characters', function () {
|
||||
|
|
@ -70,7 +69,7 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(title: $shortTitle))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture title must be at least 4 characters.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture title must be at least 4 characters.');
|
||||
});
|
||||
|
||||
test('it throws when title exceeds 75 characters', function () {
|
||||
|
|
@ -79,6 +78,6 @@ describe('PictureMetadata Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new PictureMetadata(title: $longTitle))
|
||||
->toThrow(InvalidArgumentException::class, 'Picture title cannot exceed 75 characters.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Picture title cannot exceed 75 characters.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Domain\Models\ValueObjects\Slug;
|
||||
use InvalidArgumentException;
|
||||
|
||||
describe('Slug Value Object', function () {
|
||||
test('it can be instantiated with a valid slug', function () {
|
||||
|
|
@ -24,7 +23,7 @@ describe('Slug Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new Slug($empty))
|
||||
->toThrow(InvalidArgumentException::class, 'Slug cannot be empty.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Slug cannot be empty.');
|
||||
});
|
||||
|
||||
test('it throws when slug exceeds 255 characters', function () {
|
||||
|
|
@ -33,7 +32,7 @@ describe('Slug Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new Slug($long))
|
||||
->toThrow(InvalidArgumentException::class, 'Slug cannot exceed 255 characters.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Slug cannot exceed 255 characters.');
|
||||
});
|
||||
|
||||
test('it throws when slug format is invalid', function () {
|
||||
|
|
@ -42,7 +41,7 @@ describe('Slug Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => new Slug($invalid))
|
||||
->toThrow(InvalidArgumentException::class, 'Slug format is invalid.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Slug format is invalid.');
|
||||
});
|
||||
|
||||
test('it creates slug from raw string with fromString', function () {
|
||||
|
|
@ -63,6 +62,6 @@ describe('Slug Value Object', function () {
|
|||
|
||||
// WHEN & THEN
|
||||
expect(fn () => Slug::fromString($raw))
|
||||
->toThrow(InvalidArgumentException::class, 'Cannot generate a valid slug from given string.');
|
||||
->toThrow(\InvalidArgumentException::class, 'Cannot generate a valid slug from given string.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ use Illuminate\Contracts\Auth\Authenticatable;
|
|||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
||||
use InvalidArgumentException;
|
||||
use Mockery;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use stdClass;
|
||||
|
|
@ -99,7 +98,7 @@ describe('AppCustomerAuthService', function (): void {
|
|||
$action = fn () => $service->logIn($invalidCustomer);
|
||||
|
||||
// THEN
|
||||
expect($action)->toThrow(InvalidArgumentException::class, 'Expected an instance of Authenticatable and Customer for logging in');
|
||||
expect($action)->toThrow(\InvalidArgumentException::class, 'Expected an instance of Authenticatable and Customer for logging in');
|
||||
});
|
||||
|
||||
it('logs out', function (): void {
|
||||
|
|
@ -204,7 +203,7 @@ describe('AppCustomerAuthService', function (): void {
|
|||
$action = fn () => $service->getCustomer();
|
||||
|
||||
// THEN
|
||||
expect($action)->toThrow(InvalidArgumentException::class, 'Auth service needs a frontend guard');
|
||||
expect($action)->toThrow(\InvalidArgumentException::class, 'Auth service needs a frontend guard');
|
||||
});
|
||||
|
||||
it('gets customer as mandatory', function (): void {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue