Skip to content

Commit 5d2f0fa

Browse files
timacdonaldLukas Kämmerling
authored andcommitted
allow an empty subject (#56)
1 parent 06f31ed commit 5d2f0fa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/OneSignalMessage.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function toArray()
185185
{
186186
$message = [
187187
'contents' => ['en' => $this->body],
188-
'headings' => ['en' => $this->subject],
188+
'headings' => $this->subjectToArray(),
189189
'url' => $this->url,
190190
'buttons' => $this->buttons,
191191
'web_buttons' => $this->webButtons,
@@ -205,4 +205,13 @@ public function toArray()
205205

206206
return $message;
207207
}
208+
209+
protected function subjectToArray()
210+
{
211+
if ($this->subject === null) {
212+
return [];
213+
}
214+
215+
return ['en' => $this->subject];
216+
}
208217
}

tests/MessageTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public function it_can_set_the_subject()
5050
$this->assertEquals('mySubject', Arr::get($this->message->toArray(), 'headings.en'));
5151
}
5252

53+
/** @test */
54+
public function it_does_not_append_empty_subject_value_when_subject_is_null()
55+
{
56+
$this->assertEquals([], Arr::get($this->message->toArray(), 'headings'));
57+
}
58+
5359
/** @test */
5460
public function it_can_set_the_url()
5561
{

0 commit comments

Comments
 (0)