Skip to content

Commit ff69ea0

Browse files
committed
test: fix MailToFileSender tests
1 parent 3acb33a commit ff69ea0

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Sender/MailToFileSender.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function send(iterable $frames): void
4040
$path = $this->path . DIRECTORY_SEPARATOR . $email;
4141
FileSystem::mkdir($path);
4242
$filepath = \sprintf("%s/%s.json", $path, $frame->time->format('Y-m-d-H-i-s-v'));
43+
4344
\assert(!\file_exists($filepath));
4445
\file_put_contents($filepath, \json_encode($frame->message, \JSON_THROW_ON_ERROR));
4546
}

tests/Unit/Sender/MailToFileSenderTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44

55
namespace Buggregator\Trap\Tests\Unit\Sender;
66

7+
use Buggregator\Trap\Info;
78
use Buggregator\Trap\Proto\Frame\Smtp as SmtpFrame;
89
use Buggregator\Trap\Sender\MailToFileSender;
910
use Buggregator\Trap\Traffic\Message\Smtp as SmtpMessage;
11+
use DirectoryIterator;
1012
use PHPUnit\Framework\TestCase;
1113

1214
/**
1315
* @coversDefaultClass \Buggregator\Trap\Sender\MailToFileSender
1416
*/
1517
final 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

Comments
 (0)