diff --git a/src/Lunr/Vortex/APNS/APNSLiveActivityPayload.php b/src/Lunr/Vortex/APNS/APNSLiveActivityPayload.php new file mode 100644 index 0000000..77549f3 --- /dev/null +++ b/src/Lunr/Vortex/APNS/APNSLiveActivityPayload.php @@ -0,0 +1,141 @@ +elements['event'] = $event; + + return $this; + } + + /** + * Sets the payload key contentState. + * + * @param array|object $state The current content state for the live activity + * + * @return self Self Reference + */ + public function set_content_state(array|object $state): self + { + $this->elements['contentState'] = $state; + + return $this; + } + + /** + * Sets the payload key attributes. + * + * @param array|object $attributes The starting attributes for the live activity + * + * @return self Self Reference + */ + public function set_attributes(array|object $attributes): self + { + $this->elements['attributes'] = $attributes; + + return $this; + } + + /** + * Sets the payload key attributesType. + * + * @param string $type The starting attributes type for the live activity + * + * @return self Self Reference + */ + public function set_attributes_type(string $type): self + { + $this->elements['attributesType'] = $type; + + return $this; + } + + /** + * Sets the payload key staleTime. + * + * @param int $time The timestamp when the activity should become stale + * + * @return self Self Reference + */ + public function set_stale_timestamp(int $time): self + { + $this->elements['staleTime'] = $time; + + return $this; + } + + /** + * Sets the payload key dismissTime. + * + * @param int $time The timestamp when the activity should dismiss + * + * @return self Self Reference + */ + public function set_dismiss_timestamp(int $time): self + { + $this->elements['dismissTime'] = $time; + + return $this; + } +} + +?> diff --git a/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadGetTest.php b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadGetTest.php new file mode 100644 index 0000000..9eb0665 --- /dev/null +++ b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadGetTest.php @@ -0,0 +1,41 @@ +set_reflection_property_value('elements', $elements); + + $this->assertJsonStringEqualsJsonFile($file, json_encode($this->class->get_payload())); + } + +} + +?> diff --git a/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadSetTest.php b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadSetTest.php new file mode 100644 index 0000000..f134dd7 --- /dev/null +++ b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadSetTest.php @@ -0,0 +1,175 @@ +class->set_event(LiveActivityEvent::Start); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('event', $value); + $this->assertEquals(LiveActivityEvent::Start, $value['event']); + } + + /** + * Test fluid interface of set_event(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_event + */ + public function testSetEventReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_event(LiveActivityEvent::Start)); + } + + /** + * Test set_content_state() works correctly. + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_content_state + */ + public function testSetContentState(): void + { + $this->class->set_content_state([]); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('contentState', $value); + $this->assertEquals([], $value['contentState']); + } + + /** + * Test fluid interface of set_content_state(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_content_state + */ + public function testSetContentStateReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_content_state([])); + } + + /** + * Test set_attributes() works correctly. + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_attributes + */ + public function testSetAttributes(): void + { + $this->class->set_attributes([]); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('attributes', $value); + $this->assertEquals([], $value['attributes']); + } + + /** + * Test fluid interface of set_attributes(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_attributes + */ + public function testSetAttributesReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_attributes([])); + } + + /** + * Test set_attributes_type() works correctly. + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_attributes_type + */ + public function testSetAttributesType(): void + { + $this->class->set_attributes_type('type'); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('attributesType', $value); + $this->assertEquals('type', $value['attributesType']); + } + + /** + * Test fluid interface of set_attributes_type(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_attributes_type + */ + public function testSetAttributesTypeReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_attributes_type('type')); + } + + /** + * Test set_stale_timestamp() works correctly. + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_stale_timestamp + */ + public function testSetStaleTime(): void + { + $this->class->set_stale_timestamp(1); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('staleTime', $value); + $this->assertEquals(1, $value['staleTime']); + } + + /** + * Test fluid interface of set_stale_timestamp(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_stale_timestamp + */ + public function testSetStaleTimeReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_stale_timestamp(1)); + } + + /** + * Test set_dismiss_timestamp() works correctly. + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_dismiss_timestamp + */ + public function testSetDismissTime(): void + { + $this->class->set_dismiss_timestamp(1); + + $value = $this->get_reflection_property_value('elements'); + + $this->assertArrayHasKey('dismissTime', $value); + $this->assertEquals(1, $value['dismissTime']); + } + + /** + * Test fluid interface of set_dismiss_timestamp(). + * + * @covers Lunr\Vortex\APNS\APNSLiveActivityPayload::set_dismiss_timestamp + */ + public function testSetDismissTimeReturnsSelfReference(): void + { + $this->assertSame($this->class, $this->class->set_dismiss_timestamp(1)); + } + +} + +?> diff --git a/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadTest.php b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadTest.php new file mode 100644 index 0000000..94026be --- /dev/null +++ b/src/Lunr/Vortex/APNS/Tests/APNSLiveActivityPayloadTest.php @@ -0,0 +1,95 @@ + 'apnsmessage', + 'badge' => 10, + 'sound' => 'bingbong.wav', + 'custom_data' => [ + 'key1' => 'value1', + 'key2' => 'value2', + ], + ]; + + $this->payload = json_encode($elements_array); + + $this->class = new APNSLiveActivityPayload(); + + parent::baseSetUp($this->class); + } + + /** + * TestCase Destructor. + */ + public function tearDown(): void + { + unset($this->payload); + unset($this->class); + + parent::tearDown(); + } + + /** + * Unit test data provider for payload files. + * + * @return array $values Array of non-object values + */ + public function payloadProvider(): array + { + $values = []; + $values['alert'] = [ '/Vortex/apns/alert.json', [ 'alert' => 'apnsmessage' ] ]; + $values['custom data'] = [ '/Vortex/apns/custom_data.json', [ 'custom_data' => [ 'key1' => 'value1', 'key2' => 'value2' ] ] ]; + $values['badge'] = [ '/Vortex/apns/badge.json', [ 'badge' => 10 ] ]; + $values['full'] = [ + '/Vortex/apns/apns.json', + [ + 'alert' => 'apnsmessage', + 'badge' => 10, + 'sound' => 'bingbong.wav', + 'custom_data' => [ 'key1' => 'value1', 'key2' => 'value2' ], + ], + ]; + + return $values; + } + +} + +?>