Skip to content

Commit 9788570

Browse files
committed
Adjust tests to assert contents
1 parent 7d9a886 commit 9788570

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

tests/Unit/Connection/ImapParserTest.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@
273273
$stream->open();
274274

275275
// Simulating BODY[TEXT] before BODY[HEADER]
276-
$stream->feed([
277-
'* 1 FETCH (UID 123 FLAGS (\\Seen) BODY[TEXT] {0}',
278-
'',
279-
' BODY[HEADER] {0}',
280-
'',
281-
')',
276+
$stream->feedRaw([
277+
"* 1 FETCH (UID 123 FLAGS (\\Seen) BODY[TEXT] {13}\r\n",
278+
"Hello World\r\n",
279+
" BODY[HEADER] {23}\r\n",
280+
"Subject: Test Message\r\n",
281+
")\r\n",
282282
]);
283283

284284
$tokenizer = new ImapTokenizer($stream);
@@ -301,25 +301,27 @@
301301
$flags = $data->lookup('FLAGS');
302302
expect($flags)->not->toBeNull();
303303

304-
// Verify we can lookup both BODY sections
304+
// Verify we can lookup both BODY sections with correct content
305305
$text = $data->lookup('[TEXT]');
306306
expect($text)->not->toBeNull();
307+
expect($text->value)->toBe("Hello World\r\n");
307308

308309
$header = $data->lookup('[HEADER]');
309310
expect($header)->not->toBeNull();
310-
})->issue(115);
311+
expect($header->value)->toBe("Subject: Test Message\r\n");
312+
});
311313

312314
test('parses fetch response with body header then text', function () {
313315
$stream = new FakeStream;
314316
$stream->open();
315317

316318
// Simulating BODY[HEADER] before BODY[TEXT]
317-
$stream->feed([
318-
'* 1 FETCH (UID 456 FLAGS (\\Seen) BODY[HEADER] {0}',
319-
'',
320-
' BODY[TEXT] {0}',
321-
'',
322-
')',
319+
$stream->feedRaw([
320+
"* 1 FETCH (UID 456 FLAGS (\\Seen) BODY[HEADER] {26}\r\n",
321+
"From: [email protected]\r\n",
322+
" BODY[TEXT] {20}\r\n",
323+
"Message body here.\r\n",
324+
")\r\n",
323325
]);
324326

325327
$tokenizer = new ImapTokenizer($stream);
@@ -342,25 +344,27 @@
342344
$flags = $data->lookup('FLAGS');
343345
expect($flags)->not->toBeNull();
344346

345-
// Verify we can lookup both BODY sections
347+
// Verify we can lookup both BODY sections with correct content
346348
$header = $data->lookup('[HEADER]');
347349
expect($header)->not->toBeNull();
350+
expect($header->value)->toBe("From: [email protected]\r\n");
348351

349352
$text = $data->lookup('[TEXT]');
350353
expect($text)->not->toBeNull();
351-
})->issue(115);
354+
expect($text->value)->toBe("Message body here.\r\n");
355+
});
352356

353357
test('parses fetch response with all metadata and body parts', function () {
354358
$stream = new FakeStream;
355359
$stream->open();
356360

357361
// Full FETCH response with all common fields
358-
$stream->feed([
359-
'* 1 FETCH (UID 789 RFC822.SIZE 1024 FLAGS (\\Seen \\Flagged) BODY[TEXT] {0}',
360-
'',
361-
' BODY[HEADER] {0}',
362-
'',
363-
')',
362+
$stream->feedRaw([
363+
"* 1 FETCH (UID 789 RFC822.SIZE 1024 FLAGS (\\Seen \\Flagged) BODY[TEXT] {25}\r\n",
364+
"This is the email body.\r\n",
365+
" BODY[HEADER] {46}\r\n",
366+
"To: [email protected]\r\nSubject: Re: Test\r\n",
367+
")\r\n",
364368
]);
365369

366370
$tokenizer = new ImapTokenizer($stream);
@@ -373,10 +377,10 @@
373377
$data = $response->tokenAt(3);
374378
expect($data)->toBeInstanceOf(ListData::class);
375379

376-
// Verify all lookups work correctly
380+
// Verify all lookups work correctly with actual content
377381
expect($data->lookup('UID')?->value)->toBe('789');
378382
expect($data->lookup('RFC822.SIZE')?->value)->toBe('1024');
379383
expect($data->lookup('FLAGS'))->not->toBeNull();
380-
expect($data->lookup('[TEXT]'))->not->toBeNull();
381-
expect($data->lookup('[HEADER]'))->not->toBeNull();
382-
})->issue(115);
384+
expect($data->lookup('[TEXT]')->value)->toBe("This is the email body.\r\n");
385+
expect($data->lookup('[HEADER]')->value)->toBe("To: [email protected]\r\nSubject: Re: Test\r\n");
386+
});

0 commit comments

Comments
 (0)