11<?php
22
3- namespace Tests \ServerNotifications ;
3+ namespace Tests \Unit \ ServerNotifications ;
44
55use Imdhemy \AppStore \ServerNotifications \ServerNotification ;
6- use Imdhemy \Purchases \Contracts \ServerNotificationContract ;
76use Imdhemy \Purchases \Contracts \SubscriptionContract ;
87use Imdhemy \Purchases \ServerNotifications \AppStoreServerNotification ;
98use Imdhemy \Purchases \ValueObjects \Time ;
9+ use JsonException ;
1010use Tests \TestCase ;
1111
1212class AppStoreServerNotificationTest extends TestCase
1313{
1414 /**
1515 * @var AppStoreServerNotification
1616 */
17- private $ appStoreServerNotification ;
17+ private AppStoreServerNotification $ appStoreServerNotification ;
18+
19+ /**
20+ * @var array
21+ */
22+ private array $ serverNotificationBody ;
1823
1924 /**
2025 * @inheritDoc
26+ * @throws JsonException
2127 */
2228 protected function setUp (): void
2329 {
2430 parent ::setUp ();
2531 $ path = $ this ->testAssetPath ('appstore-server-notification.json ' );
26- $ serverNotificationBody = json_decode (file_get_contents ($ path ), true );
32+ $ this -> serverNotificationBody = json_decode (file_get_contents ($ path ), true , 512 , JSON_THROW_ON_ERROR );
2733
28- $ serverNotification = ServerNotification::fromArray ($ serverNotificationBody );
34+ $ serverNotification = ServerNotification::fromArray ($ this -> serverNotificationBody );
2935 $ this ->appStoreServerNotification = new AppStoreServerNotification ($ serverNotification );
3036 }
3137
3238 /**
3339 * @test
3440 */
35- public function test_constructor ()
36- {
37- $ this ->assertInstanceOf (ServerNotificationContract::class, $ this ->appStoreServerNotification );
38- }
39-
40- /**
41- * @test
42- */
43- public function test_get_notification_type ()
41+ public function get_notification_type (): void
4442 {
4543 $ this ->assertEquals (
4644 ServerNotification::DID_CHANGE_RENEWAL_STATUS ,
@@ -51,15 +49,17 @@ public function test_get_notification_type()
5149 /**
5250 * @test
5351 */
54- public function test_get_subscription ()
52+ public function get_subscription (): void
5553 {
56- $ this ->assertInstanceOf (SubscriptionContract::class, $ this ->appStoreServerNotification ->getSubscription ());
54+ $ subscription = $ this ->appStoreServerNotification ->getSubscription ();
55+
56+ $ this ->assertEquals (SubscriptionContract::PROVIDER_APP_STORE , $ subscription ->getProvider ());
5757 }
5858
5959 /**
6060 * @test
6161 */
62- public function test_get_change_renewal_status_data ()
62+ public function get_change_renewal_status_data (): void
6363 {
6464 $ isAutoRenewal = $ this ->appStoreServerNotification ->isAutoRenewal ();
6565 $ changeDate = $ this ->appStoreServerNotification ->getAutoRenewStatusChangeDate ();
@@ -71,9 +71,23 @@ public function test_get_change_renewal_status_data()
7171 /**
7272 * @test
7373 */
74- public function test_get_bundle ()
74+ public function get_bundle (): void
7575 {
76- $ this ->assertNotNull ($ this ->appStoreServerNotification ->getBundle ());
76+ $ this ->assertEquals (
77+ 'com.twigano.fashion ' ,
78+ $ this ->appStoreServerNotification ->getBundle ()
79+ );
80+ }
81+
82+ /**
83+ * @test
84+ */
85+ public function get_payload (): void
86+ {
87+ $ this ->assertEquals (
88+ $ this ->serverNotificationBody ,
89+ $ this ->appStoreServerNotification ->getPayload ()
90+ );
7791 }
7892
7993 /**
0 commit comments