Skip to content

Commit 1007041

Browse files
committed
[domain] force message priority serialization
1 parent 7be36d2 commit 1007041

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/Domain/Message.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function ToObject(): object {
105105
$obj->priority = $this->priority;
106106
}
107107

108+
// Go wire parity: Message.Priority has no omitempty and always
109+
// serializes (zero value 0).
110+
$obj->priority = $this->priority ?? 0;
111+
108112
if ($this->ttl !== null) {
109113
$obj->ttl = $this->ttl;
110114
}

‎tests/Domain/MessageTest.php‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testCanSerializeToObject(): void {
3131
$expected = (object) [
3232
'id' => $id,
3333
'message' => $messageText,
34+
'priority' => 0,
3435
'ttl' => $ttl,
3536
'simNumber' => $simNumber,
3637
'withDeliveryReport' => $withDeliveryReport,
@@ -52,5 +53,17 @@ public function testDefaultsWithNullParameters(): void {
5253
$this->assertNull($serialized->simNumber);
5354
$this->assertTrue($serialized->withDeliveryReport);
5455
$this->assertFalse($serialized->isEncrypted);
56+
$this->assertSame(0, $serialized->priority);
5557
}
56-
}
58+
59+
public function testLegacyTextMessageStillSerializesMessageKey(): void {
60+
$message = new Message('Hello', ['+1234567890']);
61+
62+
$json = json_encode($message->ToObject(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
63+
64+
$this->assertSame(
65+
'{"id":null,"message":"Hello","simNumber":null,"withDeliveryReport":true,"isEncrypted":false,"phoneNumbers":["+1234567890"],"priority":0}',
66+
$json
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)