44
55namespace Buggregator \Trap \Tests \Unit \Sender ;
66
7+ use Buggregator \Trap \Info ;
78use Buggregator \Trap \Proto \Frame \Smtp as SmtpFrame ;
89use Buggregator \Trap \Sender \MailToFileSender ;
910use Buggregator \Trap \Traffic \Message \Smtp as SmtpMessage ;
11+ use DirectoryIterator ;
1012use PHPUnit \Framework \TestCase ;
1113
1214/**
1315 * @coversDefaultClass \Buggregator\Trap\Sender\MailToFileSender
1416 */
1517final class MailToFileSenderTest extends TestCase
1618{
19+ /** @var list<non-empty-string> */
1720 private array $ cleanupFolders = [];
1821
1922 public function testForSmtp (): void
2023 {
21- $ this ->cleanupFolders [] = $ root = \sys_get_temp_dir () . DIRECTORY_SEPARATOR . \uniqid ( ' trap_mail_ ' ) ;
24+ $ this ->cleanupFolders [] = $ root = Info:: TRAP_ROOT . ' /runtime/tests/mail-to-file-sender ' ;
2225
2326 $ message = SmtpMessage::create (
2427 protocol: [
@@ -36,23 +39,23 @@ public function testForSmtp(): void
3639 $ sender = new MailToFileSender ($ root );
3740 $ sender ->send ([$ frame ]);
3841
39- $ this ->assertRecipient ("$ root/user1@ company.tld " );
40- $ this ->assertRecipient ("$ root/user2@ company.tld " );
42+ $ this ->assertRecipient ("$ root/user1[at] company.tld " );
43+ $ this ->assertRecipient ("$ root/user2[at] company.tld " );
4144 }
4245
4346 protected function tearDown (): void
4447 {
4548 foreach ($ this ->cleanupFolders as $ folder ) {
46- \array_map ('unlink ' , \glob ("$ folder/*.* " ));
49+ \array_map ('unlink ' , \glob ("$ folder/*/*.* " ));
50+ \array_map ('rmdir ' , \glob ("$ folder/* " ));
4751 \rmdir ($ folder );
4852 }
4953 }
5054
5155 private function assertRecipient (string $ folder ): void
5256 {
53- self ::assertTrue (\file_exists ($ folder ));
54- self ::assertTrue (\is_dir ($ folder ));
55- $ files = \glob ("$ folder/*.json " );
57+ self ::assertDirectoryExists ($ folder );
58+ $ files = \glob (\str_replace ('[ ' , '[[] ' , "$ folder/*.json " ));
5659 self ::assertCount (1 , $ files );
5760 $ arr = \json_decode (\file_get_contents ($ files [0 ]), true , \JSON_THROW_ON_ERROR );
5861 self ::assertArrayHasKey ('protocol ' , $ arr );
0 commit comments