Skip to content

Commit 62d514c

Browse files
authored
Merge pull request #1 from kmarques/master
[FIX] spec for content_available
2 parents 61e1206 + c6b59ec commit 62d514c

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Or add this to your composer.json and run "composer update":
2222
}
2323
```
2424

25-
#Send message to Device
25+
#Send message to **one or multiple** Devices
2626
```
2727
use sngrl\PhpFirebaseCloudMessaging\Client;
2828
use sngrl\PhpFirebaseCloudMessaging\Message;

src/Message.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Message implements \JsonSerializable
1313
private $notification;
1414
private $collapseKey;
1515
private $priority;
16+
private $contentAvailable;
1617
private $data;
1718
private $recipients = [];
1819
private $recipientType;
@@ -62,6 +63,17 @@ public function setPriority($priority)
6263
return $this;
6364
}
6465

66+
public function getContentAvailable()
67+
{
68+
return $this->contentAvailable;
69+
}
70+
71+
public function setContentAvailable($contentAvailable)
72+
{
73+
$this->contentAvailable = $contentAvailable;
74+
return $this;
75+
}
76+
6577
public function setData(array $data)
6678
{
6779
$this->data = $data;
@@ -159,6 +171,9 @@ public function jsonSerialize()
159171
if ($this->priority) {
160172
$jsonData['priority'] = $this->priority;
161173
}
174+
if ($this->contentAvailable) {
175+
$jsonData['content_available'] = $this->contentAvailable;
176+
}
162177
if ($this->notification) {
163178
$jsonData['notification'] = $this->notification;
164179
}

src/Notification.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Notification extends Message
1313
private $sound;
1414
private $clickAction;
1515
private $tag;
16-
private $content_available;
1716

1817
public function __construct($title = '', $body = '')
1918
{
@@ -78,12 +77,6 @@ public function setTag($tag)
7877
return $this;
7978
}
8079

81-
public function setContentAvailable($content_available)
82-
{
83-
$this->content_available = $content_available;
84-
return $this;
85-
}
86-
8780
public function jsonSerialize()
8881
{
8982
$jsonData = $this->getJsonData();
@@ -108,9 +101,6 @@ public function jsonSerialize()
108101
if ($this->tag) {
109102
$jsonData['tag'] = $this->tag;
110103
}
111-
if ($this->content_available) {
112-
$jsonData['content_available'] = $this->content_available;
113-
}
114104
return $jsonData;
115105
}
116106
}

tests/MessageTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,19 @@ public function testJsonEncodeWorksOnDeviceRecipients()
6868
json_encode($message)
6969
);
7070
}
71+
72+
public function testJsonSerializeWithContentAvailable()
73+
{
74+
$body = '{"to":"deviceId","content_available":true,"notification":{"title":"test","body":"a nice testing notification"}}';
75+
76+
$notification = new Notification('test', 'a nice testing notification');
77+
$message = new Message();
78+
$message->setNotification($notification);
79+
$message->setContentAvailable(true);
80+
$message->addRecipient(new Device('deviceId'));
81+
$this->assertSame(
82+
$body,
83+
json_encode($message)
84+
);
85+
}
7186
}

tests/NotificationTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,4 @@ public function testJsonSerializeWithIcon()
2929
$this->fixture->setIcon('name');
3030
$this->assertEquals(array('title' => 'foo', 'body' =>'bar', 'icon' => 'name'), $this->fixture->jsonSerialize());
3131
}
32-
33-
public function testJsonSerializeWithContentAvailable()
34-
{
35-
$this->fixture->setContentAvailable(true);
36-
$this->assertEquals(array('title' => 'foo', 'body' =>'bar', 'content_available' => true), $this->fixture->jsonSerialize());
37-
}
3832
}

0 commit comments

Comments
 (0)