From e656048bce3bef08e8ece98cba2cc2583fbb4716 Mon Sep 17 00:00:00 2001 From: Jeroen de Graaf Date: Fri, 10 Oct 2025 08:58:10 +0200 Subject: [PATCH 1/2] Bump gember/dependency-contracts to ^0.2 --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 46b992c..da65d79 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": "^8.3", - "gember/dependency-contracts": "^0.1", + "gember/dependency-contracts": "^0.2", "symfony/messenger": "^7.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 84d4e1f..9435087 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "295e25f250f63c48c442bd33466ab4d9", + "content-hash": "1e9e6f06d37ffaca3bf7de8ca95d6fab", "packages": [ { "name": "gember/dependency-contracts", - "version": "0.1.0", + "version": "0.2.0", "source": { "type": "git", "url": "https://github.com/GemberPHP/dependency-contracts.git", - "reference": "e82562e0f46c091d4991508ebf43257fc3a9a424" + "reference": "a8aebde31bd527a66c6e656dd51b0e8d3794ecf5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/GemberPHP/dependency-contracts/zipball/e82562e0f46c091d4991508ebf43257fc3a9a424", - "reference": "e82562e0f46c091d4991508ebf43257fc3a9a424", + "url": "https://api.github.com/repos/GemberPHP/dependency-contracts/zipball/a8aebde31bd527a66c6e656dd51b0e8d3794ecf5", + "reference": "a8aebde31bd527a66c6e656dd51b0e8d3794ecf5", "shasum": "" }, "require": { @@ -58,9 +58,9 @@ ], "support": { "issues": "https://github.com/GemberPHP/dependency-contracts/issues", - "source": "https://github.com/GemberPHP/dependency-contracts/tree/0.1.0" + "source": "https://github.com/GemberPHP/dependency-contracts/tree/0.2.0" }, - "time": "2025-09-03T17:15:32+00:00" + "time": "2025-10-10T06:44:36+00:00" }, { "name": "psr/clock", From ec3f5f3cbe6a63a21b0a4f2824f7b2234ce7399e Mon Sep 17 00:00:00 2001 From: Jeroen de Graaf Date: Fri, 10 Oct 2025 08:59:07 +0200 Subject: [PATCH 2/2] Add CommandBus implementation --- src/SymfonyCommandBus.php | 28 +++++++++++ tests/SymfonyCommandBusTest.php | 47 +++++++++++++++++++ tests/TestDoubles/TestCommand.php | 7 +++ .../TestCommandThrowingException.php | 7 +++ tests/TestDoubles/TestSymfonyCommandBus.php | 26 ++++++++++ 5 files changed, 115 insertions(+) create mode 100644 src/SymfonyCommandBus.php create mode 100644 tests/SymfonyCommandBusTest.php create mode 100644 tests/TestDoubles/TestCommand.php create mode 100644 tests/TestDoubles/TestCommandThrowingException.php create mode 100644 tests/TestDoubles/TestSymfonyCommandBus.php diff --git a/src/SymfonyCommandBus.php b/src/SymfonyCommandBus.php new file mode 100644 index 0000000..fb17e3b --- /dev/null +++ b/src/SymfonyCommandBus.php @@ -0,0 +1,28 @@ +commandBus->dispatch($command); + } catch (ExceptionInterface $exception) { + throw HandlingMessageFailedException::withException($exception); + } + } +} diff --git a/tests/SymfonyCommandBusTest.php b/tests/SymfonyCommandBusTest.php new file mode 100644 index 0000000..218aa31 --- /dev/null +++ b/tests/SymfonyCommandBusTest.php @@ -0,0 +1,47 @@ +commandBus = new SymfonyCommandBus( + $this->symfonyCommandBus = new TestSymfonyCommandBus(), + ); + } + + #[Test] + public function itShouldHandleCommand(): void + { + $this->commandBus->handle(new TestCommand()); + + self::assertTrue($this->symfonyCommandBus->isCalled); + } + + #[Test] + public function itShouldThrowExceptionWhenHandlingCommandFailed(): void + { + self::expectException(HandlingMessageFailedException::class); + + $this->commandBus->handle(new TestCommandThrowingException()); + } +} diff --git a/tests/TestDoubles/TestCommand.php b/tests/TestDoubles/TestCommand.php new file mode 100644 index 0000000..2806abf --- /dev/null +++ b/tests/TestDoubles/TestCommand.php @@ -0,0 +1,7 @@ +isCalled = true; + + if ($message instanceof TestCommandThrowingException) { + throw new class extends Exception implements ExceptionInterface {}; + } + + return new Envelope($message); + } +}