From 4e318e302a27498d3a888dbce81b55f672879867 Mon Sep 17 00:00:00 2001 From: Daniel Simkus Date: Tue, 13 Aug 2024 08:49:53 +0100 Subject: [PATCH 1/2] Add Enum for InterruptionLevel --- src/ApnMessageInterruptionLevel.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/ApnMessageInterruptionLevel.php diff --git a/src/ApnMessageInterruptionLevel.php b/src/ApnMessageInterruptionLevel.php new file mode 100644 index 0000000..75eaf1b --- /dev/null +++ b/src/ApnMessageInterruptionLevel.php @@ -0,0 +1,11 @@ + Date: Tue, 13 Aug 2024 09:00:18 +0100 Subject: [PATCH 2/2] Allow ApnMessage::interruptionLevel to receive either string or enum --- src/ApnMessage.php | 6 ++++-- tests/ApnMessageTest.php | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ApnMessage.php b/src/ApnMessage.php index c1f8b22..54b9d67 100644 --- a/src/ApnMessage.php +++ b/src/ApnMessage.php @@ -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; } diff --git a/tests/ApnMessageTest.php b/tests/ApnMessageTest.php index fd657e3..f95effe 100644 --- a/tests/ApnMessageTest.php +++ b/tests/ApnMessageTest.php @@ -5,6 +5,7 @@ use DateTime; use Mockery; use NotificationChannels\Apn\ApnMessage; +use NotificationChannels\Apn\ApnMessageInterruptionLevel; use Pushok\Client; class ApnMessageTest extends TestCase @@ -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; @@ -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() {