Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c8c4993

Browse files
committed
GPS: revert the attributes and use the headers instead.
1 parent 2d41b6e commit c8c4993

File tree

4 files changed

+12
-40
lines changed

4 files changed

+12
-40
lines changed

‎pkg/gps/GpsMessage.php‎

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

27-
/**
28-
* @var array
29-
*/
30-
private $attributes;
31-
3227
/**
3328
* @var bool
3429
*/
@@ -39,12 +34,11 @@ class GpsMessage implements Message, \JsonSerializable
3934
*/
4035
private $nativeMessage;
4136

42-
public function __construct(string $body = '', array $properties = [], array $headers = [], array$attributes = [])
37+
public function __construct(string $body = '', array $properties = [], array $headers = [])
4338
{
4439
$this->body = $body;
4540
$this->properties = $properties;
4641
$this->headers = $headers;
47-
$this->attributes = $attributes;
4842

4943
$this->redelivered = false;
5044
}
@@ -157,7 +151,6 @@ public function jsonSerialize(): array
157151
'body' => $this->getBody(),
158152
'properties' => $this->getProperties(),
159153
'headers' => $this->getHeaders(),
160-
'attributes' => $this->getAttributes(),
161154
];
162155
}
163156

@@ -168,7 +161,7 @@ public static function jsonUnserialize(string $json): self
168161
throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg()));
169162
}
170163

171-
return new self($data['body'] ?? $json, $data['properties'] ?? [], $data['headers'] ?? [], $data['attributes'] ?? []);
164+
return new self($data['body'] ?? $json, $data['properties'] ?? [], $data['headers'] ?? []);
172165
}
173166

174167
public function getNativeMessage(): ?GoogleMessage
@@ -180,14 +173,4 @@ public function setNativeMessage(?GoogleMessage $message = null): void
180173
{
181174
$this->nativeMessage = $message;
182175
}
183-
184-
public function setAttributes(array $attributes): void
185-
{
186-
$this->attributes = $attributes;
187-
}
188-
189-
public function getAttributes(): array
190-
{
191-
return $this->attributes;
192-
}
193176
}

‎pkg/gps/GpsProducer.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function send(Destination $destination, Message $message): void
4040

4141
$params = ['data' => json_encode($message)];
4242

43-
if (count($message->getAttributes()) > 0) {
44-
$params['attributes'] = $message->getAttributes();
43+
if (count($message->getHeaders()) > 0) {
44+
$params['attributes'] = $message->getHeaders();
4545
}
4646

4747
$topic->publish($params);

‎pkg/gps/Tests/GpsMessageTest.php‎

Lines changed: 4 additions & 15 deletions
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'], ['theAttributeFoo' => 'theAttributeFooVal']);
21+
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
2222

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

2626
public function testCouldBeUnserializedFromJson()
2727
{
28-
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal'], ['theAttributeFoo' => 'theAttributeFooVal']);
28+
$message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
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"},"attributes":{"theAttributeFoo":"theAttributeFooVal"}}';
43+
$json = '{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}';
4444

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

@@ -49,7 +49,6 @@ 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());
5352
}
5453

5554
public function testMessagePayloadCouldBeUnserializedFromJson()
@@ -62,7 +61,6 @@ public function testMessagePayloadCouldBeUnserializedFromJson()
6261
$this->assertEquals($json, $unserializedMessage->getBody());
6362
$this->assertEquals([], $unserializedMessage->getProperties());
6463
$this->assertEquals([], $unserializedMessage->getHeaders());
65-
$this->assertEquals([], $unserializedMessage->getAttributes());
6664
}
6765

6866
public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()
@@ -72,13 +70,4 @@ public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()
7270

7371
GpsMessage::jsonUnserialize('{]');
7472
}
75-
76-
public function testGetAttributes()
77-
{
78-
$message = new GpsMessage('the body', [], [], ['key1' => 'value1']);
79-
80-
$attributes = $message->getAttributes();
81-
82-
$this->assertSame(['key1' => 'value1'], $attributes);
83-
}
8473
}

‎pkg/gps/Tests/GpsProducerTest.php‎

Lines changed: 4 additions & 4 deletions
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":[],"attributes":[]}',
37+
'data' => '{"body":"","properties":[],"headers":[]}',
3838
]));
3939

4040
$client = $this->createPubSubClientMock();
@@ -56,16 +56,16 @@ public function testShouldSendMessage()
5656
$producer->send($topic, $message);
5757
}
5858

59-
public function testShouldSendMessageWithAttributes()
59+
public function testShouldSendMessageWithHeaders()
6060
{
6161
$topic = new GpsTopic('topic-name');
62-
$message = new GpsMessage('', [], [], ['key1' => 'value1']);
62+
$message = new GpsMessage('', [], ['key1' => 'value1']);
6363

6464
$gtopic = $this->createGTopicMock();
6565
$gtopic
6666
->expects($this->once())
6767
->method('publish')
68-
->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[],"attributes":{"key1":"value1"}}', 'attributes' => ['key1' => 'value1']]))
68+
->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":{"key1":"value1"}}', 'attributes' => ['key1' => 'value1']]))
6969
;
7070

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /