From 179722f42e4776321f24cd4cc55c60ae2f164d4c Mon Sep 17 00:00:00 2001 From: David Badura Date: Thu, 11 Jan 2024 13:11:46 +0100 Subject: [PATCH] add psr 14 support --- composer.json | 1 + composer.lock | 2 +- src/EventBus/Psr14EventBus.php | 22 +++++++++ tests/Unit/EventBus/Psr14EventBusTest.php | 60 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/EventBus/Psr14EventBus.php create mode 100644 tests/Unit/EventBus/Psr14EventBusTest.php diff --git a/composer.json b/composer.json index 0b48a17f5..1e4712676 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "patchlevel/worker": "^1.1.0", "psr/cache": "^2.0.0|^3.0.0", "psr/clock": "^1.0", + "psr/event-dispatcher": "^1.0", "psr/log": "^2.0.0|^3.0.0", "psr/simple-cache": "^2.0.0|^3.0.0", "ramsey/uuid": "^4.7", diff --git a/composer.lock b/composer.lock index 3a6cde5af..a52da4108 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6d8b289f331bdf12d6cd2dca8ef7ff36", + "content-hash": "7940712aab42f22a46c30206477e3cee", "packages": [ { "name": "brick/math", diff --git a/src/EventBus/Psr14EventBus.php b/src/EventBus/Psr14EventBus.php new file mode 100644 index 000000000..b548534a3 --- /dev/null +++ b/src/EventBus/Psr14EventBus.php @@ -0,0 +1,22 @@ +eventDispatcher->dispatch($message); + } + } +} diff --git a/tests/Unit/EventBus/Psr14EventBusTest.php b/tests/Unit/EventBus/Psr14EventBusTest.php new file mode 100644 index 000000000..0827a8f95 --- /dev/null +++ b/tests/Unit/EventBus/Psr14EventBusTest.php @@ -0,0 +1,60 @@ +prophesize(EventDispatcherInterface::class); + $eventDispatcher->dispatch($message)->shouldBeCalled(); + + $eventBus = new Psr14EventBus($eventDispatcher->reveal()); + $eventBus->dispatch($message); + } + + public function testDispatchMultipleMessages(): void + { + $message1 = new Message( + new ProfileCreated( + ProfileId::fromString('1'), + Email::fromString('info@patchlevel.de'), + ), + ); + + $message2 = new Message( + new ProfileCreated( + ProfileId::fromString('1'), + Email::fromString('info@patchlevel.de'), + ), + ); + + $eventDispatcher = $this->prophesize(EventDispatcherInterface::class); + $eventDispatcher->dispatch($message1)->shouldBeCalled(); + $eventDispatcher->dispatch($message2)->shouldBeCalled(); + + $eventBus = new Psr14EventBus($eventDispatcher->reveal()); + $eventBus->dispatch($message1, $message2); + } +}