From 985299054a416faee999b5e5f735957b589168a5 Mon Sep 17 00:00:00 2001 From: fogush Date: Wed, 18 Mar 2020 16:28:16 +0300 Subject: [PATCH] Add a few tests (#100) Co-authored-by: Denis Gurov --- tests/Payload/AlertTest.php | 14 +++++++++++--- tests/PayloadTest.php | 26 ++++++++++++++++++++++++++ tests/ResponseTest.php | 14 ++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/tests/Payload/AlertTest.php b/tests/Payload/AlertTest.php index 65c033f..0590712 100644 --- a/tests/Payload/AlertTest.php +++ b/tests/Payload/AlertTest.php @@ -23,6 +23,13 @@ public function testSetTitle() $this->assertEquals('title', $alert->getTitle()); } + public function testSetSubtitle() + { + $alert = Alert::create()->setSubtitle('subtitle'); + + $this->assertEquals('subtitle', $alert->getSubtitle()); + } + public function testSetBody() { $alert = Alert::create()->setBody('body'); @@ -76,6 +83,7 @@ public function testAlertConvertingToJson() { $alert = Alert::create() ->setTitle('title') + ->setSubtitle('subtitle') ->setBody('body') ->setTitleLocKey('title-loc-key') ->setTitleLocArgs(['loc-arg']) @@ -85,9 +93,9 @@ public function testAlertConvertingToJson() ->setLaunchImage('launch-image'); $this->assertJsonStringEqualsJsonString( - '{"title":"title","body":"body","title-loc-key":"title-loc-key","title-loc-args":["loc-arg"],' . - '"action-loc-key":"action-loc-key","loc-key":"loc-key","loc-args":["loc-arg"],' . - '"launch-image":"launch-image"}', + '{"title":"title","subtitle":"subtitle","body":"body","title-loc-key":"title-loc-key",' . + '"title-loc-args":["loc-arg"],"action-loc-key":"action-loc-key","loc-key":"loc-key",' . + '"loc-args":["loc-arg"],"launch-image":"launch-image"}', $alert->toJson() ); } diff --git a/tests/PayloadTest.php b/tests/PayloadTest.php index cd809ac..7b2549a 100644 --- a/tests/PayloadTest.php +++ b/tests/PayloadTest.php @@ -12,6 +12,7 @@ namespace Pushok\Tests; use PHPUnit\Framework\TestCase; +use Pushok\InvalidPayloadException; use Pushok\Payload; use Pushok\Payload\Alert; @@ -74,6 +75,31 @@ public function testSetCustomValue() $this->assertEquals('value', $payload->getCustomValue('key')); } + public function testSetCustomValueToRootKey() + { + $this->expectException(InvalidPayloadException::class); + $this->expectExceptionMessage("Key aps is reserved and can't be used for custom property."); + + Payload::create()->setCustomValue('aps', 'value'); + } + + public function testGetCustomValueOfNotExistingKey() + { + $this->expectException(InvalidPayloadException::class); + $this->expectExceptionMessage("Custom value with key 'notExistingKey' doesn't exist."); + + Payload::create() + ->setCustomValue('something', 'value') + ->getCustomValue('notExistingKey', 'value'); + } + + public function testSetPushType() + { + $payload = Payload::create()->setPushType('pushType'); + + $this->assertEquals('pushType', $payload->getPushType()); + } + public function testConvertToJSon() { diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 0027b03..0548aba 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -30,6 +30,13 @@ public function testGetApnsId() $this->assertEquals('123', $response->getApnsId()); } + public function testGetDeviceToken() + { + $response = new Response(200, 'headers', 'body', 'token'); + + $this->assertEquals('token', $response->getDeviceToken()); + } + public function testGetReasonPhrase() { $response = new Response(200, 'headers', 'body'); @@ -54,6 +61,13 @@ public function testGetErrorDescription() ); } + public function testGetErrorDescriptionForUnknownReason() + { + $response = new Response(400, 'headers', '{"reason": "UnknownReason"}'); + + $this->assertEquals('', $response->getErrorDescription()); + } + public function testGetError410Timestamp() { $response = new Response(410, 'headers', '{"reason": "Unregistered", "timestamp": 1514808000}');