File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments