From f708b1042c11884aa419baf282212004367115d7 Mon Sep 17 00:00:00 2001 From: zumba Date: Fri, 8 Mar 2024 13:55:25 +0200 Subject: [PATCH] Fix customHeader method to actually check for the header existing --- src/EventBus/Message.php | 2 +- tests/Unit/EventBus/MessageTest.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/EventBus/Message.php b/src/EventBus/Message.php index 3e7be39e1..21a090a93 100644 --- a/src/EventBus/Message.php +++ b/src/EventBus/Message.php @@ -167,7 +167,7 @@ public function withArchived(bool $value): self public function customHeader(string $name): mixed { - if (array_keys($this->customHeaders, $name)) { + if (!array_key_exists($name, $this->customHeaders)) { throw HeaderNotFound::custom($name); } diff --git a/tests/Unit/EventBus/MessageTest.php b/tests/Unit/EventBus/MessageTest.php index 596721188..63080816b 100644 --- a/tests/Unit/EventBus/MessageTest.php +++ b/tests/Unit/EventBus/MessageTest.php @@ -119,11 +119,16 @@ public function testCustomHeaders(): void ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn($recordedAt) - ->withCustomHeader('custom-field', 'foo-bar'); + ->withCustomHeader('custom-field', 'foo-bar') + ->withCustomHeader('valueiskey', 'valueiskey') + ; self::assertEquals( - ['custom-field' => 'foo-bar'], + ['custom-field' => 'foo-bar', 'valueiskey' => 'valueiskey'], $message->customHeaders(), ); + + self::assertEquals('foo-bar', $message->customHeader('custom-field')); + self::assertEquals('valueiskey', $message->customHeader('valueiskey')); } }