Skip to content

Commit 0c5ebd2

Browse files
committed
Add test
1 parent f7052aa commit 0c5ebd2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Commands/WatchMailboxTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DirectoryTree\ImapEngine\Laravel\Tests;
44

55
use DirectoryTree\ImapEngine\Laravel\Commands\WatchMailbox;
6+
use DirectoryTree\ImapEngine\Laravel\Events\MailboxWatchAttemptsExceeded;
67
use DirectoryTree\ImapEngine\Laravel\Events\MessageReceived;
78
use DirectoryTree\ImapEngine\Laravel\Facades\Imap;
89
use DirectoryTree\ImapEngine\Laravel\Support\LoopFake;
@@ -13,6 +14,7 @@
1314
use Illuminate\Support\Facades\Config;
1415
use Illuminate\Support\Facades\Event;
1516
use InvalidArgumentException;
17+
use RuntimeException;
1618

1719
use function Pest\Laravel\artisan;
1820

@@ -48,3 +50,39 @@
4850
fn (MessageReceived $event) => $event->message->is($message)
4951
);
5052
});
53+
54+
it('dispatches event when failure attempts have been reached', function () {
55+
Config::set('imap.mailboxes.test', [
56+
'host' => 'localhost',
57+
'port' => 993,
58+
'encryption' => 'ssl',
59+
'username' => '',
60+
'password' => '',
61+
]);
62+
63+
Imap::fake('test', folders: [
64+
new class('inbox') extends FakeFolder
65+
{
66+
public function idle(
67+
callable $callback,
68+
?callable $query = null,
69+
int $timeout = 300
70+
): void {
71+
throw new RuntimeException('Simulated exception');
72+
}
73+
},
74+
]);
75+
76+
Event::fake();
77+
78+
try {
79+
artisan(WatchMailbox::class, [
80+
'mailbox' => 'test',
81+
'--attempts' => 5,
82+
]);
83+
} catch (RuntimeException) {
84+
// Do nothing.
85+
}
86+
87+
Event::assertDispatched(MailboxWatchAttemptsExceeded::class);
88+
});

0 commit comments

Comments
 (0)