Skip to content

Commit

Permalink
Merge pull request #165 from tcousin-ext/add_status_code_to_response_…
Browse files Browse the repository at this point in the history
…content

add status code to response content of send request method
  • Loading branch information
norkunas authored May 24, 2022
2 parents 17ee48b + af7be4c commit 0dddeca
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getOne(string $id): array
* @param int $offset Results offset (results are sorted by ID)
* @param int $kind Kind of notifications returned. Default (not set) is all notification types
*/
public function getAll(int $limit = null, int $offset = null/*, int $kind = null */): array
public function getAll(int $limit = null, int $offset = null/* , int $kind = null */): array
{
if (func_num_args() > 2 && !is_int(func_get_arg(2))) {
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__);
Expand Down
4 changes: 4 additions & 0 deletions src/OneSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function sendRequest(RequestInterface $request): array
throw new JsonException(sprintf('JSON content was expected to decode to an array, %s returned.', gettype($content)));
}

if (!isset($content['_status_code'])) {
$content['_status_code'] = $response->getStatusCode();
}

return $content;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/AppsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testGetOne(): void
'safari_icon_256_256' => 'http://onesignal.com/safari_packages/e4e87830-b954-11e3-811d-f3b376925f15/128x128@2x.png',
'site_name' => 'The URL to your website for Web Push',
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'errors' => 'Couldn\'t find app with id = a',
'_status_code' => 404,
], $responseData);
}

Expand Down Expand Up @@ -148,6 +150,7 @@ public function testGetAll(): void
'site_name' => 'The URL to your website for Web Push',
'basic_auth_key' => 'NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj',
],
'_status_code' => 200,
], $responseData);
}

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

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

Expand All @@ -251,6 +256,7 @@ public function testAddWithEmptyName(): void
'errors' => [
'Name Enter an app name',
],
'_status_code' => 400,
], $responseData);
}

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

Expand All @@ -328,6 +335,7 @@ public function testUpdateNotExisting(): void
self::assertSame([
'status' => 404,
'error' => 'Not Found',
'_status_code' => 404,
], $responseData);
}

Expand Down Expand Up @@ -379,6 +387,7 @@ public function testCreateSegment(): void
self::assertSame([
'success' => true,
'id' => '7ed2887d-bd24-4a81-8220-4b256a08ab19',
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -408,6 +417,7 @@ public function testCreateSegmentWithExistingId(): void
self::assertSame([
'success' => false,
'errors' => ['Segment with the given id already exists.'],
'_status_code' => 409,
], $responseData);
}

Expand Down Expand Up @@ -436,6 +446,7 @@ public function testCreateSegmentWithEmptyName(): void
self::assertSame([
'success' => false,
'errors' => ['name is required'],
'_status_code' => 400,
], $responseData);
}

Expand Down Expand Up @@ -483,6 +494,7 @@ public function testOutcomes(): void
'aggregation' => 'sum',
],
],
'_status_code' => 200,
], $responseData);
}
}
11 changes: 11 additions & 0 deletions tests/DevicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testGetOne(): void
'invalid_identifier' => false,
'badge_count' => 0,
'external_user_id' => null,
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'errors' => ['No user with this id found'],
'_status_code' => 400,
], $responseData);
}

Expand Down Expand Up @@ -108,6 +110,7 @@ public function testGetAll(): void
'external_user_id' => null,
],
],
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -140,6 +143,7 @@ public function testAdd(): void
self::assertSame([
'success' => true,
'id' => 'ffffb794-ba37-11e3-8077-031d62f86ebf',
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -170,6 +174,7 @@ public function testUpdate(): void

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -219,6 +225,7 @@ public function testOnSession(): void

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -249,6 +256,7 @@ public function testOnPurchase(): void

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

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

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

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

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}
}
6 changes: 6 additions & 0 deletions tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function testGetOne(): void
'errored' => 0,
],
],
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -199,6 +200,7 @@ public function testGetAll(): void
],
],
],
'_status_code' => 200,
], $responseData);
}

Expand Down Expand Up @@ -245,6 +247,7 @@ public function testAdd(): void
self::assertSame([
'id' => '458dcec4-cf53-11e3-add2-000c2940e62c',
'recipients' => 3,
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

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

self::assertSame([
'success' => true,
'_status_code' => 200,
], $responseData);
}

Expand All @@ -315,6 +320,7 @@ public function testHistory(): void
self::assertSame([
'success' => true,
'destination_url' => 'https://onesignal-aws-link.com',
'_status_code' => 200,
], $responseData);
}
}
1 change: 1 addition & 0 deletions tests/OneSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testSendRequest(): void
['id' => 1],
['id' => 2],
],
'_status_code' => 200,
], $responseData);
}

Expand Down

0 comments on commit 0dddeca

Please sign in to comment.