11<?php
22
3+ use DirectoryTree \ImapEngine \Connection \ImapConnection ;
34use DirectoryTree \ImapEngine \Connection \ImapQueryBuilder ;
5+ use DirectoryTree \ImapEngine \Connection \Streams \FakeStream ;
46use DirectoryTree \ImapEngine \Folder ;
57use DirectoryTree \ImapEngine \Mailbox ;
68use DirectoryTree \ImapEngine \MessageQuery ;
79
8- function query (): MessageQuery
10+ function query (? Mailbox $ mailbox = null ): MessageQuery
911{
1012 return new MessageQuery (
11- new Folder (new Mailbox , 'test ' ),
13+ new Folder ($ mailbox ?? new Mailbox , 'test ' ),
1214 new ImapQueryBuilder
1315 );
1416}
@@ -27,3 +29,41 @@ function query(): MessageQuery
2729
2830 expect ($ query )->toBe ('SUBJECT "hello" ' );
2931});
32+
33+ test ('destroy ' , function () {
34+ $ stream = new FakeStream ;
35+ $ stream ->open ();
36+
37+ $ stream ->feed ([
38+ '* OK Welcome to IMAP ' ,
39+ 'TAG1 OK Logged in ' ,
40+ 'TAG2 OK UID STORE completed ' ,
41+ ]);
42+
43+ $ mailbox = Mailbox::make ();
44+
45+ $ mailbox ->connect (new ImapConnection ($ stream ));
46+
47+ query ($ mailbox )->destroy (1 );
48+
49+ $ stream ->assertWritten ('TAG2 UID STORE 1 +FLAGS.SILENT (\Deleted) ' );
50+ });
51+
52+ test ('destroy with multiple messages ' , function () {
53+ $ stream = new FakeStream ;
54+ $ stream ->open ();
55+
56+ $ stream ->feed ([
57+ '* OK Welcome to IMAP ' ,
58+ 'TAG1 OK Logged in ' ,
59+ 'TAG2 OK UID STORE completed ' ,
60+ ]);
61+
62+ $ mailbox = Mailbox::make ();
63+
64+ $ mailbox ->connect (new ImapConnection ($ stream ));
65+
66+ query ($ mailbox )->destroy ([1 , 2 , 3 ]);
67+
68+ $ stream ->assertWritten ('TAG2 UID STORE 1,2,3 +FLAGS.SILENT (\Deleted) ' );
69+ });
0 commit comments