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
76
76
}
77
77
78
78
/**
79
- * Set the message data.
79
+ * Set the message data, or throw exception if data is not an array of strings .
80
80
*/
81
81
public function data (?array $ data ): self
82
82
{
83
+ if (! empty (array_filter ($ data , fn ($ value ) => ! is_string ($ value )))) {
84
+ throw new \InvalidArgumentException ('Data values must be strings. ' );
85
+ }
86
+
83
87
$ this ->data = $ data ;
84
88
85
89
return $ this ;
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ public function test_it_can_set_data()
63
63
$ this ->assertEquals (['data ' => ['a ' => 'b ' ]], $ message ->toArray ());
64
64
}
65
65
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
+
66
73
public function test_it_can_set_custom_attributes ()
67
74
{
68
75
$ message = FcmMessage::create ()
You can’t perform that action at this time.
0 commit comments