Skip to content

Commit fa9bb3b

Browse files
committed
Add some folder unit tests
1 parent fc28220 commit fa9bb3b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/Unit/MailboxTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use DirectoryTree\ImapEngine\Connection\ImapConnection;
44
use DirectoryTree\ImapEngine\Connection\Streams\FakeStream;
55
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
6+
use DirectoryTree\ImapEngine\Folder;
67
use DirectoryTree\ImapEngine\Mailbox;
78

89
test('config defaults', function () {
@@ -94,3 +95,54 @@
9495

9596
$mailbox->connect(new ImapConnection($stream));
9697
})->throws(ImapCommandException::class, 'IMAP command "TAG1 LOGIN [redacted] [redacted]" failed. Response: "TAG1 BAD Authentication failed"');
98+
99+
test('folders', function () {
100+
$stream = new FakeStream;
101+
$stream->open();
102+
103+
$stream->feed([
104+
'* OK Welcome to IMAP',
105+
'TAG1 OK Logged in',
106+
'* LIST (\\HasNoChildren) "/" "INBOX"',
107+
'TAG2 OK LIST completed',
108+
]);
109+
110+
$mailbox = Mailbox::make();
111+
112+
$mailbox->connect(new ImapConnection($stream));
113+
114+
$folders = $mailbox->folders()->get();
115+
116+
$stream->assertWritten('TAG1 LOGIN "" ""');
117+
$stream->assertWritten('TAG2 LIST "" "*"');
118+
119+
expect($folders)->toHaveCount(1);
120+
expect($folders[0]->path())->toBe('INBOX');
121+
expect($folders[0]->flags())->toBe(['\\HasNoChildren']);
122+
});
123+
124+
test('inbox', function () {
125+
$stream = new FakeStream;
126+
$stream->open();
127+
128+
$stream->feed([
129+
'* OK Welcome to IMAP',
130+
'TAG1 OK Logged in',
131+
'* LIST (\\HasNoChildren) "/" "INBOX"',
132+
'TAG2 OK LIST completed',
133+
]);
134+
135+
$mailbox = Mailbox::make();
136+
137+
$mailbox->connect(new ImapConnection($stream));
138+
139+
$folder = $mailbox->inbox();
140+
141+
$stream->assertWritten('TAG1 LOGIN "" ""');
142+
$stream->assertWritten('TAG2 LIST "" "INBOX"');
143+
144+
expect($folder)->toBeInstanceOf(Folder::class);
145+
146+
expect($folder->path())->toBe('INBOX');
147+
expect($folder->flags())->toBe(['\\HasNoChildren']);
148+
});

0 commit comments

Comments
 (0)