Skip to content

Commit a295628

Browse files
author
Gustavo Nieves
authored
Update Symfony.php
1 parent 5dac9c1 commit a295628

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,27 @@ public function seeInCurrentRoute($routeName)
479479
* ```
480480
*
481481
* @param null|int $expectedCount
482+
* @param null|string $mailer
482483
*/
483-
public function seeEmailIsSent($expectedCount = null)
484+
public function seeEmailIsSent($expectedCount = null, $mailer = 'swiftmailer')
484485
{
485486
$profile = $this->getProfile();
486487
if (!$profile) {
487488
$this->fail('Emails can\'t be tested without Profiler');
488489
}
489-
if (!$profile->hasCollector('swiftmailer')) {
490-
$this->fail('Emails can\'t be tested without SwiftMailer connector');
490+
switch ($mailer) {
491+
case 'swiftmailer':
492+
if (!$profile->hasCollector('swiftmailer')) {
493+
$this->fail('Emails can\'t be tested without SwiftMailer connector');
494+
}
495+
break;
496+
case 'symfony_mailer':
497+
if (!$profile->hasCollector('mailer')) {
498+
$this->fail('Emails can\'t be tested without Symfony Mailer connector');
499+
}
500+
break;
501+
default:
502+
$this->fail('Invalid mailer argument. Allowed Options: "swiftmailer" or "symfony_mailer"');
491503
}
492504

493505
if (!is_int($expectedCount) && !is_null($expectedCount)) {
@@ -497,8 +509,12 @@ public function seeEmailIsSent($expectedCount = null)
497509
));
498510
}
499511

500-
$realCount = $profile->getCollector('swiftmailer')->getMessageCount();
501-
$realCount += count($profile->getCollector('mailer')->getEvents()->getMessages());
512+
if ($mailer === 'swiftmailer') {
513+
$realCount = $profile->getCollector('swiftmailer')->getMessageCount();
514+
} else {
515+
$realCount = count($profile->getCollector('mailer')->getEvents()->getMessages());
516+
}
517+
502518
if ($expectedCount === null) {
503519
$this->assertGreaterThan(0, $realCount);
504520
} else {
@@ -634,6 +650,11 @@ protected function debugResponse($url)
634650
if ($messages) {
635651
$this->debugSection('Emails', $messages . ' sent');
636652
}
653+
} elseif ($profile->hasCollector('mailer')) {
654+
$messages = count($profile->getCollector('mailer')->getEvents()->getMessages());
655+
if ($messages) {
656+
$this->debugSection('Emails', $messages . ' sent');
657+
}
637658
}
638659
if ($profile->hasCollector('timer')) {
639660
$this->debugSection('Time', $profile->getCollector('timer')->getTime());

0 commit comments

Comments
 (0)