@@ -30,17 +30,14 @@ public static function setUpBeforeClass()
3030 {
3131 self ::$ endpoints = [
3232 'standard ' => getenv ('STANDARD_ENDPOINT ' ),
33- 'GCM ' => getenv ('GCM_ENDPOINT ' ),
3433 ];
3534
3635 self ::$ keys = [
3736 'standard ' => getenv ('USER_PUBLIC_KEY ' ),
38- 'GCM ' => getenv ('GCM_USER_PUBLIC_KEY ' ),
3937 ];
4038
4139 self ::$ tokens = [
4240 'standard ' => getenv ('USER_AUTH_TOKEN ' ),
43- 'GCM ' => getenv ('GCM_USER_AUTH_TOKEN ' ),
4441 ];
4542 }
4643
@@ -51,10 +48,7 @@ public function setUp()
5148 {
5249 $ envs = [
5350 'STANDARD_ENDPOINT ' ,
54- 'GCM_ENDPOINT ' ,
5551 'USER_PUBLIC_KEY ' ,
56- 'GCM_API_KEY ' ,
57- 'GCM_USER_PUBLIC_KEY ' ,
5852 'USER_AUTH_TOKEN ' ,
5953 'VAPID_PUBLIC_KEY ' ,
6054 'VAPID_PRIVATE_KEY ' ,
@@ -66,7 +60,6 @@ public function setUp()
6660 }
6761
6862 $ this ->webPush = new WebPush ([
69- 'GCM ' => getenv ('GCM_API_KEY ' ),
7063 'VAPID ' => [
7164 'subject ' => 'https://github.com/Minishlink/web-push ' ,
7265 'publicKey ' => getenv ('VAPID_PUBLIC_KEY ' ),
@@ -88,10 +81,7 @@ public function notificationProvider(): array
8881 if (getenv ('CI ' )) return [];
8982
9083 return [
91- [new Subscription (self ::$ endpoints ['standard ' ]), null ],
9284 [new Subscription (self ::$ endpoints ['standard ' ], self ::$ keys ['standard ' ], self ::$ tokens ['standard ' ]), '{"message":"Comment ça va ?","tag":"general"} ' ],
93- [new Subscription (self ::$ endpoints ['GCM ' ]), null ],
94- [new Subscription (self ::$ endpoints ['GCM ' ], self ::$ keys ['GCM ' ], self ::$ tokens ['GCM ' ]), '{"message":"Comment ça va ?","tag":"general"} ' ],
9585 ];
9686 }
9787
@@ -104,9 +94,11 @@ public function notificationProvider(): array
10494 */
10595 public function testSendNotification ($ subscription , $ payload )
10696 {
107- $ res = $ this ->webPush ->sendNotification ($ subscription , $ payload , true );
97+ $ reports = $ this ->webPush ->sendNotification ($ subscription , $ payload , true );
10898
109- $ this ->assertTrue ($ res );
99+ foreach ($ reports as $ report ) {
100+ $ this ->assertTrue ($ report ->isSuccess ());
101+ }
110102 }
111103
112104 /**
@@ -124,9 +116,11 @@ public function testSendNotificationBatch()
124116 $ this ->webPush ->sendNotification ($ notification [0 ], $ notification [1 ]);
125117 }
126118
127- $ res = $ this ->webPush ->flush ($ batchSize );
119+ $ reports = $ this ->webPush ->flush ($ batchSize );
128120
129- $ this ->assertTrue ($ res );
121+ foreach ($ reports as $ report ) {
122+ $ this ->assertTrue ($ report ->isSuccess ());
123+ }
130124 }
131125
132126 /**
@@ -160,30 +154,30 @@ public function testFlush() {
160154 $ this ->webPush ->sendNotification ($ subscription );
161155 $ this ->assertNotEmpty (iterator_to_array ($ this ->webPush ->flush ()));
162156
163- $ sub = Subscription::create ([
157+ $ nonExistantSubscription = Subscription::create ([
164158 'endpoint ' => 'https://fcm.googleapis.com/fcm/send/fCd2-8nXJhU:APA91bGi2uaqFXGft4qdolwyRUcUPCL1XV_jWy1tpCRqnu4sk7ojUpC5gnq1PTncbCdMq9RCVQIIFIU9BjzScvjrDqpsI7J-K_3xYW8xo1xSNCfge1RvJ6Xs8RGL_Sw7JtbCyG1_EVgWDc22on1r_jozD8vsFbB0Fg ' ,
165159 'publicKey ' => 'BME-1ZSAv2AyGjENQTzrXDj6vSnhAIdKso4n3NDY0lsd1DUgEzBw7ARMKjrYAm7JmJBPsilV5CWNH0mVPyJEt0Q ' ,
166160 'authToken ' => 'hUIGbmiypj9_EQea8AnCKA ' ,
167161 'contentEncoding ' => 'aes128gcm ' ,
168162 ]);
169163
170164 // test multiple requests
171- $ this ->webPush ->sendNotification ($ sub , json_encode (['test ' => 1 ]));
172- $ this ->webPush ->sendNotification ($ sub , json_encode (['test ' => 2 ]));
173- $ this ->webPush ->sendNotification ($ sub , json_encode (['test ' => 3 ]));
165+ $ this ->webPush ->sendNotification ($ nonExistantSubscription , json_encode (['test ' => 1 ]));
166+ $ this ->webPush ->sendNotification ($ nonExistantSubscription , json_encode (['test ' => 2 ]));
167+ $ this ->webPush ->sendNotification ($ nonExistantSubscription , json_encode (['test ' => 3 ]));
174168
175169 /** @var \Minishlink\WebPush\MessageSentReport $report */
176170 foreach ($ this ->webPush ->flush () as $ report ) {
177171 $ this ->assertFalse ($ report ->isSuccess ());
178- $ this ->assertFalse ($ report ->isSubscriptionExpired ());
179- $ this ->assertEquals (404 , $ report ->getResponse ()->getStatusCode ());
172+ $ this ->assertTrue ($ report ->isSubscriptionExpired ());
173+ $ this ->assertEquals (410 , $ report ->getResponse ()->getStatusCode ());
180174 $ this ->assertNotEmpty ($ report ->getReason ());
181175 $ this ->assertNotFalse (filter_var ($ report ->getEndpoint (), FILTER_VALIDATE_URL ));
182176 }
183177 }
184178
185179 public function testFlushEmpty (): void {
186- $ this ->webPush ->flush (300 );
180+ $ this ->assertEmpty ( iterator_to_array ( $ this -> webPush ->flush (300 )) );
187181 }
188182
189183 /**
@@ -197,50 +191,6 @@ public function testCount(): void {
197191 $ this ->webPush ->sendNotification ($ subscription );
198192 $ this ->webPush ->sendNotification ($ subscription );
199193
200- $ this ->assertCount (4 , $ this ->webPush );
201- }
202-
203- /**
204- * @throws ErrorException
205- */
206- public function testSendGCMNotificationWithoutGCMApiKey ()
207- {
208- if (substr (self ::$ endpoints ['GCM ' ], 0 , strlen (WebPush::GCM_URL )) !== WebPush::GCM_URL ) {
209- $ this ->markTestSkipped ("The provided GCM URL is not a GCM URL, but probably a FCM URL. " );
210- }
211-
212- $ webPush = new WebPush ();
213- $ this ->expectException ('ErrorException ' );
214- $ this ->expectExceptionMessage ('No GCM API Key specified. ' );
215-
216- $ subscription = new Subscription (self ::$ endpoints ['GCM ' ]);
217- $ webPush ->sendNotification ($ subscription , null , true );
218- }
219-
220- /**
221- * @throws ErrorException
222- */
223- public function testSendGCMNotificationWithWrongGCMApiKey ()
224- {
225- if (substr (self ::$ endpoints ['GCM ' ], 0 , strlen (WebPush::GCM_URL )) !== WebPush::GCM_URL ) {
226- $ this ->markTestSkipped ("The provided GCM URL is not a GCM URL, but probably a FCM URL. " );
227- }
228-
229- $ webPush = new WebPush (['GCM ' => 'bar ' ]);
230-
231- $ subscription = new Subscription (self ::$ endpoints ['GCM ' ]);
232- $ res = $ webPush ->sendNotification ($ subscription , null , true );
233-
234- $ this ->assertTrue (is_array ($ res )); // there has been an error
235- $ this ->assertArrayHasKey ('success ' , $ res );
236- $ this ->assertFalse ($ res ['success ' ]);
237-
238- $ this ->assertArrayHasKey ('statusCode ' , $ res );
239- $ this ->assertEquals (400 , $ res ['statusCode ' ]);
240-
241- $ this ->assertArrayHasKey ('headers ' , $ res );
242-
243- $ this ->assertArrayHasKey ('endpoint ' , $ res );
244- $ this ->assertEquals (self ::$ endpoints ['GCM ' ], $ res ['endpoint ' ]);
194+ $ this ->assertEquals (4 , $ this ->webPush ->countPendingNotifications ());
245195 }
246196}
0 commit comments