Skip to content

[Messenger] choose the proper array element to decode the message #43656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public function redisEnvelopeProvider(): \Generator
yield [
[
'id' => 1,
'data' => json_encode([
'body' => '{"message": "Hi"}',
'headers' => [
'type' => DummyMessage::class,
],
]),
'data' => [
'message' => json_encode([
'body' => '{"message": "Hi"}',
'headers' => [
'type' => DummyMessage::class,
],
]),
],
],
new DummyMessage('Hi'),
new Serializer(
Expand All @@ -80,12 +82,14 @@ public function redisEnvelopeProvider(): \Generator
yield [
[
'id' => 2,
'data' => json_encode([
'foo' => 'fooValue',
'bar' => [
'baz' => 'bazValue',
],
]),
'data' => [
'message' => json_encode([
'foo' => 'fooValue',
'bar' => [
'baz' => 'bazValue',
],
]),
],
],
(new ExternalMessage('fooValue'))->setBar(['baz' => 'bazValue']),
new ExternalMessageSerializer(),
Expand All @@ -97,24 +101,28 @@ public function rejectedRedisEnvelopeProvider(): \Generator
yield [
[
'id' => 1,
'data' => json_encode([
'body' => '{"message": "Hi"}',
'headers' => [
'type' => DummyMessage::class,
],
]),
'data' => [
'message' => json_encode([
'body' => '{"message": "Hi"}',
'headers' => [
'type' => DummyMessage::class,
],
]),
],
],
];

yield [
[
'id' => 2,
'data' => json_encode([
'foo' => 'fooValue',
'bar' => [
'baz' => 'bazValue',
],
]),
'data' => [
'message' => json_encode([
'foo' => 'fooValue',
'bar' => [
'baz' => 'bazValue',
],
]),
],
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function testReceivesMessages()

$redisEnvelope = [
'id' => '5',
'data' => json_encode([
'body' => 'body',
'headers' => ['my' => 'header'],
]),
'data' => [
'message' => json_encode([
'body' => 'body',
'headers' => ['my' => 'header'],
]),
],
];

$serializer->method('decode')->with(['body' => 'body', 'headers' => ['my' => 'header']])->willReturn(new Envelope($decodedMessage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function get(): iterable
return [];
}

$redisEnvelope = json_decode($message['data'], true);
$redisEnvelope = json_decode($message['data']['message'] ?? '', true);

try {
if (\array_key_exists('body', $redisEnvelope) && \array_key_exists('headers', $redisEnvelope)) {
Expand Down