diff --git a/src/ApnAdapter.php b/src/ApnAdapter.php index 6d78a32..e1fdda6 100644 --- a/src/ApnAdapter.php +++ b/src/ApnAdapter.php @@ -48,9 +48,15 @@ public function adapt(ApnMessage $message, string $token) } $payload = Payload::create() - ->setAlert($alert) - ->setContentAvailability((bool) $message->contentAvailable) - ->setMutableContent((bool) $message->mutableContent); + ->setAlert($alert); + + if ($contentAvailable = $message->contentAvailable) { + $payload->setContentAvailability((bool) $message->contentAvailable); + } + + if ($mutableContent = $message->mutableContent) { + $payload->setMutableContent((bool) $message->mutableContent); + } if (is_int($badge = $message->badge)) { $payload->setBadge($badge); diff --git a/tests/ApnAdapterTest.php b/tests/ApnAdapterTest.php index 31eb8da..29c7213 100644 --- a/tests/ApnAdapterTest.php +++ b/tests/ApnAdapterTest.php @@ -45,6 +45,16 @@ public function it_adapts_content_available() $this->assertTrue($notification->getPayload()->isContentAvailable()); } + /** @test */ + public function it_does_not_set_content_available_by_default() + { + $message = (new ApnMessage); + + $notification = $this->adapter->adapt($message, 'token'); + + $this->assertNull($notification->getPayload()->isContentAvailable()); + } + /** @test */ public function it_adapts_mutable_content() { @@ -55,6 +65,16 @@ public function it_adapts_mutable_content() $this->assertTrue($notification->getPayload()->hasMutableContent()); } + /** @test */ + public function it_does_not_set_mutable_content_by_default() + { + $message = (new ApnMessage); + + $notification = $this->adapter->adapt($message, 'token'); + + $this->assertNull($notification->getPayload()->hasMutableContent()); + } + /** @test */ public function it_adapts_badge() {