Skip to content

Commit 0dddeca

Browse files
authored
Merge pull request #165 from tcousin-ext/add_status_code_to_response_content
add status code to response content of send request method
2 parents 17ee48b + af7be4c commit 0dddeca

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

src/Notifications.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getOne(string $id): array
4343
* @param int $offset Results offset (results are sorted by ID)
4444
* @param int $kind Kind of notifications returned. Default (not set) is all notification types
4545
*/
46-
public function getAll(int $limit = null, int $offset = null/*, int $kind = null */): array
46+
public function getAll(int $limit = null, int $offset = null/* , int $kind = null */): array
4747
{
4848
if (func_num_args() > 2 && !is_int(func_get_arg(2))) {
4949
trigger_deprecation('norkunas/onesignal-php-api', '2.1.0', 'Method %s() will have a third `int $kind` argument. Not defining it or passing a non integer value is deprecated.', __METHOD__);

src/OneSignal.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function sendRequest(RequestInterface $request): array
7777
throw new JsonException(sprintf('JSON content was expected to decode to an array, %s returned.', gettype($content)));
7878
}
7979

80+
if (!isset($content['_status_code'])) {
81+
$content['_status_code'] = $response->getStatusCode();
82+
}
83+
8084
return $content;
8185
}
8286

tests/AppsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testGetOne(): void
5353
'safari_icon_256_256' => 'http://onesignal.com/safari_packages/e4e87830-b954-11e3-811d-f3b376925f15/128x128@2x.png',
5454
'site_name' => 'The URL to your website for Web Push',
5555
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
56+
'_status_code' => 200,
5657
], $responseData);
5758
}
5859

@@ -75,6 +76,7 @@ public function testGetOneNonExisting(): void
7576

7677
self::assertSame([
7778
'errors' => 'Couldn\'t find app with id = a',
79+
'_status_code' => 404,
7880
], $responseData);
7981
}
8082

@@ -148,6 +150,7 @@ public function testGetAll(): void
148150
'site_name' => 'The URL to your website for Web Push',
149151
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
150152
],
153+
'_status_code' => 200,
151154
], $responseData);
152155
}
153156

@@ -175,6 +178,7 @@ public function testGetWithWrongUserAuthKey(): void
175178
'reference' => [
176179
'https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key',
177180
],
181+
'_status_code' => 400,
178182
], $responseData);
179183
}
180184

@@ -227,6 +231,7 @@ public function testAdd(): void
227231
'safari_icon_256_256' => 'http://onesignal.com/safari_packages/e4e87830-b954-11e3-811d-f3b376925f15/128x128@2x.png',
228232
'site_name' => 'The URL to your website for Web Push',
229233
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
234+
'_status_code' => 200,
230235
], $responseData);
231236
}
232237

@@ -251,6 +256,7 @@ public function testAddWithEmptyName(): void
251256
'errors' => [
252257
'Name Enter an app name',
253258
],
259+
'_status_code' => 400,
254260
], $responseData);
255261
}
256262

@@ -303,6 +309,7 @@ public function testUpdate(): void
303309
'safari_icon_256_256' => 'http://onesignal.com/safari_packages/e4e87830-b954-11e3-811d-f3b376925f15/128x128@2x.png',
304310
'site_name' => 'The URL to your website for Web Push',
305311
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
312+
'_status_code' => 200,
306313
], $responseData);
307314
}
308315

@@ -328,6 +335,7 @@ public function testUpdateNotExisting(): void
328335
self::assertSame([
329336
'status' => 404,
330337
'error' => 'Not Found',
338+
'_status_code' => 404,
331339
], $responseData);
332340
}
333341

@@ -379,6 +387,7 @@ public function testCreateSegment(): void
379387
self::assertSame([
380388
'success' => true,
381389
'id' => '7ed2887d-bd24-4a81-8220-4b256a08ab19',
390+
'_status_code' => 200,
382391
], $responseData);
383392
}
384393

@@ -408,6 +417,7 @@ public function testCreateSegmentWithExistingId(): void
408417
self::assertSame([
409418
'success' => false,
410419
'errors' => ['Segment with the given id already exists.'],
420+
'_status_code' => 409,
411421
], $responseData);
412422
}
413423

@@ -436,6 +446,7 @@ public function testCreateSegmentWithEmptyName(): void
436446
self::assertSame([
437447
'success' => false,
438448
'errors' => ['name is required'],
449+
'_status_code' => 400,
439450
], $responseData);
440451
}
441452

@@ -483,6 +494,7 @@ public function testOutcomes(): void
483494
'aggregation' => 'sum',
484495
],
485496
],
497+
'_status_code' => 200,
486498
], $responseData);
487499
}
488500
}

tests/DevicesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testGetOne(): void
4444
'invalid_identifier' => false,
4545
'badge_count' => 0,
4646
'external_user_id' => null,
47+
'_status_code' => 200,
4748
], $responseData);
4849
}
4950

@@ -64,6 +65,7 @@ public function testGetOneNonExisting(): void
6465

6566
self::assertSame([
6667
'errors' => ['No user with this id found'],
68+
'_status_code' => 400,
6769
], $responseData);
6870
}
6971

@@ -108,6 +110,7 @@ public function testGetAll(): void
108110
'external_user_id' => null,
109111
],
110112
],
113+
'_status_code' => 200,
111114
], $responseData);
112115
}
113116

@@ -140,6 +143,7 @@ public function testAdd(): void
140143
self::assertSame([
141144
'success' => true,
142145
'id' => 'ffffb794-ba37-11e3-8077-031d62f86ebf',
146+
'_status_code' => 200,
143147
], $responseData);
144148
}
145149

@@ -170,6 +174,7 @@ public function testUpdate(): void
170174

171175
self::assertSame([
172176
'success' => true,
177+
'_status_code' => 200,
173178
], $responseData);
174179
}
175180

@@ -192,6 +197,7 @@ public function testDelete(): void
192197

193198
self::assertSame([
194199
'success' => true,
200+
'_status_code' => 200,
195201
], $responseData);
196202
}
197203

@@ -219,6 +225,7 @@ public function testOnSession(): void
219225

220226
self::assertSame([
221227
'success' => true,
228+
'_status_code' => 200,
222229
], $responseData);
223230
}
224231

@@ -249,6 +256,7 @@ public function testOnPurchase(): void
249256

250257
self::assertSame([
251258
'success' => true,
259+
'_status_code' => 200,
252260
], $responseData);
253261
}
254262

@@ -274,6 +282,7 @@ public function testOnFocus(): void
274282

275283
self::assertSame([
276284
'success' => true,
285+
'_status_code' => 200,
277286
], $responseData);
278287
}
279288

@@ -296,6 +305,7 @@ public function testCsvExport(): void
296305

297306
self::assertSame([
298307
'csv_file_url' => 'https://onesignal.com/csv_exports/b2f7f966-d8cc-11e4-bed1-df8f05be55ba/users_184948440ec0e334728e87228011ff41_2015-11-10.csv.gz',
308+
'_status_code' => 200,
299309
], $responseData);
300310
}
301311

@@ -320,6 +330,7 @@ public function testEditTags(): void
320330

321331
self::assertSame([
322332
'success' => true,
333+
'_status_code' => 200,
323334
], $responseData);
324335
}
325336
}

tests/NotificationsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function testGetOne(): void
5959
'errored' => 0,
6060
],
6161
],
62+
'_status_code' => 200,
6263
], $responseData);
6364
}
6465

@@ -199,6 +200,7 @@ public function testGetAll(): void
199200
],
200201
],
201202
],
203+
'_status_code' => 200,
202204
], $responseData);
203205
}
204206

@@ -245,6 +247,7 @@ public function testAdd(): void
245247
self::assertSame([
246248
'id' => '458dcec4-cf53-11e3-add2-000c2940e62c',
247249
'recipients' => 3,
250+
'_status_code' => 200,
248251
], $responseData);
249252
}
250253

@@ -267,6 +270,7 @@ public function testOpen(): void
267270

268271
self::assertSame([
269272
'success' => true,
273+
'_status_code' => 200,
270274
], $responseData);
271275
}
272276

@@ -289,6 +293,7 @@ public function testCancel(): void
289293

290294
self::assertSame([
291295
'success' => true,
296+
'_status_code' => 200,
292297
], $responseData);
293298
}
294299

@@ -315,6 +320,7 @@ public function testHistory(): void
315320
self::assertSame([
316321
'success' => true,
317322
'destination_url' => 'https://onesignal-aws-link.com',
323+
'_status_code' => 200,
318324
], $responseData);
319325
}
320326
}

tests/OneSignalTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testSendRequest(): void
3636
['id' => 1],
3737
['id' => 2],
3838
],
39+
'_status_code' => 200,
3940
], $responseData);
4041
}
4142

0 commit comments

Comments
 (0)