@@ -30,17 +30,14 @@ public static function setUpBeforeClass()
30
30
{
31
31
self ::$ endpoints = [
32
32
'standard ' => getenv ('STANDARD_ENDPOINT ' ),
33
- 'GCM ' => getenv ('GCM_ENDPOINT ' ),
34
33
];
35
34
36
35
self ::$ keys = [
37
36
'standard ' => getenv ('USER_PUBLIC_KEY ' ),
38
- 'GCM ' => getenv ('GCM_USER_PUBLIC_KEY ' ),
39
37
];
40
38
41
39
self ::$ tokens = [
42
40
'standard ' => getenv ('USER_AUTH_TOKEN ' ),
43
- 'GCM ' => getenv ('GCM_USER_AUTH_TOKEN ' ),
44
41
];
45
42
}
46
43
@@ -51,10 +48,7 @@ public function setUp()
51
48
{
52
49
$ envs = [
53
50
'STANDARD_ENDPOINT ' ,
54
- 'GCM_ENDPOINT ' ,
55
51
'USER_PUBLIC_KEY ' ,
56
- 'GCM_API_KEY ' ,
57
- 'GCM_USER_PUBLIC_KEY ' ,
58
52
'USER_AUTH_TOKEN ' ,
59
53
'VAPID_PUBLIC_KEY ' ,
60
54
'VAPID_PRIVATE_KEY ' ,
@@ -66,7 +60,6 @@ public function setUp()
66
60
}
67
61
68
62
$ this ->webPush = new WebPush ([
69
- 'GCM ' => getenv ('GCM_API_KEY ' ),
70
63
'VAPID ' => [
71
64
'subject ' => 'https://github.com/Minishlink/web-push ' ,
72
65
'publicKey ' => getenv ('VAPID_PUBLIC_KEY ' ),
@@ -88,10 +81,7 @@ public function notificationProvider(): array
88
81
if (getenv ('CI ' )) return [];
89
82
90
83
return [
91
- [new Subscription (self ::$ endpoints ['standard ' ]), null ],
92
84
[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"} ' ],
95
85
];
96
86
}
97
87
@@ -104,9 +94,11 @@ public function notificationProvider(): array
104
94
*/
105
95
public function testSendNotification ($ subscription , $ payload )
106
96
{
107
- $ res = $ this ->webPush ->sendNotification ($ subscription , $ payload , true );
97
+ $ reports = $ this ->webPush ->sendNotification ($ subscription , $ payload , true );
108
98
109
- $ this ->assertTrue ($ res );
99
+ foreach ($ reports as $ report ) {
100
+ $ this ->assertTrue ($ report ->isSuccess ());
101
+ }
110
102
}
111
103
112
104
/**
@@ -124,9 +116,11 @@ public function testSendNotificationBatch()
124
116
$ this ->webPush ->sendNotification ($ notification [0 ], $ notification [1 ]);
125
117
}
126
118
127
- $ res = $ this ->webPush ->flush ($ batchSize );
119
+ $ reports = $ this ->webPush ->flush ($ batchSize );
128
120
129
- $ this ->assertTrue ($ res );
121
+ foreach ($ reports as $ report ) {
122
+ $ this ->assertTrue ($ report ->isSuccess ());
123
+ }
130
124
}
131
125
132
126
/**
@@ -160,30 +154,30 @@ public function testFlush() {
160
154
$ this ->webPush ->sendNotification ($ subscription );
161
155
$ this ->assertNotEmpty (iterator_to_array ($ this ->webPush ->flush ()));
162
156
163
- $ sub = Subscription::create ([
157
+ $ nonExistantSubscription = Subscription::create ([
164
158
'endpoint ' => 'https://fcm.googleapis.com/fcm/send/fCd2-8nXJhU:APA91bGi2uaqFXGft4qdolwyRUcUPCL1XV_jWy1tpCRqnu4sk7ojUpC5gnq1PTncbCdMq9RCVQIIFIU9BjzScvjrDqpsI7J-K_3xYW8xo1xSNCfge1RvJ6Xs8RGL_Sw7JtbCyG1_EVgWDc22on1r_jozD8vsFbB0Fg ' ,
165
159
'publicKey ' => 'BME-1ZSAv2AyGjENQTzrXDj6vSnhAIdKso4n3NDY0lsd1DUgEzBw7ARMKjrYAm7JmJBPsilV5CWNH0mVPyJEt0Q ' ,
166
160
'authToken ' => 'hUIGbmiypj9_EQea8AnCKA ' ,
167
161
'contentEncoding ' => 'aes128gcm ' ,
168
162
]);
169
163
170
164
// 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 ]));
174
168
175
169
/** @var \Minishlink\WebPush\MessageSentReport $report */
176
170
foreach ($ this ->webPush ->flush () as $ report ) {
177
171
$ 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 ());
180
174
$ this ->assertNotEmpty ($ report ->getReason ());
181
175
$ this ->assertNotFalse (filter_var ($ report ->getEndpoint (), FILTER_VALIDATE_URL ));
182
176
}
183
177
}
184
178
185
179
public function testFlushEmpty (): void {
186
- $ this ->webPush ->flush (300 );
180
+ $ this ->assertEmpty ( iterator_to_array ( $ this -> webPush ->flush (300 )) );
187
181
}
188
182
189
183
/**
@@ -197,50 +191,6 @@ public function testCount(): void {
197
191
$ this ->webPush ->sendNotification ($ subscription );
198
192
$ this ->webPush ->sendNotification ($ subscription );
199
193
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 ());
245
195
}
246
196
}
0 commit comments