Skip to content

Commit 719e9e8

Browse files
committed
get attributes in unserialization
1 parent e2fae17 commit 719e9e8

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pkg/gps/GpsMessage.php

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function jsonSerialize(): array
157157
'body' => $this->getBody(),
158158
'properties' => $this->getProperties(),
159159
'headers' => $this->getHeaders(),
160+
'attributes' => $this->getAttributes(),
160161
];
161162
}
162163

pkg/gps/Tests/GpsMessageTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public function testCouldSetGetNativeMessage()
1818

1919
public function testColdBeSerializedToJson()
2020
{
21-
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
21+
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal'], ['theAttributeFoo' => 'theAttributeFooVal']);
2222

23-
$this->assertEquals('{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}', json_encode($message));
23+
$this->assertEquals('{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"},"attributes":{"theAttributeFoo":"theAttributeFooVal"}}', json_encode($message));
2424
}
2525

2626
public function testCouldBeUnserializedFromJson()
2727
{
28-
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
28+
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal'], ['theAttributeFoo' => 'theAttributeFooVal']);
2929

3030
$json = json_encode($message);
3131

@@ -40,7 +40,7 @@ public function testCouldBeUnserializedFromJson()
4040

4141
public function testMessageEntityCouldBeUnserializedFromJson()
4242
{
43-
$json = '{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}';
43+
$json = '{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"},"attributes":{"theAttributeFoo":"theAttributeFooVal"}}';
4444

4545
$unserializedMessage = GpsMessage::jsonUnserialize($json);
4646

@@ -49,6 +49,7 @@ public function testMessageEntityCouldBeUnserializedFromJson()
4949
$this->assertEquals($decoded['body'], $unserializedMessage->getBody());
5050
$this->assertEquals($decoded['properties'], $unserializedMessage->getProperties());
5151
$this->assertEquals($decoded['headers'], $unserializedMessage->getHeaders());
52+
$this->assertEquals($decoded['attributes'], $unserializedMessage->getAttributes());
5253
}
5354

5455
public function testMessagePayloadCouldBeUnserializedFromJson()
@@ -61,6 +62,7 @@ public function testMessagePayloadCouldBeUnserializedFromJson()
6162
$this->assertEquals($json, $unserializedMessage->getBody());
6263
$this->assertEquals([], $unserializedMessage->getProperties());
6364
$this->assertEquals([], $unserializedMessage->getHeaders());
65+
$this->assertEquals([], $unserializedMessage->getAttributes());
6466
}
6567

6668
public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()

pkg/gps/Tests/GpsProducerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testShouldSendMessage()
3434
->expects($this->once())
3535
->method('publish')
3636
->with($this->identicalTo([
37-
'data' => '{"body":"","properties":[],"headers":[]}',
37+
'data' => '{"body":"","properties":[],"headers":[],"attributes":[]}',
3838
]));
3939

4040
$client = $this->createPubSubClientMock();
@@ -65,7 +65,7 @@ public function testShouldSendMessageWithAttributes()
6565
$gtopic
6666
->expects($this->once())
6767
->method('publish')
68-
->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[]}', 'attributes' => ['key1' => 'value1']]))
68+
->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[],"attributes":{"key1":"value1"}}', 'attributes' => ['key1' => 'value1']]))
6969
;
7070

7171
$client = $this->createPubSubClientMock();

0 commit comments

Comments
 (0)