Skip to content

Commit

Permalink
Merge pull request #221 from StyxOfDynamite/issue/220
Browse files Browse the repository at this point in the history
issue/220
  • Loading branch information
dwightwatson authored Feb 26, 2025
2 parents b421a79 + ce3f66d commit ccf883b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/FcmMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ public function condition(?string $condition): self
}

/**
* Set the message data.
* Set the message data, or throw exception if data is not an array of strings.
*/
public function data(?array $data): self
{
if (! empty(array_filter($data, fn ($value) => ! is_string($value)))) {
throw new \InvalidArgumentException('Data values must be strings.');
}

$this->data = $data;

return $this;
Expand Down
7 changes: 7 additions & 0 deletions tests/FcmMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public function test_it_can_set_data()
$this->assertEquals(['data' => ['a' => 'b']], $message->toArray());
}

public function test_it_throws_exception_on_invalid_data()
{
$this->expectException(\InvalidArgumentException::class);

FcmMessage::create()->data(['a' => 1]);
}

public function test_it_can_set_custom_attributes()
{
$message = FcmMessage::create()
Expand Down

0 comments on commit ccf883b

Please sign in to comment.