Skip to content

Update Symfony.php #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* * debug: true - turn on/off debug mode
* * cache_router: 'false' - enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire)
* * rebootable_client: 'true' - reboot client's kernel before each request
* * mailer: 'symfony_mailer' - choose the mailer used by your application
*
* #### Example (`functional.suite.yml`) - Symfony 4 Directory Structure
*
Expand All @@ -56,6 +57,7 @@
* * debug: true - turn on/off debug mode
* * cache_router: 'false' - enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire)
* * rebootable_client: 'true' - reboot client's kernel before each request
* * mailer: 'swiftmailer' - choose the mailer used by your application
*
* #### Example (`functional.suite.yml`) - Symfony 3 Directory Structure
*
Expand All @@ -76,6 +78,7 @@
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
* * cache_router: 'false' - enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire)
* * rebootable_client: 'true' - reboot client's kernel before each request
* * mailer: 'swiftmailer' - choose the mailer used by your application
*
* ### Example (`functional.suite.yml`) - Symfony 2.x Directory Structure
*
Expand Down Expand Up @@ -113,6 +116,9 @@
*/
class Symfony extends Framework implements DoctrineProvider, PartedModule
{
public const SWIFTMAILER = 'swiftmailer';
public const SYMFONY_MAILER = 'symfony_mailer';

private static $possibleKernelClasses = [
'AppKernel', // Symfony Standard
'App\Kernel', // Symfony Flex
Expand All @@ -132,6 +138,7 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
'cache_router' => false,
'em_service' => 'doctrine.orm.entity_manager',
'rebootable_client' => true,
'mailer' => self::SWIFTMAILER
];

/**
Expand Down Expand Up @@ -486,8 +493,25 @@ public function seeEmailIsSent($expectedCount = null)
if (!$profile) {
$this->fail('Emails can\'t be tested without Profiler');
}
if (!$profile->hasCollector('swiftmailer')) {
$this->fail('Emails can\'t be tested without SwiftMailer connector');
switch ($this->config['mailer']) {
case self::SWIFTMAILER:
if (!$profile->hasCollector('swiftmailer')) {
$this->fail(
'Emails can\'t be tested without SwiftMailer connector.
If you are using Symfony Mailer define mailer: "symfony_mailer" in Symfony module config.'
);
}
break;
case self::SYMFONY_MAILER:
if (!$profile->hasCollector('mailer')) {
$this->fail(
'Emails can\'t be tested without Symfony Mailer connector.
If you are using SwiftMailer define mailer: "swiftmailer" in Symfony module config.'
);
}
break;
default:
$this->fail('Invalid mailer config. Allowed Options: "swiftmailer" or "mailer"');
}

if (!is_int($expectedCount) && !is_null($expectedCount)) {
Expand All @@ -497,7 +521,12 @@ public function seeEmailIsSent($expectedCount = null)
));
}

$realCount = $profile->getCollector('swiftmailer')->getMessageCount();
if ($this->config['mailer'] === self::SWIFTMAILER) {
$realCount = $profile->getCollector('swiftmailer')->getMessageCount();
} else {
$realCount = count($profile->getCollector('mailer')->getEvents()->getMessages());
}

if ($expectedCount === null) {
$this->assertGreaterThan(0, $realCount);
} else {
Expand Down Expand Up @@ -633,6 +662,11 @@ protected function debugResponse($url)
if ($messages) {
$this->debugSection('Emails', $messages . ' sent');
}
} elseif ($profile->hasCollector('mailer')) {
$messages = count($profile->getCollector('mailer')->getEvents()->getMessages());
if ($messages) {
$this->debugSection('Emails', $messages . ' sent');
}
}
if ($profile->hasCollector('timer')) {
$this->debugSection('Time', $profile->getCollector('timer')->getTime());
Expand Down