|
4 | 4 |
|
5 | 5 | require_once __DIR__ . '/framework.php'; |
6 | 6 |
|
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 () { |
9 | 9 | $pattern = '/^GET:\/api\/v\d+\/authorize/'; |
10 | 10 | assertTrue(preg_match($pattern, 'GET:/api/v1/authorize') === 1); |
11 | 11 | assertTrue(preg_match($pattern, 'GET:/api/v2/authorize') === 1); |
12 | 12 | assertTrue(preg_match($pattern, 'GET:/api/v10/authorize') === 1); |
13 | 13 | }); |
14 | 14 |
|
15 | | - test('authorize route does not match POST requests', function () { |
| 15 | + test('authorize route does not match POST requests', static function () { |
16 | 16 | $pattern = '/^GET:\/api\/v\d+\/authorize/'; |
17 | 17 | assertFalse(preg_match($pattern, 'POST:/api/v1/authorize') === 1); |
18 | 18 | }); |
19 | 19 |
|
20 | | - test('notify route matches POST requests with version', function () { |
| 20 | + test('notify route matches POST requests with version', static function () { |
21 | 21 | $pattern = '/^POST:\/api\/v\d+\/notify/'; |
22 | 22 | assertTrue(preg_match($pattern, 'POST:/api/v1/notify') === 1); |
23 | 23 | assertTrue(preg_match($pattern, 'POST:/api/v2/notify') === 1); |
24 | 24 | }); |
25 | 25 |
|
26 | | - test('notify route does not match GET requests', function () { |
| 26 | + test('notify route does not match GET requests', static function () { |
27 | 27 | $pattern = '/^POST:\/api\/v\d+\/notify/'; |
28 | 28 | assertFalse(preg_match($pattern, 'GET:/api/v1/notify') === 1); |
29 | 29 | }); |
30 | 30 | }); |
31 | 31 |
|
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 () { |
34 | 34 | $body = '{ "status" : "success", "data" : { "authorization" : true } }'; |
35 | 35 | $json = json_decode($body, true); |
36 | 36 |
|
37 | 37 | assertEquals('success', $json['status']); |
38 | 38 | assertTrue($json['data']['authorization']); |
39 | 39 | }); |
40 | 40 |
|
41 | | - test('fail response has correct structure', function () { |
| 41 | + test('fail response has correct structure', static function () { |
42 | 42 | $body = '{ "status" : "fail", "data" : { "authorization" : false } }'; |
43 | 43 | $json = json_decode($body, true); |
44 | 44 |
|
|
47 | 47 | }); |
48 | 48 | }); |
49 | 49 |
|
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 () { |
52 | 52 | $body = ''; |
53 | 53 | assertEquals('', $body); |
54 | 54 | }); |
55 | 55 |
|
56 | | - test('error response has correct structure', function () { |
| 56 | + test('error response has correct structure', static function () { |
57 | 57 | $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); |
59 | 59 |
|
60 | 60 | assertEquals('error', $json['status']); |
61 | 61 | assertContains('not available', $json['message']); |
62 | 62 | }); |
63 | 63 | }); |
64 | 64 |
|
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 () { |
67 | 67 | $route = 'GET:/api/v1/unknown'; |
68 | 68 | $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); |
70 | 70 |
|
71 | 71 | assertEquals('fail', $json['status']); |
72 | 72 | assertContains($route, $json['data']['message']); |
73 | 73 | }); |
74 | 74 | }); |
75 | 75 |
|
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 | + ) { |
80 | 88 | $header = sprintf('https://http.cat/status/%s', $code); |
81 | | - assertContains((string)$code, $header); |
| 89 | + assertContains((string) $code, $header); |
82 | 90 | assertContains('http.cat', $header); |
83 | 91 | } |
84 | 92 | }); |
|
0 commit comments