Skip to content

Commit

Permalink
Fix customHeader method to actually check for the header existing
Browse files Browse the repository at this point in the history
  • Loading branch information
gzumba committed Mar 8, 2024
1 parent f6f7ce9 commit f708b10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/EventBus/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/EventBus/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit f708b10

Please sign in to comment.