Skip to content

Commit

Permalink
Merge pull request #147 from danielsimkus/add-interruption-level-enum
Browse files Browse the repository at this point in the history
Add interruption level enum
  • Loading branch information
dwightwatson authored Aug 13, 2024
2 parents 63ef817 + f72c7f7 commit bde87eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/ApnMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ public function sound(null|string|Sound $sound = 'default'): self
/**
* Set the interruptionLevel of the notification.
*/
public function interruptionLevel(?string $interruptionLevel = 'active'): self
public function interruptionLevel(string|ApnMessageInterruptionLevel|null $interruptionLevel = 'active'): self
{
$this->interruptionLevel = $interruptionLevel;
$this->interruptionLevel = $interruptionLevel instanceof ApnMessageInterruptionLevel
? $interruptionLevel->value
: $interruptionLevel;

return $this;
}
Expand Down
11 changes: 11 additions & 0 deletions src/ApnMessageInterruptionLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace NotificationChannels\Apn;

enum ApnMessageInterruptionLevel: string
{
case Active = 'active';
case Critical = 'critical';
case Passive = 'passive';
case TimeSensitive = 'time-sensitive';
}
14 changes: 13 additions & 1 deletion tests/ApnMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use Mockery;
use NotificationChannels\Apn\ApnMessage;
use NotificationChannels\Apn\ApnMessageInterruptionLevel;
use Pushok\Client;

class ApnMessageTest extends TestCase
Expand Down Expand Up @@ -78,7 +79,7 @@ public function it_can_set_sound()
}

/** @test */
public function it_can_set_interruption_level()
public function it_can_set_interruption_level_as_string()
{
$message = new ApnMessage;

Expand All @@ -88,6 +89,17 @@ public function it_can_set_interruption_level()
$this->assertEquals($message, $result);
}

/** @test */
public function it_can_set_interruption_level_as_enum()
{
$message = new ApnMessage;

$result = $message->interruptionLevel(ApnMessageInterruptionLevel::Critical);

$this->assertEquals('critical', $message->interruptionLevel);
$this->assertEquals($message, $result);
}

/** @test */
public function it_can_set_sound_to_default()
{
Expand Down

0 comments on commit bde87eb

Please sign in to comment.