Skip to content

Commit 2660727

Browse files
committed
style(tests): apply code formatting
1 parent 9932ad5 commit 2660727

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

tests/api_test.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44

55
require_once __DIR__ . '/framework.php';
66

7-
describe('Route Matching', function () {
8-
test('authorize route matches GET requests with version', function () {
7+
describe('Route Matching', static function () {
8+
test('authorize route matches GET requests with version', static function () {
99
$pattern = '/^GET:\/api\/v\d+\/authorize/';
1010
assertTrue(preg_match($pattern, 'GET:/api/v1/authorize') === 1);
1111
assertTrue(preg_match($pattern, 'GET:/api/v2/authorize') === 1);
1212
assertTrue(preg_match($pattern, 'GET:/api/v10/authorize') === 1);
1313
});
1414

15-
test('authorize route does not match POST requests', function () {
15+
test('authorize route does not match POST requests', static function () {
1616
$pattern = '/^GET:\/api\/v\d+\/authorize/';
1717
assertFalse(preg_match($pattern, 'POST:/api/v1/authorize') === 1);
1818
});
1919

20-
test('notify route matches POST requests with version', function () {
20+
test('notify route matches POST requests with version', static function () {
2121
$pattern = '/^POST:\/api\/v\d+\/notify/';
2222
assertTrue(preg_match($pattern, 'POST:/api/v1/notify') === 1);
2323
assertTrue(preg_match($pattern, 'POST:/api/v2/notify') === 1);
2424
});
2525

26-
test('notify route does not match GET requests', function () {
26+
test('notify route does not match GET requests', static function () {
2727
$pattern = '/^POST:\/api\/v\d+\/notify/';
2828
assertFalse(preg_match($pattern, 'GET:/api/v1/notify') === 1);
2929
});
3030
});
3131

32-
describe('Authorize Response Structure', function () {
33-
test('success response has correct structure', function () {
32+
describe('Authorize Response Structure', static function () {
33+
test('success response has correct structure', static function () {
3434
$body = '{ "status" : "success", "data" : { "authorization" : true } }';
3535
$json = json_decode($body, true);
3636

3737
assertEquals('success', $json['status']);
3838
assertTrue($json['data']['authorization']);
3939
});
4040

41-
test('fail response has correct structure', function () {
41+
test('fail response has correct structure', static function () {
4242
$body = '{ "status" : "fail", "data" : { "authorization" : false } }';
4343
$json = json_decode($body, true);
4444

@@ -47,38 +47,46 @@
4747
});
4848
});
4949

50-
describe('Notify Response Structure', function () {
51-
test('success response is empty with 204', function () {
50+
describe('Notify Response Structure', static function () {
51+
test('success response is empty with 204', static function () {
5252
$body = '';
5353
assertEquals('', $body);
5454
});
5555

56-
test('error response has correct structure', function () {
56+
test('error response has correct structure', static function () {
5757
$body = '{ "status" : "error", "message": "The service is not available, try again later" }';
58-
$json = json_decode($body, true);
58+
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
5959

6060
assertEquals('error', $json['status']);
6161
assertContains('not available', $json['message']);
6262
});
6363
});
6464

65-
describe('Not Found Response', function () {
66-
test('not found response includes route in message', function () {
65+
describe('Not Found Response', static function () {
66+
test('not found response includes route in message', static function () {
6767
$route = 'GET:/api/v1/unknown';
6868
$body = sprintf('{ "status" : "fail", "data" : { "message": "Route \'%s\' not found" } }', $route);
69-
$json = json_decode($body, true);
69+
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
7070

7171
assertEquals('fail', $json['status']);
7272
assertContains($route, $json['data']['message']);
7373
});
7474
});
7575

76-
describe('HTTP Status Cat Header', function () {
77-
test('generates correct cat URL for status codes', function () {
78-
$codes = [200, 204, 403, 404, 500, 504];
79-
foreach ($codes as $code) {
76+
describe('HTTP Status Cat Header', static function () {
77+
test('generates correct cat URL for status codes', static function () {
78+
foreach (
79+
[
80+
200,
81+
204,
82+
403,
83+
404,
84+
500,
85+
504,
86+
] as $code
87+
) {
8088
$header = sprintf('https://http.cat/status/%s', $code);
81-
assertContains((string)$code, $header);
89+
assertContains((string) $code, $header);
8290
assertContains('http.cat', $header);
8391
}
8492
});

0 commit comments

Comments
 (0)