|
70 | 70 | use function is_subclass_of;
|
71 | 71 | use function iterator_to_array;
|
72 | 72 | use function json_encode;
|
73 |
| -use function print_r; |
74 | 73 | use function serialize;
|
75 | 74 | use function sprintf;
|
76 | 75 | use function strlen;
|
@@ -578,41 +577,26 @@ public function seePageRedirectsTo(string $page, string $redirectsTo): void
|
578 | 577 | */
|
579 | 578 | public function seeEmailIsSent(?int $expectedCount = null): void
|
580 | 579 | {
|
581 |
| - if (($profile = $this->getProfile()) === null) { |
582 |
| - $this->fail("Emails can't be tested without Profiler"); |
583 |
| - } |
584 |
| - |
| 580 | + $realCount = 0; |
585 | 581 | $mailer = $this->config['mailer'];
|
586 |
| - if ($mailer === self::SYMFONY_MAILER) { |
587 |
| - $mailer = 'mailer'; |
588 |
| - } |
589 |
| - |
590 |
| - if (!$profile->hasCollector($mailer)) { |
| 582 | + if ($mailer === self::SWIFTMAILER) { |
| 583 | + $mailCollector = $this->grabCollector('swiftmailer', __FUNCTION__); |
| 584 | + $realCount = $mailCollector->getMessageCount(); |
| 585 | + } elseif ($mailer === self::SYMFONY_MAILER) { |
| 586 | + $mailCollector = $this->grabCollector('mailer', __FUNCTION__); |
| 587 | + $realCount = count($mailCollector->getEvents()->getMessages()); |
| 588 | + } else { |
591 | 589 | $this->fail(
|
592 | 590 | "Emails can't be tested without Mailer service connector.
|
593 | 591 | Set your mailer service in `functional.suite.yml`: `mailer: swiftmailer`
|
594 | 592 | (Or `mailer: symfony_mailer` for Symfony Mailer)."
|
595 | 593 | );
|
596 | 594 | }
|
597 | 595 |
|
598 |
| - if (!is_int($expectedCount) && !is_null($expectedCount)) { |
599 |
| - $this->fail(sprintf( |
600 |
| - 'The required number of emails must be either an integer or null. "%s" was provided.', |
601 |
| - print_r($expectedCount, true) |
602 |
| - )); |
603 |
| - } |
604 |
| - |
605 |
| - $mailCollector = $profile->getCollector($mailer); |
606 |
| - if ($mailer === self::SWIFTMAILER) { |
607 |
| - $realCount = $mailCollector->getMessageCount(); |
608 |
| - } else { |
609 |
| - $realCount = count($mailCollector->getEvents()->getMessages()); |
610 |
| - } |
611 |
| - |
612 | 596 | if ($expectedCount !== null) {
|
613 | 597 | $this->assertEquals($expectedCount, $realCount, sprintf(
|
614 | 598 | 'Expected number of sent emails was %d, but in reality %d %s sent.',
|
615 |
| - $expectedCount, $realCount, $realCount === 2 ? 'was' : 'were' |
| 599 | + $expectedCount, $realCount, $realCount === 1 ? 'was' : 'were' |
616 | 600 | ));
|
617 | 601 | return;
|
618 | 602 | }
|
|
0 commit comments