Skip to content

Commit

Permalink
Merge pull request #113 from koenhoeijmakers/master
Browse files Browse the repository at this point in the history
Do not always set content-available and mutable-content
  • Loading branch information
dwightwatson authored Nov 24, 2020
2 parents b2b4972 + a5515b7 commit cc0100e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ApnAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions tests/ApnAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down

0 comments on commit cc0100e

Please sign in to comment.