symfony4.2中的Swiftmailer单元/功能测试

问题描述 投票:0回答:1

以下是tests / controller文件夹中的代码。

<?php

namespace App\Tests\Controller;
use App\Controller\RegisterController;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Swift_Message;

class EvaplyTest extends TestCase
{
    /** @var LoggerInterface|MockObject */
    protected $logger;
    /** @var RegisterController **/
    protected $controller;
/**
 * {@inheritdoc}
 */
protected function setUp()
{
    $this->logger = $this->createMock(LoggerInterface::class);
    $this->controller = new RegisterController(
        $this->logger
    );
    parent::setUp();
}

/**
 * Test for determing wether evaply id generated sucessfully or not
 */
public function testMailsent()
  {
    $message = (new Swift_Message("Successfully Registered"));
  }
}

我收到此错误“此测试未执行任何断言”

我只是想确认邮件发送成功与否。

php unit-testing symfony swiftmailer phpunit-testing
1个回答
0
投票

使用phpunit时,任何测试都必须包含一个断言。断言是需要验证的肯定。

例如,在Symfony doc for email testing中,你会发现

$ this-> assertSame(1,$ mailCollector-> getMessageCount());

这意味着肯定第一个参数的值必须与第二个参数的值相同。如果这是真的,测试继续/是成功的。如果没有,php单元将报告错误。

正如蒂蒂利所说,发送电子邮件已经在这里记录了https://symfony.com/doc/current/email/testing.html

© www.soinside.com 2019 - 2024. All rights reserved.