Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Basic email steps
Browse files Browse the repository at this point in the history
  • Loading branch information
umpirsky committed Dec 19, 2014
1 parent c5737ab commit b28a1c3
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require-dev": {
"symfony/http-kernel": "~2.0",
"symfony/framework-bundle": "~2.0",
"symfony/swiftmailer-bundle": "~2.0",
"symfony/web-profiler-bundle": "~2.0",
"symfony/twig-bundle": "~2.0",
"symfony/form": "~2.0",
Expand Down
13 changes: 13 additions & 0 deletions features/Page/EmailWithSubjectPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Page;

use Knp\FriendlyExtension\Page\Page;

class EmailWithSubjectPage extends Page
{
public function getPath()
{
return '/mailer/email-with-subject';
}
}
12 changes: 12 additions & 0 deletions features/fixtures/App/Controller/MailerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ public function noEmailsAction()
{
return new Response();
}

public function emailWithSubjectAction()
{
$this->get('mailer')->send(\Swift_Message::newInstance()
->setSubject('Hello Subject')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody('Hello Body.')
);

return new Response();
}
}
4 changes: 4 additions & 0 deletions features/fixtures/App/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ homepage:
mailer_no_emails:
pattern: /mailer/no-emails
defaults: { _controller: 'App:Mailer:noEmails' }

mailer_email_with_subject:
pattern: /mailer/email-with-subject
defaults: { _controller: 'App:Mailer:emailWithSubject' }
5 changes: 5 additions & 0 deletions features/fixtures/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function registerBundles()
return array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle,
new Symfony\Bundle\TwigBundle\TwigBundle,
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle,
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle,
new App\App
Expand All @@ -31,6 +32,10 @@ public function registerContainerConfiguration(LoaderInterface $loader)
'orm' => array(),
'dbal' => array(),
));

$container->loadFromExtension('swiftmailer', array(
'disable_delivery' => true,
));
});
}

Expand Down
4 changes: 4 additions & 0 deletions features/mailer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ Feature: I am able to describe sending emails
Scenario: No emails sent
When I go to the noEmails page
Then no email should have been sent

Scenario: Email with subject sent
When I go to the emailWithSubject page
Then email with subject "Hello Subject" should have been sent
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function isEmailSent($subject = null, $to = null)

protected function getCollector()
{
return $this->get('swiftmailer')->getCollector('swiftmailer');
return $this->get('profiler')->getCollector('swiftmailer');
}

public function getName()
Expand Down
20 changes: 20 additions & 0 deletions src/Knp/FriendlyExtension/Context/SymfonyMailerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,25 @@ class SymfonyMailerContext extends Context
*/
public function noEmailShouldHaveBeenSent()
{
$count = $this->get('swiftmailer')->countEmailsSent();

$this->get('asserter')->assertEquals(
0,
$count,
sprintf('%d emails have been sent.', $count)
);
}

/**
* @Then email with subject :subject should have been sent
*/
public function emailWithSubjectShouldHaveBeenSent($subject)
{
if (!$this->get('swiftmailer')->isEmailSent($subject)) {
throw new \Exception(sprintf(
'Email with subject "%s" have been sent.',
$subject
));
}
}
}
6 changes: 6 additions & 0 deletions src/Knp/FriendlyExtension/Resources/config/symfony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ services:
- { name: friendly.symfony.service, class: Doctrine\Common\Persistence\AbstractManagerRegistry }
- { name: remove-when-missing, service: friendly.symfony.kernel }

mailer:
synthetic: true
tags:
- { name: friendly.symfony.service, class: Swift_Mailer }
- { name: remove-when-missing, service: friendly.symfony.kernel }

profiler:
synthetic: true
tags:
Expand Down

0 comments on commit b28a1c3

Please sign in to comment.