|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Tests\integration; |
|
6
|
|
|
|
|
7
|
|
|
class NoteTest extends BaseTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
private static int $id; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Test Get All Notes. |
|
13
|
|
|
*/ |
|
14
|
|
|
public function testGetNotes(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$response = $this->runApp('GET', '/api/v1/notes'); |
|
17
|
|
|
|
|
18
|
|
|
$result = (string) $response->getBody(); |
|
19
|
|
|
$value = json_encode(json_decode($result)); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
22
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
23
|
|
|
$this->assertStringContainsString('success', $result); |
|
24
|
|
|
$this->assertStringContainsString('id', $result); |
|
25
|
|
|
$this->assertStringContainsString('name', $result); |
|
26
|
|
|
$this->assertStringContainsString('description', $result); |
|
27
|
|
|
$this->assertMatchesRegularExpression('{"code":200,"status":"success"}', (string) $value); |
|
28
|
|
|
$this->assertMatchesRegularExpression('{"name":"[A-Za-z0-9_. ]+","description":"[A-Za-z0-9_. ]+"}', (string) $value); |
|
29
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Test Get Notes By Page. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testGetNotesByPage(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$response = $this->runApp('GET', '/api/v1/notes?page=1&perPage=3'); |
|
38
|
|
|
|
|
39
|
|
|
$result = (string) $response->getBody(); |
|
40
|
|
|
$value = (string) json_encode(json_decode($result)); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
43
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
44
|
|
|
$this->assertStringContainsString('success', $result); |
|
45
|
|
|
$this->assertStringContainsString('id', $result); |
|
46
|
|
|
$this->assertStringContainsString('name', $result); |
|
47
|
|
|
$this->assertStringContainsString('description', $result); |
|
48
|
|
|
$this->assertStringContainsString('pagination', $result); |
|
49
|
|
|
$this->assertMatchesRegularExpression('{"code":200,"status":"success"}', $value); |
|
50
|
|
|
$this->assertMatchesRegularExpression('{"name":"[A-Za-z0-9_. ]+","description":"[A-Za-z0-9_. ]+"}', $value); |
|
51
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Test Get One Note. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testGetNote(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $this->runApp('GET', '/api/v1/notes/1'); |
|
60
|
|
|
|
|
61
|
|
|
$result = (string) $response->getBody(); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
64
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
65
|
|
|
$this->assertStringContainsString('success', $result); |
|
66
|
|
|
$this->assertStringContainsString('id', $result); |
|
67
|
|
|
$this->assertStringContainsString('name', $result); |
|
68
|
|
|
$this->assertStringContainsString('description', $result); |
|
69
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Test Get Note Not Found. |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testGetNoteNotFound(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$response = $this->runApp('GET', '/api/v1/notes/123456789'); |
|
78
|
|
|
|
|
79
|
|
|
$result = (string) $response->getBody(); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
|
82
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
83
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
84
|
|
|
$this->assertStringNotContainsString('id', $result); |
|
85
|
|
|
$this->assertStringNotContainsString('description', $result); |
|
86
|
|
|
$this->assertStringContainsString('error', $result); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Test Search Notes. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testSearchNotes(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$response = $this->runApp('GET', '/api/v1/notes/search/n'); |
|
95
|
|
|
|
|
96
|
|
|
$result = (string) $response->getBody(); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
99
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
100
|
|
|
$this->assertStringContainsString('success', $result); |
|
101
|
|
|
$this->assertStringContainsString('id', $result); |
|
102
|
|
|
$this->assertStringContainsString('description', $result); |
|
103
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Test Search Note Not Found. |
|
108
|
|
|
*/ |
|
109
|
|
|
public function testSearchNoteNotFound(): void |
|
110
|
|
|
{ |
|
111
|
|
|
$response = $this->runApp('GET', '/api/v1/notes/search/123456789'); |
|
112
|
|
|
|
|
113
|
|
|
$result = (string) $response->getBody(); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
|
116
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
117
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
118
|
|
|
$this->assertStringNotContainsString('id', $result); |
|
119
|
|
|
$this->assertStringContainsString('error', $result); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Test Create Note. |
|
124
|
|
|
*/ |
|
125
|
|
|
public function testCreateNote(): void |
|
126
|
|
|
{ |
|
127
|
|
|
$response = $this->runApp( |
|
128
|
|
|
'POST', |
|
129
|
|
|
'/api/v1/notes', |
|
130
|
|
|
['name' => 'My Test Note', 'description' => 'New Note...'] |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
$result = (string) $response->getBody(); |
|
134
|
|
|
|
|
135
|
|
|
self::$id = json_decode($result)->message->id; |
|
136
|
|
|
|
|
137
|
|
|
$this->assertEquals(201, $response->getStatusCode()); |
|
138
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
139
|
|
|
$this->assertStringContainsString('success', $result); |
|
140
|
|
|
$this->assertStringContainsString('id', $result); |
|
141
|
|
|
$this->assertStringContainsString('name', $result); |
|
142
|
|
|
$this->assertStringContainsString('description', $result); |
|
143
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Test Get Note Created. |
|
148
|
|
|
*/ |
|
149
|
|
|
public function testGetNoteCreated(): void |
|
150
|
|
|
{ |
|
151
|
|
|
$response = $this->runApp('GET', '/api/v1/notes/' . self::$id); |
|
152
|
|
|
|
|
153
|
|
|
$result = (string) $response->getBody(); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
156
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
157
|
|
|
$this->assertStringContainsString('success', $result); |
|
158
|
|
|
$this->assertStringContainsString('id', $result); |
|
159
|
|
|
$this->assertStringContainsString('name', $result); |
|
160
|
|
|
$this->assertStringContainsString('description', $result); |
|
161
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Test Create Note Without Name. |
|
166
|
|
|
*/ |
|
167
|
|
|
public function testCreateNoteWithoutName(): void |
|
168
|
|
|
{ |
|
169
|
|
|
$response = $this->runApp('POST', '/api/v1/notes'); |
|
170
|
|
|
|
|
171
|
|
|
$result = (string) $response->getBody(); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertEquals(400, $response->getStatusCode()); |
|
174
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
175
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
176
|
|
|
$this->assertStringNotContainsString('description', $result); |
|
177
|
|
|
$this->assertStringContainsString('error', $result); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Test Create Note With Invalid Name. |
|
182
|
|
|
*/ |
|
183
|
|
|
public function testCreateNoteWithInvalidName(): void |
|
184
|
|
|
{ |
|
185
|
|
|
$response = $this->runApp( |
|
186
|
|
|
'POST', |
|
187
|
|
|
'/api/v1/notes', |
|
188
|
|
|
['name' => ''] |
|
189
|
|
|
); |
|
190
|
|
|
|
|
191
|
|
|
$result = (string) $response->getBody(); |
|
192
|
|
|
|
|
193
|
|
|
$this->assertEquals(400, $response->getStatusCode()); |
|
194
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
195
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
196
|
|
|
$this->assertStringNotContainsString('description', $result); |
|
197
|
|
|
$this->assertStringContainsString('error', $result); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Test Update Note. |
|
202
|
|
|
*/ |
|
203
|
|
|
public function testUpdateNote(): void |
|
204
|
|
|
{ |
|
205
|
|
|
$response = $this->runApp( |
|
206
|
|
|
'PUT', |
|
207
|
|
|
'/api/v1/notes/' . self::$id, |
|
208
|
|
|
['name' => 'Victor Notes', 'description' => 'Pep.'] |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
$result = (string) $response->getBody(); |
|
212
|
|
|
|
|
213
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
214
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
215
|
|
|
$this->assertStringContainsString('success', $result); |
|
216
|
|
|
$this->assertStringContainsString('id', $result); |
|
217
|
|
|
$this->assertStringContainsString('name', $result); |
|
218
|
|
|
$this->assertStringContainsString('description', $result); |
|
219
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Test Update Note Without Send Data. |
|
224
|
|
|
*/ |
|
225
|
|
|
public function testUpdateNoteWithOutSendData(): void |
|
226
|
|
|
{ |
|
227
|
|
|
$response = $this->runApp('PUT', '/api/v1/notes/' . self::$id); |
|
228
|
|
|
|
|
229
|
|
|
$result = (string) $response->getBody(); |
|
230
|
|
|
|
|
231
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
232
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
233
|
|
|
$this->assertStringContainsString('success', $result); |
|
234
|
|
|
$this->assertStringContainsString('id', $result); |
|
235
|
|
|
$this->assertStringContainsString('name', $result); |
|
236
|
|
|
$this->assertStringContainsString('description', $result); |
|
237
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Test Update Note Not Found. |
|
242
|
|
|
*/ |
|
243
|
|
|
public function testUpdateNoteNotFound(): void |
|
244
|
|
|
{ |
|
245
|
|
|
$response = $this->runApp( |
|
246
|
|
|
'PUT', |
|
247
|
|
|
'/api/v1/notes/123456789', |
|
248
|
|
|
['name' => 'Note'] |
|
249
|
|
|
); |
|
250
|
|
|
|
|
251
|
|
|
$result = (string) $response->getBody(); |
|
252
|
|
|
|
|
253
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
|
254
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
255
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
256
|
|
|
$this->assertStringNotContainsString('id', $result); |
|
257
|
|
|
$this->assertStringNotContainsString('name', $result); |
|
258
|
|
|
$this->assertStringNotContainsString('description', $result); |
|
259
|
|
|
$this->assertStringContainsString('error', $result); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Test Delete Note. |
|
264
|
|
|
*/ |
|
265
|
|
|
public function testDeleteNote(): void |
|
266
|
|
|
{ |
|
267
|
|
|
$response = $this->runApp('DELETE', '/api/v1/notes/' . self::$id); |
|
268
|
|
|
|
|
269
|
|
|
$result = (string) $response->getBody(); |
|
270
|
|
|
|
|
271
|
|
|
$this->assertEquals(204, $response->getStatusCode()); |
|
272
|
|
|
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type')); |
|
273
|
|
|
$this->assertStringContainsString('success', $result); |
|
274
|
|
|
$this->assertStringNotContainsString('error', $result); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Test Delete Note Not Found. |
|
279
|
|
|
*/ |
|
280
|
|
|
public function testDeleteNoteNotFound(): void |
|
281
|
|
|
{ |
|
282
|
|
|
$response = $this->runApp('DELETE', '/api/v1/notes/123456789'); |
|
283
|
|
|
|
|
284
|
|
|
$result = (string) $response->getBody(); |
|
285
|
|
|
|
|
286
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
|
287
|
|
|
$this->assertEquals('application/problem+json', $response->getHeaderLine('Content-Type')); |
|
288
|
|
|
$this->assertStringNotContainsString('success', $result); |
|
289
|
|
|
$this->assertStringNotContainsString('id', $result); |
|
290
|
|
|
$this->assertStringNotContainsString('name', $result); |
|
291
|
|
|
$this->assertStringNotContainsString('description', $result); |
|
292
|
|
|
$this->assertStringContainsString('error', $result); |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|