|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | use GuzzleHttp\Psr7\Request;
|
8 |
| -use \Minishlink\WebPush\MessageSentReport; |
9 |
| -use \GuzzleHttp\Psr7\Response; |
| 8 | +use GuzzleHttp\Psr7\Response; |
| 9 | +use Minishlink\WebPush\MessageSentReport; |
| 10 | +use PHPUnit\Framework\TestCase; |
10 | 11 |
|
11 | 12 | /**
|
12 | 13 | * @covers \Minishlink\WebPush\MessageSentReport
|
13 | 14 | */
|
14 |
| -class MessageSentReportTest extends \PHPUnit\Framework\TestCase { |
| 15 | +class MessageSentReportTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @dataProvider generateReportsWithExpiration |
| 19 | + */ |
| 20 | + public function testIsSubscriptionExpired(MessageSentReport $report, bool $expected): void |
| 21 | + { |
| 22 | + $this->assertEquals($expected, $report->isSubscriptionExpired()); |
| 23 | + } |
15 | 24 |
|
16 |
| - /** |
17 |
| - * @dataProvider generateReportsWithExpiration |
18 |
| - */ |
19 |
| - public function testIsSubscriptionExpired(MessageSentReport $report, bool $expected): void { |
20 |
| - $this->assertEquals($expected, $report->isSubscriptionExpired()); |
21 |
| - } |
22 |
| - |
23 |
| - public function generateReportsWithExpiration(): array { |
24 |
| - $request = new Request('POST', 'https://example.com'); |
25 |
| - return [ |
26 |
| - [new MessageSentReport($request, new Response(404)), true], |
27 |
| - [new MessageSentReport($request, new Response(410)), true], |
28 |
| - [new MessageSentReport($request, new Response(500)), false], |
29 |
| - [new MessageSentReport($request, new Response(200)), false] |
30 |
| - ]; |
31 |
| - } |
| 25 | + public function generateReportsWithExpiration(): array |
| 26 | + { |
| 27 | + $request = new Request('POST', 'https://example.com'); |
| 28 | + return [ |
| 29 | + [new MessageSentReport($request, new Response(404)), true], |
| 30 | + [new MessageSentReport($request, new Response(410)), true], |
| 31 | + [new MessageSentReport($request, new Response(500)), false], |
| 32 | + [new MessageSentReport($request, new Response(200)), false] |
| 33 | + ]; |
| 34 | + } |
32 | 35 |
|
33 |
| - /** |
34 |
| - * @dataProvider generateReportsWithEndpoints |
35 |
| - */ |
36 |
| - public function testGetEndpoint(MessageSentReport $report, string $expected): void { |
37 |
| - $this->assertEquals($expected, $report->getEndpoint()); |
38 |
| - } |
| 36 | + /** |
| 37 | + * @dataProvider generateReportsWithEndpoints |
| 38 | + */ |
| 39 | + public function testGetEndpoint(MessageSentReport $report, string $expected): void |
| 40 | + { |
| 41 | + $this->assertEquals($expected, $report->getEndpoint()); |
| 42 | + } |
39 | 43 |
|
40 |
| - public function generateReportsWithEndpoints(): array { |
41 |
| - return [ |
42 |
| - [new MessageSentReport(new Request('POST', 'https://www.example.com')), 'https://www.example.com'], |
43 |
| - [new MessageSentReport(new Request('POST', 'https://m.example.com')), 'https://m.example.com'], |
44 |
| - [new MessageSentReport(new Request('POST', 'https://test.net')), 'https://test.net'], |
45 |
| - ]; |
46 |
| - } |
| 44 | + public function generateReportsWithEndpoints(): array |
| 45 | + { |
| 46 | + return [ |
| 47 | + [new MessageSentReport(new Request('POST', 'https://www.example.com')), 'https://www.example.com'], |
| 48 | + [new MessageSentReport(new Request('POST', 'https://m.example.com')), 'https://m.example.com'], |
| 49 | + [new MessageSentReport(new Request('POST', 'https://test.net')), 'https://test.net'], |
| 50 | + ]; |
| 51 | + } |
47 | 52 |
|
48 |
| - /** |
49 |
| - * @dataProvider generateReportsWithRequests |
50 |
| - */ |
51 |
| - public function testGetRequest(MessageSentReport $report, Request $expected): void { |
52 |
| - $this->assertEquals($expected, $report->getRequest()); |
53 |
| - } |
| 53 | + /** |
| 54 | + * @dataProvider generateReportsWithRequests |
| 55 | + */ |
| 56 | + public function testGetRequest(MessageSentReport $report, Request $expected): void |
| 57 | + { |
| 58 | + $this->assertEquals($expected, $report->getRequest()); |
| 59 | + } |
54 | 60 |
|
55 |
| - public function generateReportsWithRequests(): array { |
56 |
| - $r1 = new Request('POST', 'https://www.example.com'); |
57 |
| - $r2 = new Request('PUT', 'https://m.example.com'); |
58 |
| - $r3 = new Request('GET', 'https://test.net'); |
| 61 | + public function generateReportsWithRequests(): array |
| 62 | + { |
| 63 | + $r1 = new Request('POST', 'https://www.example.com'); |
| 64 | + $r2 = new Request('PUT', 'https://m.example.com'); |
| 65 | + $r3 = new Request('GET', 'https://test.net'); |
59 | 66 |
|
60 |
| - return [ |
61 |
| - [new MessageSentReport($r1), $r1], |
62 |
| - [new MessageSentReport($r2), $r2], |
63 |
| - [new MessageSentReport($r3), $r3], |
64 |
| - ]; |
65 |
| - } |
| 67 | + return [ |
| 68 | + [new MessageSentReport($r1), $r1], |
| 69 | + [new MessageSentReport($r2), $r2], |
| 70 | + [new MessageSentReport($r3), $r3], |
| 71 | + ]; |
| 72 | + } |
66 | 73 |
|
67 |
| - /** |
68 |
| - * @dataProvider generateReportsWithJson |
69 |
| - */ |
70 |
| - public function testJsonSerialize(MessageSentReport $report, string $json): void { |
71 |
| - $this->assertJsonStringEqualsJsonString($json, json_encode($report, JSON_THROW_ON_ERROR)); |
72 |
| - } |
| 74 | + /** |
| 75 | + * @dataProvider generateReportsWithJson |
| 76 | + */ |
| 77 | + public function testJsonSerialize(MessageSentReport $report, string $json): void |
| 78 | + { |
| 79 | + $this->assertJsonStringEqualsJsonString($json, json_encode($report, JSON_THROW_ON_ERROR)); |
| 80 | + } |
73 | 81 |
|
74 |
| - public function generateReportsWithJson(): array { |
75 |
| - $request1Body = json_encode(['title' => 'test', 'body' => 'blah', 'data' => []]); |
76 |
| - $request1 = new Request('POST', 'https://www.example.com', [], $request1Body); |
77 |
| - $response1 = new Response(200, [], 'test'); |
| 82 | + public function generateReportsWithJson(): array |
| 83 | + { |
| 84 | + $request1Body = json_encode(['title' => 'test', 'body' => 'blah', 'data' => []], JSON_THROW_ON_ERROR); |
| 85 | + $request1 = new Request('POST', 'https://www.example.com', [], $request1Body); |
| 86 | + $response1 = new Response(200, [], 'test'); |
78 | 87 |
|
79 |
| - $request2Body = ''; |
80 |
| - $request2 = new Request('POST', 'https://www.example.com', [], $request2Body); |
81 |
| - $response2 = new Response(410, [], 'Faield to do somthing', '1.1', 'Gone'); |
| 88 | + $request2Body = ''; |
| 89 | + $request2 = new Request('POST', 'https://www.example.com', [], $request2Body); |
| 90 | + $response2 = new Response(410, [], 'Failed to do something', '1.1', 'Gone'); |
82 | 91 |
|
83 |
| - return [ |
84 |
| - [ |
85 |
| - new MessageSentReport($request1, $response1), |
86 |
| - json_encode([ |
87 |
| - 'success' => true, |
88 |
| - 'expired' => false, |
89 |
| - 'reason' => 'OK', |
90 |
| - 'endpoint' => (string) $request1->getUri(), |
91 |
| - 'payload' => $request1Body, |
92 |
| - ], JSON_THROW_ON_ERROR) |
93 |
| - ], |
94 |
| - [ |
95 |
| - new MessageSentReport($request2, $response2, false, 'Gone'), |
96 |
| - json_encode([ |
97 |
| - 'success' => false, |
98 |
| - 'expired' => true, |
99 |
| - 'reason' => 'Gone', |
100 |
| - 'endpoint' => (string) $request2->getUri(), |
101 |
| - 'payload' => $request2Body, |
102 |
| - ], JSON_THROW_ON_ERROR) |
103 |
| - ] |
104 |
| - ]; |
105 |
| - } |
| 92 | + return [ |
| 93 | + [ |
| 94 | + new MessageSentReport($request1, $response1), |
| 95 | + json_encode([ |
| 96 | + 'success' => true, |
| 97 | + 'expired' => false, |
| 98 | + 'reason' => 'OK', |
| 99 | + 'endpoint' => (string) $request1->getUri(), |
| 100 | + 'payload' => $request1Body, |
| 101 | + ], JSON_THROW_ON_ERROR) |
| 102 | + ], |
| 103 | + [ |
| 104 | + new MessageSentReport($request2, $response2, false, 'Gone'), |
| 105 | + json_encode([ |
| 106 | + 'success' => false, |
| 107 | + 'expired' => true, |
| 108 | + 'reason' => 'Gone', |
| 109 | + 'endpoint' => (string) $request2->getUri(), |
| 110 | + 'payload' => $request2Body, |
| 111 | + ], JSON_THROW_ON_ERROR) |
| 112 | + ] |
| 113 | + ]; |
| 114 | + } |
106 | 115 |
|
107 |
| - /** |
108 |
| - * @dataProvider generateReportsWithSuccess |
109 |
| - */ |
110 |
| - public function testIsSuccess(MessageSentReport $report, bool $expected): void { |
111 |
| - $this->assertEquals($expected, $report->isSuccess()); |
112 |
| - } |
| 116 | + /** |
| 117 | + * @dataProvider generateReportsWithSuccess |
| 118 | + */ |
| 119 | + public function testIsSuccess(MessageSentReport $report, bool $expected): void |
| 120 | + { |
| 121 | + $this->assertEquals($expected, $report->isSuccess()); |
| 122 | + } |
113 | 123 |
|
114 |
| - public function generateReportsWithSuccess(): array { |
| 124 | + public function generateReportsWithSuccess(): array |
| 125 | + { |
115 | 126 | $request = new Request('POST', 'https://example.com');
|
116 |
| - return [ |
117 |
| - [new MessageSentReport($request), true], |
118 |
| - [new MessageSentReport($request, null, true), true], |
119 |
| - [new MessageSentReport($request, null, false), false], |
120 |
| - ]; |
121 |
| - } |
| 127 | + return [ |
| 128 | + [new MessageSentReport($request), true], |
| 129 | + [new MessageSentReport($request, null, true), true], |
| 130 | + [new MessageSentReport($request, null, false), false], |
| 131 | + ]; |
| 132 | + } |
122 | 133 | }
|
0 commit comments