Skip to content

Commit ccf883b

Browse files
authored
Merge pull request #221 from StyxOfDynamite/issue/220
issue/220
2 parents b421a79 + ce3f66d commit ccf883b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/FcmMessage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ public function condition(?string $condition): self
7676
}
7777

7878
/**
79-
* Set the message data.
79+
* Set the message data, or throw exception if data is not an array of strings.
8080
*/
8181
public function data(?array $data): self
8282
{
83+
if (! empty(array_filter($data, fn ($value) => ! is_string($value)))) {
84+
throw new \InvalidArgumentException('Data values must be strings.');
85+
}
86+
8387
$this->data = $data;
8488

8589
return $this;

tests/FcmMessageTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public function test_it_can_set_data()
6363
$this->assertEquals(['data' => ['a' => 'b']], $message->toArray());
6464
}
6565

66+
public function test_it_throws_exception_on_invalid_data()
67+
{
68+
$this->expectException(\InvalidArgumentException::class);
69+
70+
FcmMessage::create()->data(['a' => 1]);
71+
}
72+
6673
public function test_it_can_set_custom_attributes()
6774
{
6875
$message = FcmMessage::create()

0 commit comments

Comments
 (0)