Skip to content

Commit ac21806

Browse files
committed
Use connection fake
1 parent 3b9b377 commit ac21806

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

tests/Unit/MailboxTest.php

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use DirectoryTree\ImapEngine\Connection\ImapConnection;
4-
use DirectoryTree\ImapEngine\Connection\Streams\FakeStream;
54
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
65
use DirectoryTree\ImapEngine\Folder;
76
use DirectoryTree\ImapEngine\Mailbox;
@@ -64,83 +63,57 @@
6463
});
6564

6665
test('connect', function () {
67-
$stream = new FakeStream;
68-
$stream->open();
66+
$mailbox = Mailbox::make();
6967

70-
$stream->feed([
68+
$mailbox->connect(ImapConnection::fake([
7169
'* OK Welcome to IMAP',
7270
'TAG1 OK Logged in',
73-
]);
74-
75-
$mailbox = Mailbox::make();
76-
77-
$mailbox->connect(new ImapConnection($stream));
71+
]));
7872

7973
expect($mailbox->connected())->toBeTrue();
8074
});
8175

8276
test('connect throws exception with bad response', function () {
83-
$stream = new FakeStream;
84-
$stream->open();
85-
86-
$stream->feed([
87-
'* OK Welcome to IMAP',
88-
'TAG1 BAD Authentication failed',
89-
]);
90-
9177
$mailbox = Mailbox::make([
9278
'username' => 'foo',
9379
'password' => 'bar',
9480
]);
9581

96-
$mailbox->connect(new ImapConnection($stream));
82+
$mailbox->connect(ImapConnection::fake([
83+
'* OK Welcome to IMAP',
84+
'TAG1 BAD Authentication failed',
85+
]));
9786
})->throws(ImapCommandException::class, 'IMAP command "TAG1 LOGIN [redacted] [redacted]" failed. Response: "TAG1 BAD Authentication failed"');
9887

9988
test('folders', function () {
100-
$stream = new FakeStream;
101-
$stream->open();
89+
$mailbox = Mailbox::make();
10290

103-
$stream->feed([
91+
$mailbox->connect(ImapConnection::fake([
10492
'* OK Welcome to IMAP',
10593
'TAG1 OK Logged in',
10694
'* LIST (\\HasNoChildren) "/" "INBOX"',
10795
'TAG2 OK LIST completed',
108-
]);
109-
110-
$mailbox = Mailbox::make();
111-
112-
$mailbox->connect(new ImapConnection($stream));
96+
]));
11397

11498
$folders = $mailbox->folders()->get();
11599

116-
$stream->assertWritten('TAG1 LOGIN "" ""');
117-
$stream->assertWritten('TAG2 LIST "" "*"');
118-
119100
expect($folders)->toHaveCount(1);
120101
expect($folders[0]->path())->toBe('INBOX');
121102
expect($folders[0]->flags())->toBe(['\\HasNoChildren']);
122103
});
123104

124105
test('inbox', function () {
125-
$stream = new FakeStream;
126-
$stream->open();
106+
$mailbox = Mailbox::make();
127107

128-
$stream->feed([
108+
$mailbox->connect(ImapConnection::fake([
129109
'* OK Welcome to IMAP',
130110
'TAG1 OK Logged in',
131111
'* LIST (\\HasNoChildren) "/" "INBOX"',
132112
'TAG2 OK LIST completed',
133-
]);
134-
135-
$mailbox = Mailbox::make();
136-
137-
$mailbox->connect(new ImapConnection($stream));
113+
]));
138114

139115
$folder = $mailbox->inbox();
140116

141-
$stream->assertWritten('TAG1 LOGIN "" ""');
142-
$stream->assertWritten('TAG2 LIST "" "INBOX"');
143-
144117
expect($folder)->toBeInstanceOf(Folder::class);
145118

146119
expect($folder->path())->toBe('INBOX');

0 commit comments

Comments
 (0)