diff --git a/src/WebPushMessage.php b/src/WebPushMessage.php index 891b70b..2e6e2c5 100644 --- a/src/WebPushMessage.php +++ b/src/WebPushMessage.php @@ -102,7 +102,7 @@ public function title($value) */ public function action($title, $action, $icon = null) { - $this->actions[] = compact('title', 'action', 'icon'); + $this->actions[] = array_filter(compact('title', 'action', 'icon')); return $this; } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index bfbff71..8673f4e 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -27,6 +27,16 @@ public function title_can_be_set() /** @test */ public function action_can_be_set() + { + $this->message->action('Some Action', 'some_action'); + + $this->assertEquals( + [['title' => 'Some Action', 'action' => 'some_action']], $this->message->toArray()['actions'] + ); + } + + /** @test */ + public function action_can_be_set_with_icon() { $this->message->action('Some Action', 'some_action', '/icon.png');