|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use DirectoryTree\ImapEngine\Connection\ImapConnection; |
4 | | -use DirectoryTree\ImapEngine\Connection\Streams\FakeStream; |
5 | 4 | use DirectoryTree\ImapEngine\Exceptions\ImapCommandException; |
6 | 5 | use DirectoryTree\ImapEngine\Folder; |
7 | 6 | use DirectoryTree\ImapEngine\Mailbox; |
|
64 | 63 | }); |
65 | 64 |
|
66 | 65 | test('connect', function () { |
67 | | - $stream = new FakeStream; |
68 | | - $stream->open(); |
| 66 | + $mailbox = Mailbox::make(); |
69 | 67 |
|
70 | | - $stream->feed([ |
| 68 | + $mailbox->connect(ImapConnection::fake([ |
71 | 69 | '* OK Welcome to IMAP', |
72 | 70 | 'TAG1 OK Logged in', |
73 | | - ]); |
74 | | - |
75 | | - $mailbox = Mailbox::make(); |
76 | | - |
77 | | - $mailbox->connect(new ImapConnection($stream)); |
| 71 | + ])); |
78 | 72 |
|
79 | 73 | expect($mailbox->connected())->toBeTrue(); |
80 | 74 | }); |
81 | 75 |
|
82 | 76 | 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 | | - |
91 | 77 | $mailbox = Mailbox::make([ |
92 | 78 | 'username' => 'foo', |
93 | 79 | 'password' => 'bar', |
94 | 80 | ]); |
95 | 81 |
|
96 | | - $mailbox->connect(new ImapConnection($stream)); |
| 82 | + $mailbox->connect(ImapConnection::fake([ |
| 83 | + '* OK Welcome to IMAP', |
| 84 | + 'TAG1 BAD Authentication failed', |
| 85 | + ])); |
97 | 86 | })->throws(ImapCommandException::class, 'IMAP command "TAG1 LOGIN [redacted] [redacted]" failed. Response: "TAG1 BAD Authentication failed"'); |
98 | 87 |
|
99 | 88 | test('folders', function () { |
100 | | - $stream = new FakeStream; |
101 | | - $stream->open(); |
| 89 | + $mailbox = Mailbox::make(); |
102 | 90 |
|
103 | | - $stream->feed([ |
| 91 | + $mailbox->connect(ImapConnection::fake([ |
104 | 92 | '* OK Welcome to IMAP', |
105 | 93 | 'TAG1 OK Logged in', |
106 | 94 | '* LIST (\\HasNoChildren) "/" "INBOX"', |
107 | 95 | 'TAG2 OK LIST completed', |
108 | | - ]); |
109 | | - |
110 | | - $mailbox = Mailbox::make(); |
111 | | - |
112 | | - $mailbox->connect(new ImapConnection($stream)); |
| 96 | + ])); |
113 | 97 |
|
114 | 98 | $folders = $mailbox->folders()->get(); |
115 | 99 |
|
116 | | - $stream->assertWritten('TAG1 LOGIN "" ""'); |
117 | | - $stream->assertWritten('TAG2 LIST "" "*"'); |
118 | | - |
119 | 100 | expect($folders)->toHaveCount(1); |
120 | 101 | expect($folders[0]->path())->toBe('INBOX'); |
121 | 102 | expect($folders[0]->flags())->toBe(['\\HasNoChildren']); |
122 | 103 | }); |
123 | 104 |
|
124 | 105 | test('inbox', function () { |
125 | | - $stream = new FakeStream; |
126 | | - $stream->open(); |
| 106 | + $mailbox = Mailbox::make(); |
127 | 107 |
|
128 | | - $stream->feed([ |
| 108 | + $mailbox->connect(ImapConnection::fake([ |
129 | 109 | '* OK Welcome to IMAP', |
130 | 110 | 'TAG1 OK Logged in', |
131 | 111 | '* LIST (\\HasNoChildren) "/" "INBOX"', |
132 | 112 | 'TAG2 OK LIST completed', |
133 | | - ]); |
134 | | - |
135 | | - $mailbox = Mailbox::make(); |
136 | | - |
137 | | - $mailbox->connect(new ImapConnection($stream)); |
| 113 | + ])); |
138 | 114 |
|
139 | 115 | $folder = $mailbox->inbox(); |
140 | 116 |
|
141 | | - $stream->assertWritten('TAG1 LOGIN "" ""'); |
142 | | - $stream->assertWritten('TAG2 LIST "" "INBOX"'); |
143 | | - |
144 | 117 | expect($folder)->toBeInstanceOf(Folder::class); |
145 | 118 |
|
146 | 119 | expect($folder->path())->toBe('INBOX'); |
|
0 commit comments