diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index b04fd121..dccbc79a 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -69,7 +69,6 @@ use function is_subclass_of; use function iterator_to_array; use function json_encode; -use function print_r; use function serialize; use function sprintf; use function strlen; @@ -577,16 +576,15 @@ public function seePageRedirectsTo(string $page, string $redirectsTo): void */ public function seeEmailIsSent(?int $expectedCount = null): void { - if (($profile = $this->getProfile()) === null) { - $this->fail("Emails can't be tested without Profiler"); - } - + $realCount = 0; $mailer = $this->config['mailer']; - if ($mailer === self::SYMFONY_MAILER) { - $mailer = 'mailer'; - } - - if (!$profile->hasCollector($mailer)) { + if ($mailer === self::SWIFTMAILER) { + $mailCollector = $this->grabCollector('swiftmailer', __FUNCTION__); + $realCount = $mailCollector->getMessageCount(); + } elseif ($mailer === self::SYMFONY_MAILER) { + $mailCollector = $this->grabCollector('mailer', __FUNCTION__); + $realCount = count($mailCollector->getEvents()->getMessages()); + } else { $this->fail( "Emails can't be tested without Mailer service connector. Set your mailer service in `functional.suite.yml`: `mailer: swiftmailer` @@ -594,24 +592,10 @@ public function seeEmailIsSent(?int $expectedCount = null): void ); } - if (!is_int($expectedCount) && !is_null($expectedCount)) { - $this->fail(sprintf( - 'The required number of emails must be either an integer or null. "%s" was provided.', - print_r($expectedCount, true) - )); - } - - $mailCollector = $profile->getCollector($mailer); - if ($mailer === self::SWIFTMAILER) { - $realCount = $mailCollector->getMessageCount(); - } else { - $realCount = count($mailCollector->getEvents()->getMessages()); - } - if ($expectedCount !== null) { $this->assertEquals($expectedCount, $realCount, sprintf( 'Expected number of sent emails was %d, but in reality %d %s sent.', - $expectedCount, $realCount, $realCount === 2 ? 'was' : 'were' + $expectedCount, $realCount, $realCount === 1 ? 'was' : 'were' )); return; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy