diff --git a/src/Lunr/Vortex/FCM/FCMPayload.php b/src/Lunr/Vortex/FCM/FCMPayload.php index 46d4a9c..f3eb3ea 100644 --- a/src/Lunr/Vortex/FCM/FCMPayload.php +++ b/src/Lunr/Vortex/FCM/FCMPayload.php @@ -192,65 +192,27 @@ public function set_token(string $token): self } /** - * Get the android payload element. + * Returns a reference of the android payload element. * * @return FCMAndroidPayload */ - public function get_android_payload(): FCMAndroidPayload + public function android_payload(): FCMAndroidPayload { - return $this->android_payload ?? new FCMAndroidPayload(); - } - - /** - * Set the android payload element. - * - * @param array|FCMAndroidPayload $payload The android payload element - * - * @return self self Reference - */ - public function set_android_payload(array|FCMAndroidPayload $payload): self - { - if (is_array($payload)) - { - $this->elements['android'] = $payload; - - return $this; - } - - $this->android_payload = $payload; + $this->android_payload ??= new FCMAndroidPayload(); - return $this; + return $this->android_payload; } /** - * Get the apns payload element. + * Returns a reference the apns payload element. * * @return FCMApnsPayload */ - public function get_apns_payload(): FCMApnsPayload + public function apns_payload(): FCMApnsPayload { - return $this->apns_payload ?? new FCMApnsPayload(); - } - - /** - * Set the apns payload element. - * - * @param array|FCMApnsPayload $payload The android payload element - * - * @return self self Reference - */ - public function set_apns_payload(array|FCMApnsPayload $payload): self - { - if (is_array($payload)) - { - $this->elements['apns'] = $payload; - - return $this; - } - - $this->apns_payload = $payload; + $this->apns_payload ??= new FCMApnsPayload(); - return $this; + return $this->apns_payload; } } diff --git a/src/Lunr/Vortex/FCM/Tests/FCMPayloadGetTest.php b/src/Lunr/Vortex/FCM/Tests/FCMPayloadGetTest.php index e190286..72e8de3 100644 --- a/src/Lunr/Vortex/FCM/Tests/FCMPayloadGetTest.php +++ b/src/Lunr/Vortex/FCM/Tests/FCMPayloadGetTest.php @@ -151,47 +151,59 @@ public function testGetJsonPayloadWithApns(): void } /** - * Test get_android_payload() returns new payload. + * Test android_payload() returns new payload. * - * @covers Lunr\Vortex\FCM\FCMPayload::get_android_payload + * @covers Lunr\Vortex\FCM\FCMPayload::android_payload */ - public function testGetAndroidPayloadReturnsNewPayload(): void + public function testAndroidPayloadReturnsNewPayload(): void { - $this->assertInstanceOf(FCMAndroidPayload::class, $this->class->get_android_payload()); + $return = $this->class->android_payload(); + + $this->assertInstanceOf(FCMAndroidPayload::class, $return); + + $property_value = $this->get_reflection_property_value('android_payload'); + + $this->assertSame($return, $property_value); } /** - * Test get_android_payload() returns saved payload. + * Test android_payload() returns saved payload. * - * @covers Lunr\Vortex\FCM\FCMPayload::get_android_payload + * @covers Lunr\Vortex\FCM\FCMPayload::android_payload */ - public function testGetAndroidPayloadReturnsSavedPayload(): void + public function testAndroidPayloadReturnsSavedPayload(): void { $this->set_reflection_property_value('android_payload', $this->android_payload); - $this->assertSame($this->android_payload, $this->class->get_android_payload()); + $this->assertSame($this->android_payload, $this->class->android_payload()); } /** - * Test get_apns_payload() returns new payload. + * Test apns_payload() returns new payload. * - * @covers Lunr\Vortex\FCM\FCMPayload::get_apns_payload + * @covers Lunr\Vortex\FCM\FCMPayload::apns_payload */ public function testGetApnsPayloadReturnsNewPayload(): void { - $this->assertInstanceOf(FCMApnsPayload::class, $this->class->get_apns_payload()); + $return = $this->class->apns_payload(); + + $this->assertInstanceOf(FCMApnsPayload::class, $return); + + $property_value = $this->get_reflection_property_value('apns_payload'); + + $this->assertSame($return, $property_value); } /** - * Test get_apns_payload() returns saved payload. + * Test apns_payload() returns saved payload. * - * @covers Lunr\Vortex\FCM\FCMPayload::get_apns_payload + * @covers Lunr\Vortex\FCM\FCMPayload::apns_payload */ public function testGetApnsPayloadReturnsSavedPayload(): void { $this->set_reflection_property_value('apns_payload', $this->apns_payload); - $this->assertSame($this->apns_payload, $this->class->get_apns_payload()); + $this->assertSame($this->apns_payload, $this->class->apns_payload()); } } diff --git a/src/Lunr/Vortex/FCM/Tests/FCMPayloadSetTest.php b/src/Lunr/Vortex/FCM/Tests/FCMPayloadSetTest.php index 64d6be1..10701c5 100644 --- a/src/Lunr/Vortex/FCM/Tests/FCMPayloadSetTest.php +++ b/src/Lunr/Vortex/FCM/Tests/FCMPayloadSetTest.php @@ -169,104 +169,6 @@ public function testSetTokenReturnsSelfReference() $this->assertSame($this->class, $this->class->set_token('endpoint_token')); } - /** - * Test set_android_payload() works correctly. - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_android_payload - */ - public function testSetAndroidPayloadWorksCorrectlyWithArray() - { - $this->class->set_android_payload([ 'notification' => 'test' ]); - - $value = $this->get_reflection_property_value('elements'); - - $this->assertArrayHasKey('android', $value); - $this->assertEquals([ 'notification' => 'test' ], $value['android']); - } - - /** - * Test fluid interface of set_android_payload(). - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_android_payload - */ - public function testSetAndroidPayloadReturnsSelfReferenceWithArray() - { - $this->assertSame($this->class, $this->class->set_android_payload([ 'notification' => 'test' ])); - } - - /** - * Test set_android_payload() works correctly. - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_android_payload - */ - public function testSetAndroidPayloadWorksCorrectlyWithAndroidPayload() - { - $this->class->set_android_payload($this->android_payload); - - $value = $this->get_reflection_property_value('android_payload'); - - $this->assertEquals($this->android_payload, $value); - } - - /** - * Test fluid interface of set_android_payload(). - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_android_payload - */ - public function testSetAndroidPayloadReturnsSelfReferenceWithAndroidPayload() - { - $this->assertSame($this->class, $this->class->set_android_payload($this->android_payload)); - } - - /** - * Test set_apns_payload() works correctly. - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_apns_payload - */ - public function testSetApnsPayloadWorksCorrectlyWithArray() - { - $this->class->set_apns_payload([ 'notification' => 'test' ]); - - $value = $this->get_reflection_property_value('elements'); - - $this->assertArrayHasKey('apns', $value); - $this->assertEquals([ 'notification' => 'test' ], $value['apns']); - } - - /** - * Test fluid interface of set_apns_payload(). - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_apns_payload - */ - public function testSetApnsPayloadReturnsSelfReferenceWithArray() - { - $this->assertSame($this->class, $this->class->set_apns_payload([ 'notification' => 'test' ])); - } - - /** - * Test set_apns_payload() works correctly. - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_apns_payload - */ - public function testSetApnsPayloadWorksCorrectlyWithApnsPayload() - { - $this->class->set_apns_payload($this->apns_payload); - - $value = $this->get_reflection_property_value('apns_payload'); - - $this->assertEquals($this->apns_payload, $value); - } - - /** - * Test fluid interface of set_apns_payload(). - * - * @covers \Lunr\Vortex\FCM\FCMPayload::set_apns_payload - */ - public function testSetApnsPayloadReturnsSelfReferenceWithApnsPayload() - { - $this->assertSame($this->class, $this->class->set_apns_payload($this->apns_payload)); - } - } ?>