Skip to content

Commit

Permalink
Fix bug and test
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorprogger committed Sep 20, 2024
1 parent 02f2534 commit 2bb91ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Message/AbstractEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function __construct(MessageInterface $message)

if (is_array($this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY])) {
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = array_merge(
[static::class],
$envelopes,
array_filter(
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY],
static fn (string $envelope): bool => !in_array($envelope, $envelopes),
),
);
} else {
$this->metadata[EnvelopeInterface::ENVELOPE_STACK_KEY] = [static::class];
Expand Down
7 changes: 5 additions & 2 deletions tests/Unit/Message/JsonMessageSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testUnserializeFromData(): void

$this->assertInstanceOf(MessageInterface::class, $message);
$this->assertEquals($payload['data'], $message->getData());
$this->assertEquals([], $message->getMetadata());
$this->assertEquals([EnvelopeInterface::ENVELOPE_STACK_KEY => []], $message->getMetadata());
}

public function testUnserializeWithMetadata(): void
Expand All @@ -78,7 +78,10 @@ public function testUnserializeWithMetadata(): void

$this->assertInstanceOf(MessageInterface::class, $message);
$this->assertEquals($payload['data'], $message->getData());
$this->assertEquals(['int' => 1, 'str' => 'string', 'bool' => true], $message->getMetadata());
$this->assertEquals(
['int' => 1, 'str' => 'string', 'bool' => true, EnvelopeInterface::ENVELOPE_STACK_KEY => []],
$message->getMetadata()
);
}

public function testUnserializeEnvelopeStack(): void
Expand Down

0 comments on commit 2bb91ad

Please sign in to comment.