diff --git a/src/Application/Arcadia/Exceptions/EmployeeNotFoundException.php b/src/Application/Arcadia/Exceptions/EmployeeNotFoundException.php new file mode 100644 index 0000000..a64025b --- /dev/null +++ b/src/Application/Arcadia/Exceptions/EmployeeNotFoundException.php @@ -0,0 +1,16 @@ +directory->find($input->id); if ($employee === null) { - throw NotFoundException::forEntity('Employee', (string) $input->id); + throw EmployeeNotFoundException::forEmployee($input->id); } return new Output( diff --git a/src/Application/Arcadia/Usecase/IncoCompositions/Find/FindIncoComposition.php b/src/Application/Arcadia/Usecase/IncoCompositions/Find/FindIncoComposition.php index 01f219a..c9a7afa 100644 --- a/src/Application/Arcadia/Usecase/IncoCompositions/Find/FindIncoComposition.php +++ b/src/Application/Arcadia/Usecase/IncoCompositions/Find/FindIncoComposition.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Application\Arcadia\Usecase\IncoCompositions\Find; -use Application\Shared\Exceptions\NotFoundException; +use Application\Arcadia\Exceptions\IncoCompositionNotFoundException; use Domain\Ports\Directories\IncoCompositionDirectory; use Shared\DDD\Usecase\Input as BaseInput; use Shared\DDD\Usecase\Usecase; @@ -26,7 +26,7 @@ final readonly class FindIncoComposition implements Usecase $incoComposition = $this->directory->findByIncoId($input->incoId); if ($incoComposition === null) { - throw NotFoundException::forEntity('IncoComposition', (string) $input->incoId->value); + throw IncoCompositionNotFoundException::forInco($input->incoId); } return new Output( diff --git a/src/Application/Arcadia/Usecase/IncoSheets/Find/FindIncoSheet.php b/src/Application/Arcadia/Usecase/IncoSheets/Find/FindIncoSheet.php index 4d4db47..f2cfc70 100644 --- a/src/Application/Arcadia/Usecase/IncoSheets/Find/FindIncoSheet.php +++ b/src/Application/Arcadia/Usecase/IncoSheets/Find/FindIncoSheet.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Application\Arcadia\Usecase\IncoSheets\Find; -use Application\Shared\Exceptions\NotFoundException; +use Application\Arcadia\Exceptions\IncoSheetNotFoundException; use Domain\Ports\Directories\IncoSheetDirectory; use Shared\DDD\Usecase\Input as BaseInput; use Shared\DDD\Usecase\Usecase; @@ -26,7 +26,7 @@ final readonly class FindIncoSheet implements Usecase $incoSheet = $this->directory->find($input->id); if ($incoSheet === null) { - throw NotFoundException::forEntity('IncoSheet', $input->id->value); + throw IncoSheetNotFoundException::forIncoSheet($input->id); } return new Output( diff --git a/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php b/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php index cfe6fa9..9dcc608 100644 --- a/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php +++ b/src/Presentation/Api/V1/Exceptions/ApiExceptionRenderer.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace Presentation\Api\V1\Exceptions; -use Application\Shared\Exceptions\NotFoundException; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; use Illuminate\Validation\ValidationException; +use Shared\DDD\Exception\NotFoundException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Throwable; diff --git a/src/Presentation/Web/Exceptions/WebExceptionRenderer.php b/src/Presentation/Web/Exceptions/WebExceptionRenderer.php index 4706613..57f075f 100644 --- a/src/Presentation/Web/Exceptions/WebExceptionRenderer.php +++ b/src/Presentation/Web/Exceptions/WebExceptionRenderer.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Presentation\Web\Exceptions; -use Application\Shared\Exceptions\NotFoundException; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Shared\DDD\Exception\NotFoundException; use Throwable; final readonly class WebExceptionRenderer diff --git a/tests/Unit/Application/Arcadia/Exceptions/EmployeeNotFoundExceptionTest.php b/tests/Unit/Application/Arcadia/Exceptions/EmployeeNotFoundExceptionTest.php new file mode 100644 index 0000000..e6ca360 --- /dev/null +++ b/tests/Unit/Application/Arcadia/Exceptions/EmployeeNotFoundExceptionTest.php @@ -0,0 +1,37 @@ +toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("Employee '01155902' not found."); + }); + + it('creates exception from string', function (): void { + // GIVEN + $id = '01155902'; + + // WHEN + $exception = EmployeeNotFoundException::forEmployee($id); + + // THEN + expect($exception)->toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("Employee '01155902' not found."); + }); +}); diff --git a/tests/Unit/Application/Arcadia/Exceptions/IncoCompositionNotFoundExceptionTest.php b/tests/Unit/Application/Arcadia/Exceptions/IncoCompositionNotFoundExceptionTest.php new file mode 100644 index 0000000..56fa846 --- /dev/null +++ b/tests/Unit/Application/Arcadia/Exceptions/IncoCompositionNotFoundExceptionTest.php @@ -0,0 +1,38 @@ +toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("IncoComposition for inco '12345' not found."); + }); + + it('creates exception for generic entity', function (): void { + // GIVEN + $entity = 'IncoComposition'; + $id = '12345'; + + // WHEN + $exception = IncoCompositionNotFoundException::forEntity($entity, $id); + + // THEN + expect($exception)->toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("IncoComposition '12345' not found."); + }); +}); diff --git a/tests/Unit/Application/Arcadia/Exceptions/IncoSheetNotFoundExceptionTest.php b/tests/Unit/Application/Arcadia/Exceptions/IncoSheetNotFoundExceptionTest.php new file mode 100644 index 0000000..db204c3 --- /dev/null +++ b/tests/Unit/Application/Arcadia/Exceptions/IncoSheetNotFoundExceptionTest.php @@ -0,0 +1,37 @@ +toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("IncoSheet '12345' not found."); + }); + + it('creates exception from string', function (): void { + // GIVEN + $id = '12345'; + + // WHEN + $exception = IncoSheetNotFoundException::forIncoSheet($id); + + // THEN + expect($exception)->toBeInstanceOf(NotFoundException::class) + ->and($exception->getMessage())->toBe("IncoSheet '12345' not found."); + }); +}); diff --git a/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php b/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php index 61bb007..c050303 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Tests\Unit\Application\Arcadia\Usecase\Employees; +use Application\Arcadia\Exceptions\EmployeeNotFoundException; use Application\Arcadia\Usecase\Employees\Find\FindEmployee; use Application\Arcadia\Usecase\Employees\Find\Input; use Application\Arcadia\Usecase\Employees\Find\Output; -use Application\Shared\Exceptions\NotFoundException; use Domain\Models\Entities\Employee; use Domain\Models\ValueObjects\Employees\ArcadiaEmployeeId; use Domain\Models\ValueObjects\EstablishmentCode; @@ -72,6 +72,6 @@ describe('FindEmployee Usecase Unit Tests', function (): void { $execution = fn () => $usecase->execute($input); // THEN - expect($execution)->toThrow(NotFoundException::class, "Employee '01155902' not found."); + expect($execution)->toThrow(EmployeeNotFoundException::class, "Employee '01155902' not found."); }); }); diff --git a/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php b/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php index 8d65b3b..29b9478 100644 --- a/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Tests\Unit\Application\Arcadia\Usecase\IncoCompositions; +use Application\Arcadia\Exceptions\IncoCompositionNotFoundException; use Application\Arcadia\Usecase\IncoCompositions\Find\FindIncoComposition; use Application\Arcadia\Usecase\IncoCompositions\Find\Input; use Application\Arcadia\Usecase\IncoCompositions\Find\Output; -use Application\Shared\Exceptions\NotFoundException; use Domain\Models\Entities\Inco\Composition\IncoComposition; use Domain\Models\ValueObjects\Inco\Composition\AminoAcids; use Domain\Models\ValueObjects\Inco\Composition\CarbohydratesDetail; @@ -117,6 +117,6 @@ describe('FindIncoComposition Usecase Unit Tests', function (): void { $input = new Input($incoId); // WHEN & THEN - expect(fn () => $usecase->execute($input))->toThrow(NotFoundException::class); + expect(fn () => $usecase->execute($input))->toThrow(IncoCompositionNotFoundException::class); }); }); diff --git a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php index 386a538..4c92bc4 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets; +use Application\Arcadia\Exceptions\IncoSheetNotFoundException; use Application\Arcadia\Usecase\IncoSheets\Find\FindIncoSheet; use Application\Arcadia\Usecase\IncoSheets\Find\Input; use Application\Arcadia\Usecase\IncoSheets\Find\Output; -use Application\Shared\Exceptions\NotFoundException; use Domain\Models\Entities\Inco\IncoSheet; use Domain\Models\ValueObjects\Inco\Allegations; use Domain\Models\ValueObjects\Inco\Brand; @@ -79,6 +79,6 @@ describe('FindIncoSheet Usecase Unit Tests', function (): void { // WHEN & THEN expect(fn () => $usecase->execute($input)) - ->toThrow(NotFoundException::class, "IncoSheet '99999' not found."); + ->toThrow(IncoSheetNotFoundException::class, "IncoSheet '99999' not found."); }); });