|
232 | 232 | expect($tokenizer->nextToken())->toBeNull(); |
233 | 233 | }); |
234 | 234 |
|
235 | | -test('tokenizer parsed tagged response', function () { |
| 235 | +test('tokenizer parses tagged response with response codes', function () { |
236 | 236 | $stream = new FakeStream; |
237 | 237 | $stream->open(); |
238 | 238 |
|
|
275 | 275 | expect($tokenizer->nextToken())->toBeNull(); |
276 | 276 | }); |
277 | 277 |
|
| 278 | +test('tokenizer parsers properly', function (array|string $feed, array $tokens) { |
| 279 | + $stream = new FakeStream; |
| 280 | + $stream->open(); |
| 281 | + $stream->feed($feed); |
| 282 | + |
| 283 | + $tokenizer = new ImapTokenizer($stream); |
| 284 | + |
| 285 | + for ($i = 0; $i < count($tokens); $i++) { |
| 286 | + $token = $tokenizer->nextToken(); |
| 287 | + |
| 288 | + expect($token->value)->toBe($tokens[$i]); |
| 289 | + } |
| 290 | +})->with([ |
| 291 | + [ |
| 292 | + 'TAG2 OK List completed (0.002 + 0.000 + 0.001 secs).', |
| 293 | + ['TAG2', 'OK', 'List', 'completed', '(', '0.002', '+', '0.000', '+', '0.001', 'secs', ')'], |
| 294 | + ], |
| 295 | + [ |
| 296 | + 'TAG1 OK [UIDNEXT 1000] Completed', |
| 297 | + ['TAG1', 'OK', '[', 'UIDNEXT', '1000', ']', 'Completed'], |
| 298 | + ], |
| 299 | + [ |
| 300 | + '* OK [CAPABILITY IMAP4rev1 LITERAL+] Server ready', |
| 301 | + ['*', 'OK', '[', 'CAPABILITY', 'IMAP4rev1', 'LITERAL+', ']', 'Server', 'ready'], |
| 302 | + ], |
| 303 | + [ |
| 304 | + '* BAD Command unknown', |
| 305 | + ['*', 'BAD', 'Command', 'unknown'], |
| 306 | + ], |
| 307 | + [ |
| 308 | + 'A1 NO (ALERT Unrecognized command)', |
| 309 | + ['A1', 'NO', '(', 'ALERT', 'Unrecognized', 'command', ')'], |
| 310 | + ], |
| 311 | + [ |
| 312 | + 'A142 FETCH (FLAGS (\\Seen) UID 48273)', |
| 313 | + ['A142', 'FETCH', '(', 'FLAGS', '(', '\\Seen', ')', 'UID', '48273', ')'], |
| 314 | + ], |
| 315 | + [ |
| 316 | + 'A002 OK [READ-ONLY] Mailbox opened', |
| 317 | + ['A002', 'OK', '[', 'READ-ONLY', ']', 'Mailbox', 'opened'], |
| 318 | + ], |
| 319 | + [ |
| 320 | + ['A003 OK {4}', 'Test'], |
| 321 | + ['A003', 'OK', 'Test'], |
| 322 | + ], |
| 323 | + [ |
| 324 | + '* LIST (\\HasNoChildren) "/" INBOX', |
| 325 | + ['*', 'LIST', '(', '\\HasNoChildren', ')', '/', 'INBOX'], |
| 326 | + ], |
| 327 | + [ |
| 328 | + 'A005 OK <[email protected]> Email sent', |
| 329 | + [ 'A005', 'OK', '[email protected]', 'Email', 'sent'], |
| 330 | + ], |
| 331 | + [ |
| 332 | + 'A004 BAD Syntax error', |
| 333 | + ['A004', 'BAD', 'Syntax', 'error'], |
| 334 | + ], |
| 335 | +]); |
| 336 | + |
278 | 337 | test('all tokens implement the token interface', function (string $data) { |
279 | 338 | $stream = new FakeStream; |
280 | 339 | $stream->open(); |
|
0 commit comments