From f6b1c14c866fecec85da4974ef99106043821c83 Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk Date: Mon, 14 Oct 2024 21:00:46 +0300 Subject: [PATCH] refactor: Rearrange component namespaces --- .github/workflows/ci.yaml | 2 +- README.md | 24 ++++++------- Resources/config/services.yaml | 19 ---------- composer.json | 35 ++++++++++--------- phpstan.dist.neon | 7 ++-- phpunit.xml.dist | 11 +++--- psalm.xml | 3 +- rector.php | 1 + src/Bundle/.gitattributes | 1 + .../PhdExceptionHandlerExtension.php | 8 ++--- .../Bundle/PhdExceptionHandlerBundle.php | 7 ++-- src/Bundle/Resources/config/services.yaml | 2 ++ .../Compiler/TestServicesCompilerPass.php | 2 +- .../ThrowOriginExceptionMiddleware.php | 2 +- .../Tests}/Bootstrap/config/messenger.yaml | 8 ++--- .../Tests/Bootstrap/config/services.yaml | 9 +++++ .../Bundle/Tests/BundleTestCase.php | 8 ++--- .../ExceptionHandlerBundleIntegrationTest.php | 22 ++++++------ .../Tests}/Stub/Exception/InnerException.php | 4 +-- .../Tests}/Stub/Exception/OuterException.php | 2 +- .../Stub/LogExceptionMessageHandlerStub.php | 4 ++- .../Bundle/Tests}/Stub/MessageHandlerStub.php | 2 +- .../ExceptionHandlerMiddleware.php | 2 +- src/Handler/services.yaml | 10 ++++++ .../Chain/Escalator/RaiseAs.php | 2 +- .../Escalator/RaiseAsExceptionEscalator.php | 2 +- .../Chain/ExceptionChainMiddleware.php | 4 +-- src/Middleware/Chain/services.yaml | 3 ++ ...xceptionHandlerResultFilterMiddleware.php} | 4 +-- src/Middleware/Result/services.yaml | 3 ++ .../RethrowUnhandledExceptionMiddleware.php | 2 +- src/Middleware/Rethrow/services.yaml | 3 ++ .../Bootstrap/config/services.yaml | 9 ----- tests/Unit/ExceptionHandlerMiddlewareTest.php | 6 ++-- ...tionHandlingResultFilterMiddlewareTest.php | 8 ++--- ...ethrowUnhandledExceptionMiddlewareTest.php | 6 ++-- 36 files changed, 128 insertions(+), 119 deletions(-) delete mode 100644 Resources/config/services.yaml create mode 100644 src/Bundle/.gitattributes rename {DependencyInjection => src/Bundle/DependencyInjection}/PhdExceptionHandlerExtension.php (89%) rename PhdExceptionHandlerBundle.php => src/Bundle/PhdExceptionHandlerBundle.php (65%) create mode 100644 src/Bundle/Resources/config/services.yaml rename {tests/Integration => src/Bundle/Tests}/Bootstrap/Compiler/TestServicesCompilerPass.php (83%) rename {tests/Integration => src/Bundle/Tests}/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php (93%) rename {tests/Integration => src/Bundle/Tests}/Bootstrap/config/messenger.yaml (70%) create mode 100644 src/Bundle/Tests/Bootstrap/config/services.yaml rename tests/Integration/TestCase.php => src/Bundle/Tests/BundleTestCase.php (75%) rename tests/Integration/ExceptionHandlerTest.php => src/Bundle/Tests/ExceptionHandlerBundleIntegrationTest.php (75%) rename {tests/Integration => src/Bundle/Tests}/Stub/Exception/InnerException.php (58%) rename {tests/Integration => src/Bundle/Tests}/Stub/Exception/OuterException.php (60%) rename {tests/Integration => src/Bundle/Tests}/Stub/LogExceptionMessageHandlerStub.php (83%) rename {tests/Integration => src/Bundle/Tests}/Stub/MessageHandlerStub.php (91%) rename src/{ => Handler}/ExceptionHandlerMiddleware.php (98%) create mode 100644 src/Handler/services.yaml rename src/{ => Middleware}/Chain/Escalator/RaiseAs.php (91%) rename src/{ => Middleware}/Chain/Escalator/RaiseAsExceptionEscalator.php (94%) rename src/{ => Middleware}/Chain/ExceptionChainMiddleware.php (91%) create mode 100644 src/Middleware/Chain/services.yaml rename src/{Result/ExceptionHandlingResultFilterMiddleware.php => Middleware/Result/ExceptionHandlerResultFilterMiddleware.php} (86%) create mode 100644 src/Middleware/Result/services.yaml rename src/{ => Middleware}/Rethrow/RethrowUnhandledExceptionMiddleware.php (94%) create mode 100644 src/Middleware/Rethrow/services.yaml delete mode 100644 tests/Integration/Bootstrap/config/services.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b951366..b607ef4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -60,7 +60,7 @@ jobs: run: vendor/bin/psalm --stats --no-progress --output-format=github --shepherd --threads=$(nproc) - name: 'PHPStan' - run: vendor/bin/phpstan analyze --no-progress --error-format=github --ansi --configuration=phpstan.dist.neon ./ + run: vendor/bin/phpstan analyze --no-progress --error-format=github --ansi --configuration=phpstan.dist.neon steps: - name: 'Checkout Code' uses: actions/checkout@v4 diff --git a/README.md b/README.md index 8127de7..7998557 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ # PhdExceptionHandlerBundle -🧰 Provides [Symfony Messenger](https://symfony.com/doc/current/messenger.html) middlewares tailored for exception -handling. You can easily re-raise exceptions, chain them, or handle with a dedicated bus. +🧰 PHP Exception Handler built on top of [Symfony Messenger](https://symfony.com/doc/current/messenger.html) component. +Provides middlewares that allow you to easily re-raise exceptions, chain them, or handle with a dedicated handler. -[![Build Status](https://img.shields.io/github/actions/workflow/status/phphd/exception-handler-bundle/ci.yaml?branch=main)](https://github.com/phphd/exception-handler-bundle/actions?query=branch%3Amain) -[![Codecov](https://codecov.io/gh/phphd/exception-handler-bundle/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/exception-handler-bundle) -[![Psalm coverage](https://shepherd.dev/github/phphd/exception-handler-bundle/coverage.svg)](https://shepherd.dev/github/phphd/exception-handler-bundle) -[![Psalm level](https://shepherd.dev/github/phphd/exception-handler-bundle/level.svg)](https://shepherd.dev/github/phphd/exception-handler-bundle) -[![Packagist Downloads](https://img.shields.io/packagist/dt/phphd/exception-handler-bundle.svg)](https://packagist.org/packages/phphd/exception-handler-bundle) -[![Licence](https://img.shields.io/github/license/phphd/exception-handler-bundle.svg)](https://github.com/phphd/exception-handler-bundle/blob/main/LICENSE) +[![Build Status](https://img.shields.io/github/actions/workflow/status/phphd/exception-handler/ci.yaml?branch=main)](https://github.com/phphd/exception-handler/actions?query=branch%3Amain) +[![Codecov](https://codecov.io/gh/phphd/exception-handler/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/exception-handler) +[![Psalm coverage](https://shepherd.dev/github/phphd/exception-handler/coverage.svg)](https://shepherd.dev/github/phphd/exception-handler) +[![Psalm level](https://shepherd.dev/github/phphd/exception-handler/level.svg)](https://shepherd.dev/github/phphd/exception-handler) +[![Packagist Downloads](https://img.shields.io/packagist/dt/phphd/exception-handler.svg)](https://packagist.org/packages/phphd/exception-handler) +[![Licence](https://img.shields.io/github/license/phphd/exception-handler.svg)](https://github.com/phphd/exception-handler/blob/main/LICENSE) ## Installation 📥 1. Install via composer ```sh - composer require phphd/exception-handler-bundle + composer require phphd/exception-handler ``` 2. Enable the bundle in the `bundles.php` ```php - PhPhD\ExceptionHandlerBundle\PhdExceptionHandlerBundle::class => ['all' => true], + PhPhD\ExceptionHandler\Bundle\PhdExceptionHandlerBundle::class => ['all' => true], ``` ## Configuration ⚒️ @@ -88,7 +88,7 @@ Filters out all null results of exception handlers. The simplest use-case is defining `#[RaiseAs]` attribute on your exception class: ```php -use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs; +use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs; #[RaiseAs(AccessDeniedHttpException::class, bus: 'api.exception.bus')] final class NonWhiteListedUserException extends DomainException @@ -104,7 +104,7 @@ contexts (hence, different buses), it is required to explicitly specify the bus must be raised, so that in other scenarios another exceptions could be escalated: ```php -use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs; +use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs; #[RaiseAs(ImportLockedHttpException::class, bus: 'api.exception.bus')] #[RaiseAs(RecoverableMessageHandlingException::class, bus: 'consumer.exception.bus')] diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml deleted file mode 100644 index ceba407..0000000 --- a/Resources/config/services.yaml +++ /dev/null @@ -1,19 +0,0 @@ -services: - phd_exception_handler: - class: PhPhD\ExceptionHandler\ExceptionHandlerMiddleware - arguments: - - '@phd_exception_handler.bus' - - phd_exception_handler.bus: - class: Symfony\Component\Messenger\RoutableMessageBus - arguments: - - !tagged_locator { tag: 'messenger.bus', index_by: 'id' } - - phd_exception_rethrow_unhandled: - class: PhPhD\ExceptionHandler\Rethrow\RethrowUnhandledExceptionMiddleware - - phd_exception_chaining: - class: PhPhD\ExceptionHandler\Chain\ExceptionChainMiddleware - - phd_exception_result_filter: - class: PhPhD\ExceptionHandler\Result\ExceptionHandlingResultFilterMiddleware diff --git a/composer.json b/composer.json index 54ec8a1..4085693 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "phphd/exception-handler-bundle", + "name": "phphd/exception-handler", "description": "Message Bus Exception Handler", "type": "symfony-bundle", "license": "MIT", @@ -12,21 +12,28 @@ "minimum-stability": "stable", "require": { "php": ">=8.1", - "symfony/dependency-injection": "^6.0 | ^7.0", - "symfony/http-kernel": "^6.0 | ^7.0", "symfony/messenger": "^6.2 | ^7.0", - "symfony/string": "^6.0 | ^7.0" + "symfony/string": "^6.0 | ^7.0", + "symfony/polyfill-php83": "^1.31" + }, + "conflict": { + "symfony/http-kernel": "<6.0 || >=8.0", + "symfony/dependency-injection": "<6.0 || >=8.0", + "symfony/config": "<6.0 || >=8.0" }, "require-dev": { - "tomasvotruba/type-coverage": "^0.2.3", + "symfony/http-kernel": "*", + "symfony/dependency-injection":"*", + "symfony/config": "*", + "tomasvotruba/type-coverage": "^1.0", "phpstan/phpstan": "^1.10.60", - "vimeo/psalm": "^5.23.1", - "phpat/phpat": "^0.10.15", - "phpstan/phpstan-phpunit": "^1.3.16", + "vimeo/psalm": "^5.26.1", + "phpat/phpat": "^0.10.18", + "phpstan/phpstan-phpunit": "^1.4.0", "psalm/plugin-phpunit": "^0.18.4", "nyholm/symfony-bundle-test": "^3.0", - "phphd/coding-standard": "~0.5.0", - "phpunit/phpunit": "^10.5.13" + "phphd/coding-standard": "~0.5.3", + "phpunit/phpunit": "^10.5.36" }, "repositories": [ { @@ -35,17 +42,13 @@ } ], "autoload": { - "classmap": [ - "DependencyInjection", - "PhdExceptionHandlerBundle.php" - ], "psr-4": { "PhPhD\\ExceptionHandler\\": "src" } }, "autoload-dev": { "psr-4": { - "PhPhD\\ExceptionHandlerBundle\\Tests\\": "tests" + "PhPhD\\ExceptionHandler\\Bundle\\Tests\\": "tests" } }, "scripts": { @@ -61,7 +64,7 @@ "ci:ecs-fix": "vendor/bin/ecs check --fix", "ci:rector": "vendor/bin/rector process --dry-run -vv", "ci:rector-fix": "vendor/bin/rector process", - "ci:phpstan": "vendor/bin/phpstan analyze ./", + "ci:phpstan": "vendor/bin/phpstan analyze", "ci:psalm": "vendor/bin/psalm", "ci:test": "vendor/bin/phpunit --testdox --colors=always", "ci:unit-test": "vendor/bin/phpunit --testdox --colors=always --testsuite=Unit", diff --git a/phpstan.dist.neon b/phpstan.dist.neon index edf6a7a..45b50ba 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -8,16 +8,17 @@ parameters: level: 9 phpVersion: 80213 editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' + paths: + - src + - tests excludePaths: analyseAndScan: - - vendor - tests/*/Stub/* - - rector.php - - ecs.php type_coverage: return_type: 100 param_type: 100 property_type: 100 + constant: 0 fileExtensions: - 'php' phpat: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2a6b709..3d271f1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,19 +13,18 @@ tests/Unit - tests/Integration + src - . + src - vendor - tests - rector.php - ecs.php + src/*/*/Tests + src/*/*/*/Tests + src/*/*/*/*/Tests diff --git a/psalm.xml b/psalm.xml index 76f16a5..6658cf4 100644 --- a/psalm.xml +++ b/psalm.xml @@ -9,10 +9,9 @@ findUnusedCode="true" > - + - diff --git a/rector.php b/rector.php index b8ad2ef..2b5e3c6 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ $rectorConfig->skip([ LocallyCalledStaticMethodToNonStaticRector::class => [ __DIR__.'/tests', + __DIR__.'/src/*/Tests/*.php', ], ]); }; diff --git a/src/Bundle/.gitattributes b/src/Bundle/.gitattributes new file mode 100644 index 0000000..23b1768 --- /dev/null +++ b/src/Bundle/.gitattributes @@ -0,0 +1 @@ +/Tests export-ignore diff --git a/DependencyInjection/PhdExceptionHandlerExtension.php b/src/Bundle/DependencyInjection/PhdExceptionHandlerExtension.php similarity index 89% rename from DependencyInjection/PhdExceptionHandlerExtension.php rename to src/Bundle/DependencyInjection/PhdExceptionHandlerExtension.php index b803f97..69fbf41 100644 --- a/DependencyInjection/PhdExceptionHandlerExtension.php +++ b/src/Bundle/DependencyInjection/PhdExceptionHandlerExtension.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\DependencyInjection; +namespace PhPhD\ExceptionHandler\Bundle\DependencyInjection; use Exception; +use Override; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -17,10 +18,9 @@ final class PhdExceptionHandlerExtension extends Extension /** * @param array $configs * - * @override - * * @throws Exception */ + #[Override] public function load(array $configs, ContainerBuilder $container): void { /** @var ?string $env */ @@ -30,7 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load(__DIR__.'/../Resources/config/services.yaml'); } - /** @override */ + #[Override] public function getAlias(): string { return self::ALIAS; diff --git a/PhdExceptionHandlerBundle.php b/src/Bundle/PhdExceptionHandlerBundle.php similarity index 65% rename from PhdExceptionHandlerBundle.php rename to src/Bundle/PhdExceptionHandlerBundle.php index b017230..19d707d 100644 --- a/PhdExceptionHandlerBundle.php +++ b/src/Bundle/PhdExceptionHandlerBundle.php @@ -2,15 +2,16 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle; +namespace PhPhD\ExceptionHandler\Bundle; -use PhPhD\ExceptionHandlerBundle\DependencyInjection\PhdExceptionHandlerExtension; +use Override; +use PhPhD\ExceptionHandler\Bundle\DependencyInjection\PhdExceptionHandlerExtension; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @api */ final class PhdExceptionHandlerBundle extends Bundle { - /** @override */ + #[Override] protected function createContainerExtension(): PhdExceptionHandlerExtension { return new PhdExceptionHandlerExtension(); diff --git a/src/Bundle/Resources/config/services.yaml b/src/Bundle/Resources/config/services.yaml new file mode 100644 index 0000000..196a08b --- /dev/null +++ b/src/Bundle/Resources/config/services.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../../../{Handler,Middleware}/**/services.yaml' } diff --git a/tests/Integration/Bootstrap/Compiler/TestServicesCompilerPass.php b/src/Bundle/Tests/Bootstrap/Compiler/TestServicesCompilerPass.php similarity index 83% rename from tests/Integration/Bootstrap/Compiler/TestServicesCompilerPass.php rename to src/Bundle/Tests/Bootstrap/Compiler/TestServicesCompilerPass.php index 523fe50..1b8f804 100644 --- a/tests/Integration/Bootstrap/Compiler/TestServicesCompilerPass.php +++ b/src/Bundle/Tests/Bootstrap/Compiler/TestServicesCompilerPass.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Compiler; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; diff --git a/tests/Integration/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php b/src/Bundle/Tests/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php similarity index 93% rename from tests/Integration/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php rename to src/Bundle/Tests/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php index e18142f..4c3b51c 100644 --- a/tests/Integration/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php +++ b/src/Bundle/Tests/Bootstrap/Middleware/ThrowOriginExceptionMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException; diff --git a/tests/Integration/Bootstrap/config/messenger.yaml b/src/Bundle/Tests/Bootstrap/config/messenger.yaml similarity index 70% rename from tests/Integration/Bootstrap/config/messenger.yaml rename to src/Bundle/Tests/Bootstrap/config/messenger.yaml index 60006e8..155699b 100644 --- a/tests/Integration/Bootstrap/config/messenger.yaml +++ b/src/Bundle/Tests/Bootstrap/config/messenger.yaml @@ -7,7 +7,7 @@ framework: middleware: - add_bus_name_stamp_middleware: [ query.bus ] - phd_exception_handler - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware + - PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware - handle_message query.exception.bus: default_middleware: false @@ -15,14 +15,14 @@ framework: - phd_exception_rethrow_unhandled - phd_exception_chaining - phd_exception_result_filter - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware + - PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware - handle_message: - true command.bus: default_middleware: false middleware: - phd_exception_handler - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware + - PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware - handle_message api.command.exception.bus: default_middleware: false @@ -30,6 +30,6 @@ framework: - phd_exception_rethrow_unhandled - phd_exception_chaining - phd_exception_result_filter - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware + - PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware - handle_message: - true diff --git a/src/Bundle/Tests/Bootstrap/config/services.yaml b/src/Bundle/Tests/Bootstrap/config/services.yaml new file mode 100644 index 0000000..4f41bb8 --- /dev/null +++ b/src/Bundle/Tests/Bootstrap/config/services.yaml @@ -0,0 +1,9 @@ +services: + PhPhD\ExceptionHandler\Bundle\Tests\Stub\MessageHandlerStub: + autoconfigure: true + + PhPhD\ExceptionHandler\Bundle\Tests\Stub\LogExceptionMessageHandlerStub: + autoconfigure: true + + PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Middleware\ThrowOriginExceptionMiddleware: + autoconfigure: true diff --git a/tests/Integration/TestCase.php b/src/Bundle/Tests/BundleTestCase.php similarity index 75% rename from tests/Integration/TestCase.php rename to src/Bundle/Tests/BundleTestCase.php index 39ec97d..9400da4 100644 --- a/tests/Integration/TestCase.php +++ b/src/Bundle/Tests/BundleTestCase.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration; +namespace PhPhD\ExceptionHandler\Bundle\Tests; use Nyholm\BundleTest\TestKernel; -use PhPhD\ExceptionHandlerBundle\PhdExceptionHandlerBundle; -use PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Compiler\TestServicesCompilerPass; +use PhPhD\ExceptionHandler\Bundle\PhdExceptionHandlerBundle; +use PhPhD\ExceptionHandler\Bundle\Tests\Bootstrap\Compiler\TestServicesCompilerPass; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; -abstract class TestCase extends KernelTestCase +abstract class BundleTestCase extends KernelTestCase { protected static function getKernelClass(): string { diff --git a/tests/Integration/ExceptionHandlerTest.php b/src/Bundle/Tests/ExceptionHandlerBundleIntegrationTest.php similarity index 75% rename from tests/Integration/ExceptionHandlerTest.php rename to src/Bundle/Tests/ExceptionHandlerBundleIntegrationTest.php index ace54c9..20efad7 100644 --- a/tests/Integration/ExceptionHandlerTest.php +++ b/src/Bundle/Tests/ExceptionHandlerBundleIntegrationTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration; +namespace PhPhD\ExceptionHandler\Bundle\Tests; -use PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\Exception\InnerException; -use PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\Exception\OuterException; -use PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\LogExceptionMessageHandlerStub; +use PhPhD\ExceptionHandler\Bundle\Tests\Stub\Exception\InnerException; +use PhPhD\ExceptionHandler\Bundle\Tests\Stub\Exception\OuterException; +use PhPhD\ExceptionHandler\Bundle\Tests\Stub\LogExceptionMessageHandlerStub; use stdClass; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Stamp\BusNameStamp; @@ -14,16 +14,16 @@ use Throwable; /** - * @covers \PhPhD\ExceptionHandlerBundle\PhdExceptionHandlerBundle - * @covers \PhPhD\ExceptionHandlerBundle\DependencyInjection\PhdExceptionHandlerExtension - * @covers \PhPhD\ExceptionHandler\ExceptionHandlerMiddleware - * @covers \PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs - * @covers \PhPhD\ExceptionHandler\Chain\Escalator\RaiseAsExceptionEscalator - * @covers \PhPhD\ExceptionHandler\Rethrow\RethrowUnhandledExceptionMiddleware + * @covers \PhPhD\ExceptionHandler\Bundle\PhdExceptionHandlerBundle + * @covers \PhPhD\ExceptionHandler\Bundle\DependencyInjection\PhdExceptionHandlerExtension + * @covers \PhPhD\ExceptionHandler\Handler\ExceptionHandlerMiddleware + * @covers \PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs + * @covers \PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAsExceptionEscalator + * @covers \PhPhD\ExceptionHandler\Middleware\Rethrow\RethrowUnhandledExceptionMiddleware * * @internal */ -final class ExceptionHandlerTest extends TestCase +final class ExceptionHandlerBundleIntegrationTest extends BundleTestCase { private MessageBusInterface $commandBus; diff --git a/tests/Integration/Stub/Exception/InnerException.php b/src/Bundle/Tests/Stub/Exception/InnerException.php similarity index 58% rename from tests/Integration/Stub/Exception/InnerException.php rename to src/Bundle/Tests/Stub/Exception/InnerException.php index 7cfef99..4fa1100 100644 --- a/tests/Integration/Stub/Exception/InnerException.php +++ b/src/Bundle/Tests/Stub/Exception/InnerException.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\Exception; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Stub\Exception; -use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAs; +use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs; use RuntimeException; #[RaiseAs(OuterException::class, bus: 'query.exception.bus')] diff --git a/tests/Integration/Stub/Exception/OuterException.php b/src/Bundle/Tests/Stub/Exception/OuterException.php similarity index 60% rename from tests/Integration/Stub/Exception/OuterException.php rename to src/Bundle/Tests/Stub/Exception/OuterException.php index bb4015a..2a78c0c 100644 --- a/tests/Integration/Stub/Exception/OuterException.php +++ b/src/Bundle/Tests/Stub/Exception/OuterException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\Exception; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Stub\Exception; use RuntimeException; diff --git a/tests/Integration/Stub/LogExceptionMessageHandlerStub.php b/src/Bundle/Tests/Stub/LogExceptionMessageHandlerStub.php similarity index 83% rename from tests/Integration/Stub/LogExceptionMessageHandlerStub.php rename to src/Bundle/Tests/Stub/LogExceptionMessageHandlerStub.php index 53ea7ee..717d54c 100644 --- a/tests/Integration/Stub/LogExceptionMessageHandlerStub.php +++ b/src/Bundle/Tests/Stub/LogExceptionMessageHandlerStub.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Stub; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Throwable; @@ -17,6 +17,7 @@ ])] final class LogExceptionMessageHandlerStub { + /** @var array */ private array $loggedExceptions = []; /** @throws Throwable */ @@ -25,6 +26,7 @@ public function __invoke(Throwable $exception, object $command): void $this->loggedExceptions[] = [$exception, $command]; } + /** @return array */ public function getLoggedExceptions(): array { return $this->loggedExceptions; diff --git a/tests/Integration/Stub/MessageHandlerStub.php b/src/Bundle/Tests/Stub/MessageHandlerStub.php similarity index 91% rename from tests/Integration/Stub/MessageHandlerStub.php rename to src/Bundle/Tests/Stub/MessageHandlerStub.php index 76b3833..d98414d 100644 --- a/tests/Integration/Stub/MessageHandlerStub.php +++ b/src/Bundle/Tests/Stub/MessageHandlerStub.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Stub; use stdClass; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; diff --git a/src/ExceptionHandlerMiddleware.php b/src/Handler/ExceptionHandlerMiddleware.php similarity index 98% rename from src/ExceptionHandlerMiddleware.php rename to src/Handler/ExceptionHandlerMiddleware.php index 7cce472..e5a47e9 100644 --- a/src/ExceptionHandlerMiddleware.php +++ b/src/Handler/ExceptionHandlerMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler; +namespace PhPhD\ExceptionHandler\Handler; use Exception; use LogicException; diff --git a/src/Handler/services.yaml b/src/Handler/services.yaml new file mode 100644 index 0000000..58ac70c --- /dev/null +++ b/src/Handler/services.yaml @@ -0,0 +1,10 @@ +services: + phd_exception_handler: + class: PhPhD\ExceptionHandler\Handler\ExceptionHandlerMiddleware + arguments: + - '@phd_exception_handler.bus' + + phd_exception_handler.bus: + class: Symfony\Component\Messenger\RoutableMessageBus + arguments: + - !tagged_locator { tag: 'messenger.bus', index_by: 'id' } diff --git a/src/Chain/Escalator/RaiseAs.php b/src/Middleware/Chain/Escalator/RaiseAs.php similarity index 91% rename from src/Chain/Escalator/RaiseAs.php rename to src/Middleware/Chain/Escalator/RaiseAs.php index f9f975a..8b58821 100644 --- a/src/Chain/Escalator/RaiseAs.php +++ b/src/Middleware/Chain/Escalator/RaiseAs.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler\Chain\Escalator; +namespace PhPhD\ExceptionHandler\Middleware\Chain\Escalator; use Attribute; use Throwable; diff --git a/src/Chain/Escalator/RaiseAsExceptionEscalator.php b/src/Middleware/Chain/Escalator/RaiseAsExceptionEscalator.php similarity index 94% rename from src/Chain/Escalator/RaiseAsExceptionEscalator.php rename to src/Middleware/Chain/Escalator/RaiseAsExceptionEscalator.php index 2d583cc..84a8549 100644 --- a/src/Chain/Escalator/RaiseAsExceptionEscalator.php +++ b/src/Middleware/Chain/Escalator/RaiseAsExceptionEscalator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler\Chain\Escalator; +namespace PhPhD\ExceptionHandler\Middleware\Chain\Escalator; use ReflectionAttribute; use ReflectionClass; diff --git a/src/Chain/ExceptionChainMiddleware.php b/src/Middleware/Chain/ExceptionChainMiddleware.php similarity index 91% rename from src/Chain/ExceptionChainMiddleware.php rename to src/Middleware/Chain/ExceptionChainMiddleware.php index ea98679..1071c9b 100644 --- a/src/Chain/ExceptionChainMiddleware.php +++ b/src/Middleware/Chain/ExceptionChainMiddleware.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler\Chain; +namespace PhPhD\ExceptionHandler\Middleware\Chain; use LogicException; -use PhPhD\ExceptionHandler\Chain\Escalator\RaiseAsExceptionEscalator; +use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAsExceptionEscalator; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; diff --git a/src/Middleware/Chain/services.yaml b/src/Middleware/Chain/services.yaml new file mode 100644 index 0000000..703c221 --- /dev/null +++ b/src/Middleware/Chain/services.yaml @@ -0,0 +1,3 @@ +services: + phd_exception_chaining: + class: PhPhD\ExceptionHandler\Middleware\Chain\ExceptionChainMiddleware diff --git a/src/Result/ExceptionHandlingResultFilterMiddleware.php b/src/Middleware/Result/ExceptionHandlerResultFilterMiddleware.php similarity index 86% rename from src/Result/ExceptionHandlingResultFilterMiddleware.php rename to src/Middleware/Result/ExceptionHandlerResultFilterMiddleware.php index 4262c0e..dadbbc8 100644 --- a/src/Result/ExceptionHandlingResultFilterMiddleware.php +++ b/src/Middleware/Result/ExceptionHandlerResultFilterMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler\Result; +namespace PhPhD\ExceptionHandler\Middleware\Result; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; @@ -16,7 +16,7 @@ * * @internal */ -final class ExceptionHandlingResultFilterMiddleware implements MiddlewareInterface +final class ExceptionHandlerResultFilterMiddleware implements MiddlewareInterface { public function handle(Envelope $envelope, StackInterface $stack): Envelope { diff --git a/src/Middleware/Result/services.yaml b/src/Middleware/Result/services.yaml new file mode 100644 index 0000000..bb15d11 --- /dev/null +++ b/src/Middleware/Result/services.yaml @@ -0,0 +1,3 @@ +services: + phd_exception_result_filter: + class: PhPhD\ExceptionHandler\Middleware\Result\ExceptionHandlerResultFilterMiddleware diff --git a/src/Rethrow/RethrowUnhandledExceptionMiddleware.php b/src/Middleware/Rethrow/RethrowUnhandledExceptionMiddleware.php similarity index 94% rename from src/Rethrow/RethrowUnhandledExceptionMiddleware.php rename to src/Middleware/Rethrow/RethrowUnhandledExceptionMiddleware.php index d8735d1..6060c02 100644 --- a/src/Rethrow/RethrowUnhandledExceptionMiddleware.php +++ b/src/Middleware/Rethrow/RethrowUnhandledExceptionMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandler\Rethrow; +namespace PhPhD\ExceptionHandler\Middleware\Rethrow; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; diff --git a/src/Middleware/Rethrow/services.yaml b/src/Middleware/Rethrow/services.yaml new file mode 100644 index 0000000..a0412e8 --- /dev/null +++ b/src/Middleware/Rethrow/services.yaml @@ -0,0 +1,3 @@ +services: + phd_exception_rethrow_unhandled: + class: PhPhD\ExceptionHandler\Middleware\Rethrow\RethrowUnhandledExceptionMiddleware diff --git a/tests/Integration/Bootstrap/config/services.yaml b/tests/Integration/Bootstrap/config/services.yaml deleted file mode 100644 index 8b84a41..0000000 --- a/tests/Integration/Bootstrap/config/services.yaml +++ /dev/null @@ -1,9 +0,0 @@ -services: - PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\MessageHandlerStub: - autoconfigure: true - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Stub\LogExceptionMessageHandlerStub: - autoconfigure: true - - PhPhD\ExceptionHandlerBundle\Tests\Integration\Bootstrap\Middleware\ThrowOriginExceptionMiddleware: - autoconfigure: true diff --git a/tests/Unit/ExceptionHandlerMiddlewareTest.php b/tests/Unit/ExceptionHandlerMiddlewareTest.php index 119e4db..d8cdf1e 100644 --- a/tests/Unit/ExceptionHandlerMiddlewareTest.php +++ b/tests/Unit/ExceptionHandlerMiddlewareTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Unit; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Unit; use LogicException; -use PhPhD\ExceptionHandler\ExceptionHandlerMiddleware; +use PhPhD\ExceptionHandler\Handler\ExceptionHandlerMiddleware; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -17,7 +17,7 @@ use Symfony\Component\Messenger\Stamp\BusNameStamp; /** - * @covers \PhPhD\ExceptionHandler\ExceptionHandlerMiddleware + * @covers \PhPhD\ExceptionHandler\Handler\ExceptionHandlerMiddleware * * @internal */ diff --git a/tests/Unit/ExceptionHandlingResultFilterMiddlewareTest.php b/tests/Unit/ExceptionHandlingResultFilterMiddlewareTest.php index c3650b1..021380b 100644 --- a/tests/Unit/ExceptionHandlingResultFilterMiddlewareTest.php +++ b/tests/Unit/ExceptionHandlingResultFilterMiddlewareTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Unit; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Unit; -use PhPhD\ExceptionHandler\Result\ExceptionHandlingResultFilterMiddleware; +use PhPhD\ExceptionHandler\Middleware\Result\ExceptionHandlerResultFilterMiddleware; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; @@ -14,7 +14,7 @@ use Symfony\Component\Messenger\Stamp\HandledStamp; /** - * @covers \PhPhD\ExceptionHandler\Result\ExceptionHandlingResultFilterMiddleware + * @covers \PhPhD\ExceptionHandler\Middleware\Result\ExceptionHandlerResultFilterMiddleware * * @internal */ @@ -30,7 +30,7 @@ protected function setUp(): void $this->nextMiddleware = $this->createMock(MiddlewareInterface::class); - $this->messageBus = new MessageBus([new ExceptionHandlingResultFilterMiddleware(), $this->nextMiddleware]); + $this->messageBus = new MessageBus([new ExceptionHandlerResultFilterMiddleware(), $this->nextMiddleware]); } public function testPassesMessageThrough(): void diff --git a/tests/Unit/RethrowUnhandledExceptionMiddlewareTest.php b/tests/Unit/RethrowUnhandledExceptionMiddlewareTest.php index 85df8d3..41d6dcd 100644 --- a/tests/Unit/RethrowUnhandledExceptionMiddlewareTest.php +++ b/tests/Unit/RethrowUnhandledExceptionMiddlewareTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace PhPhD\ExceptionHandlerBundle\Tests\Unit; +namespace PhPhD\ExceptionHandler\Bundle\Tests\Unit; use LogicException; -use PhPhD\ExceptionHandler\Rethrow\RethrowUnhandledExceptionMiddleware; +use PhPhD\ExceptionHandler\Middleware\Rethrow\RethrowUnhandledExceptionMiddleware; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -15,7 +15,7 @@ use Symfony\Component\Messenger\Stamp\HandledStamp; /** - * @covers \PhPhD\ExceptionHandler\Rethrow\RethrowUnhandledExceptionMiddleware + * @covers \PhPhD\ExceptionHandler\Middleware\Rethrow\RethrowUnhandledExceptionMiddleware * * @internal */