Skip to content

Commit

Permalink
Change getMailerMessages logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Jul 19, 2022
1 parent afa7db2 commit 669c9c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/Infrastructure/TestCase/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ public static function assertEmailFrom(string|array $expected, Email $email): vo
}

/** @phpstan-ignore-next-line */
public function getMailerMessages(string $transport = null): array
public function getMailerMessages(string $transport = null, bool $isQueued = true): array
{
return $this->getMessageMailerEvents()->getMessages($transport);
return \array_values(
\array_map(
static function (MessageEvent $event) {
return $event->getMessage();
},
\array_filter(
$this->getMessageMailerEvents()->getEvents($transport),
static function (MessageEvent $event) use ($isQueued) {
return $event->isQueued() === $isQueued;
}
)
)
);
}

public function assertEmailCount(int $count, string $transport = null, bool $isQueued = true): void
Expand Down
12 changes: 6 additions & 6 deletions tests/SendEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testSendEmailMinimumConfiguration(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand All @@ -84,7 +84,7 @@ public function testSendEmailWithReturnPath(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand All @@ -110,7 +110,7 @@ public function testSendEmailWithBcc(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand All @@ -137,7 +137,7 @@ public function testSendEmailWithYopmailEnabled(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand All @@ -164,7 +164,7 @@ public function testSendEmailWithSubjectPrefix(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand All @@ -185,7 +185,7 @@ public function testSendEmailWithFooter(): void
$this->mailer->send($email);

$this->assertEmailCount(1, null, false);
$email = $this->getMailerMessages()[0];
$email = $this->getMailerMessages(null, false)[0];

self::assertEmailTo('[email protected]', $email);
self::assertEmailFrom('[email protected]', $email);
Expand Down

0 comments on commit 669c9c5

Please sign in to comment.