From 2601cd8e0110da354432c28052b0c5cca441112f Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 27 Oct 2022 13:45:09 +1300 Subject: [PATCH] FIX Emails are arrays in TestMailer --- src/Context/EmailContext.php | 8 ++++---- src/Utility/TestMailer.php | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Context/EmailContext.php b/src/Context/EmailContext.php index dae187b..78494b6 100644 --- a/src/Context/EmailContext.php +++ b/src/Context/EmailContext.php @@ -89,7 +89,7 @@ class EmailContext implements Context $match = $this->mailer->findEmail($to, $from, $subject); $allMails = $this->mailer->findEmails($to, $from); $allTitles = $allMails ? '"' . implode('","', array_map(function ($email) { - return $email->Subject; + return $email['Subject']; }, $allMails)) . '"' : null; if (trim($negate ?? '')) { Assert::assertNull($match); @@ -174,7 +174,7 @@ class EmailContext implements Context $match = $this->mailer->findEmail($to, $from); Assert::assertNotNull($match); - $crawler = new Crawler($match->Content); + $crawler = new Crawler($match['Content']); $linkEl = $crawler->selectLink($linkSelector); Assert::assertNotNull($linkEl); $link = $linkEl->attr('href'); @@ -197,7 +197,7 @@ class EmailContext implements Context $match = $this->mailer->findEmail($to, $from, $title); Assert::assertNotNull($match); - $crawler = new Crawler($match->Content); + $crawler = new Crawler($match['Content']); $linkEl = $crawler->selectLink($linkSelector); Assert::assertNotNull($linkEl); $link = $linkEl->attr('href'); @@ -283,7 +283,7 @@ class EmailContext implements Context */ public function thereIsAnEmailTitled($negate, $subject) { - $match = $this->mailer->findEmail(null, null, $subject); + $match = $this->mailer->findEmail('', null, $subject); if (trim($negate ?? '')) { Assert::assertNull($match); } else { diff --git a/src/Utility/TestMailer.php b/src/Utility/TestMailer.php index b892812..8b8d7a2 100644 --- a/src/Utility/TestMailer.php +++ b/src/Utility/TestMailer.php @@ -65,9 +65,10 @@ class TestMailer extends BaseTestMailer ?string $content = null ): ?array { $matches = $this->findEmails($to, $from, $subject, $content); - //got the count of matches emails - $emailCount = count($matches ?? []); - //get the last(latest) one + //got the count of matches emails + $emailCount = count($matches ?? []); + //get the last(latest) one + return $matches ? $matches[$emailCount-1] : null; } @@ -108,14 +109,14 @@ class TestMailer extends BaseTestMailer } } if ($matched) { - $matches[] = $email; + $matches[] = json_decode(json_encode($email), true); } } return $matches; } - protected function saveEmail($data) + protected function saveEmail(array $data) { $state = $this->testSessionEnvironment->getState(); if (!isset($state->emails)) {