xm/mailer-test-bundle

允许在使用SwiftMailerBundle时轻松测试邮件发送器/电子邮件。

安装: 67

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

0.1.1 2018-02-26 02:13 UTC

This package is auto-updated.

Last update: 2024-09-15 14:40:37 UTC


README

允许在使用SwiftMailerBundle时轻松测试邮件发送器/电子邮件。

安装步骤

步骤 1: 下载包

此包不在Packagist上,因此需要手动在composer.json中添加仓库

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ php composer.phar require --dev xm/mailer-test-bundle

此命令需要Composer

步骤 2: 启用包

然后,通过将其添加到项目中的app/AppKernel.php文件中注册的包列表中来启用包

<?php
// app/AppKernel.php

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

用法

以下是此包的典型用法。

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