Skip to content

Commit

Permalink
Allow ApnMessage::interruptionLevel to receive either string or enum
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimkus committed Aug 13, 2024
1 parent 4e318e3 commit f72c7f7
Show file tree
Hide file tree
Showing 2 changed files with 17 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
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 f72c7f7

Please sign in to comment.