xm / mailer-test-bundle
Allows for easy testing of the mailer/emails when using the SwiftMailerBundle.
Installs: 68
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^5.6 || ^7.0
- phpunit/phpunit: 4.8.*|~5.2|~6.0|~7.0
- symfony/swiftmailer-bundle: ~2.3 || ~3.0
- symfony/symfony: ~3.0
This package is auto-updated.
Last update: 2024-11-15 14:58:25 UTC
README
Allows for easy testing of the mailer/emails when using the SwiftMailerBundle.
Installation
Step 1: Download the Bundle
This package is not on Packagist, so the repository will need to be added manually in composer.json
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ php composer.phar require --dev xm/mailer-test-bundle
This command requires Composer.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { // ... if (in_array($this->getEnvironment(), array('dev', 'test'))) { // ... $bundles[] = new XM\MailerTestBundle\XMMailerTestBundle(); } } }
Usage
Below is how this bundle would be typically used.
<?php namespace Tests\AppBundle\EventSubscriber; use Symfony\Component\EventDispatcher\GenericEvent; use XM\MailerTestBundle\Test\MailerTestCase; class EventSubscriberTest extends MailerTestCase { public function testEvent() { $mailerPlugin = $this->getMailerPlugin(); $event = new GenericEvent(); $this->container->get('app.listener') ->onEvent($event); // make sure email was sent $this->assertNotNull($mailerPlugin->beforeSendEvent); $this->assertNotNull($mailerPlugin->sendEvent); // grab message and make sure it matches what we wanted $msg = $mailerPlugin->sendEvent->getMessage(); $expected = 'Expected Subject'; $this->assertEquals($expected, $msg->getSubject()); $this->assertContains('Expected part of email body', $msg->getBody()); } }