Skip to content

Commit 9335610

Browse files
committed
Refactor getMailerMessage to use getMailerEvent
Replaced the O(N) operation of fetching all mailer messages to find one by index with an O(1) operation by fetching the specific event first. This avoids unnecessary memory allocation for the messages array.
1 parent 558c038 commit 9335610

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/Codeception/Module/Symfony/MailerAssertionsTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ public function getMailerMessages(?string $transport = null): array
198198
*/
199199
public function getMailerMessage(int $index = 0, ?string $transport = null): ?RawMessage
200200
{
201-
return $this->getMailerMessages($transport)[$index] ?? null;
201+
$event = $this->getMailerEvent($index, $transport);
202+
203+
return $event?->getMessage();
202204
}
203205

204206
protected function grabLastSentRawMessage(): ?RawMessage

tests/_app/Message/TestMessage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ final class TestMessage
88
{
99
public function __construct(
1010
private readonly string $content = '',
11-
) {
12-
}
11+
) {}
1312

1413
public function getContent(): string
1514
{

0 commit comments

Comments
 (0)