ldc-boutique-cnc-sable/tests/Unit/Domain/Exceptions/ExceptionsTest.php
2026-10-27 09:58:12 +01:00

86 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Exceptions;
use Domain\Enums\Country;
use Domain\Exceptions\OrderTunnel\MissingOrderBuilderException;
use Domain\Exceptions\OrderTunnel\OrderLimitExceededException;
use Domain\Exceptions\OrderTunnel\WeeklyLimitExceededException;
use Domain\Exceptions\UnknownCountryIsoCodeException;
use RuntimeException;
describe('Exceptions', function () {
it('creates MissingOrderBuilderException correctly', function () {
// GIVEN
$expectedMessage = 'Order builder is missing or not in expected state.';
// WHEN
$e = new MissingOrderBuilderException();
// THEN
expect($e->getMessage())->toBe($expectedMessage);
});
it('creates MissingOrderBuilderException with custom args', function () {
// GIVEN
$message = 'Custom error';
$code = 123;
$previous = new RuntimeException('Prev');
// WHEN
$e = new MissingOrderBuilderException($message, $code, $previous);
// THEN
expect($e->getMessage())->toBe($message)
->and($e->getCode())->toBe($code)
->and($e->getPrevious())->toBe($previous);
});
it('creates OrderLimitExceededException correctly', function () {
// GIVEN
$expectedMessage = 'The total amount of this order has been exceeded. Please modify it to validate.';
// WHEN
$e = new OrderLimitExceededException();
// THEN
expect($e->getMessage())->toBe($expectedMessage);
});
it('creates WeeklyLimitExceededException correctly', function () {
// GIVEN
$expectedMessage = 'The total amount for this delivery date has been exceeded. Please modify it to validate.';
// WHEN
$e = new WeeklyLimitExceededException();
// THEN
expect($e->getMessage())->toBe($expectedMessage);
});
it('creates UnknownCountryIsoCodeException from iso code', function () {
// GIVEN
$isoCode = 'ZZ';
$expectedMessage = "No country found for ISO code 'ZZ'";
// WHEN
$e = UnknownCountryIsoCodeException::fromIsoCode($isoCode);
// THEN
expect($e->getMessage())->toBe($expectedMessage);
});
it('creates UnknownCountryIsoCodeException from country', function () {
// GIVEN
$country = Country::france;
$expectedMessage = "No ISO code found for country 'france'";
// WHEN
$e = UnknownCountryIsoCodeException::fromCountry($country);
// THEN
expect($e->getMessage())->toBe($expectedMessage);
});
});