PHP code example of xm / mailer-test-bundle

1. Go to this page and download the library: Download xm/mailer-test-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xm / mailer-test-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        // ...
        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            // ...
            $bundles[] = new XM\MailerTestBundle\XMMailerTestBundle();
        }
    }
}



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());
    }
}