Skip to content

Commit 52e7d05

Browse files
committed
Use a property attributes instead of a key in headers
1 parent 3ee5bf1 commit 52e7d05

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

GpsMessage.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class GpsMessage implements Message, \JsonSerializable
2424
*/
2525
private $headers;
2626

27+
/**
28+
* @var array
29+
*/
30+
private $attributes;
31+
2732
/**
2833
* @var bool
2934
*/
@@ -34,18 +39,12 @@ class GpsMessage implements Message, \JsonSerializable
3439
*/
3540
private $nativeMessage;
3641

37-
/**
38-
* @var array
39-
*/
40-
private $attributes;
41-
42-
public function __construct(string $body = '', array $properties = [], array $headers = [])
42+
public function __construct(string $body = '', array $properties = [], array $headers = [], array $attributes = [])
4343
{
4444
$this->body = $body;
4545
$this->properties = $properties;
46-
$this->attributes = $headers['attributes'] ?? [];
47-
unset($headers['attributes']);
4846
$this->headers = $headers;
47+
$this->attributes = $attributes;
4948

5049
$this->redelivered = false;
5150
}
@@ -181,6 +180,11 @@ public function setNativeMessage(?GoogleMessage $message = null): void
181180
$this->nativeMessage = $message;
182181
}
183182

183+
public function setAttributes(array $attributes): void
184+
{
185+
$this->attributes = $attributes;
186+
}
187+
184188
public function getAttributes(): array
185189
{
186190
return $this->attributes;

Tests/GpsMessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()
7373

7474
public function testGetAttributes()
7575
{
76-
$message = new GpsMessage('the body', [], ['attributes' => ['key1' => 'value1']]);
76+
$message = new GpsMessage('the body', [], [], ['key1' => 'value1']);
7777

7878
$attributes = $message->getAttributes();
7979

Tests/GpsProducerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function testShouldSendMessage()
3535
->method('publish')
3636
->with($this->identicalTo([
3737
'data' => '{"body":"","properties":[],"headers":[]}',
38-
])
39-
);
38+
]));
4039

4140
$client = $this->createPubSubClientMock();
4241
$client
@@ -60,7 +59,7 @@ public function testShouldSendMessage()
6059
public function testShouldSendMessageWithAttributes()
6160
{
6261
$topic = new GpsTopic('topic-name');
63-
$message = new GpsMessage('', [], ['attributes' => ['key1' => 'value1']]);
62+
$message = new GpsMessage('', [], [], ['key1' => 'value1']);
6463

6564
$gtopic = $this->createGTopicMock();
6665
$gtopic

0 commit comments

Comments
 (0)