- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Symfony4.1 项目中,我试图通过单元测试测试一种方法,该方法应该使用 SwiftMailer 发送邮件。
我的测试课看起来像这样
namespace App\Tests;
use App\Controller\UserImageValidationController;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
class UserImageValidationControllerTest extends TestCase
{
private $mailer = null;
public function __construct(\Swift_Mailer $testmySwiftMailer)
{
$this->mailer = $testmySwiftMailer;
}
public function testMail()
{
$controller = new UserImageValidationController();
$controller->notifyOfMissingImage(
'a',
'b',
'c',
'd',
$this->mailer
);
}
}
./bin/phpunit
我得到一个异常(exception)说
Uncaught ArgumentCountError: Too few arguments to function App\Tests\UserImageValidationControllerTest::__construct(), 0 [...] and exactly 1 expected [...]
bind:
$testmySwiftMailer: '@swiftmailer.mailer.default'
autowiring: true
到该文件(只是为了尝试),它也不起作用。
最佳答案
测试不是容器的一部分,也不充当服务,因此您的解决方案无效。扩展 Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
而是这样做(确保您的服务首先是公开的):
protected function setUp()
{
static::bootKernel();
$this->mailer = static::$kernel->getContainer()->get('mailer');
}
protected function tearDown()
{
$this->mailer = null
}
关于unit-testing - Symfony 4.1 : How to use Dependency Injection in UnitTest (Swift_Mailer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50858275/
如何给swiftmailer发送事件添加eventListener?每次我发送电子邮件时,我都会创建一个文件并将其附加到电子邮件中,发送后我想取消链接该文件。怎么做?谢谢。 file_put_con
我对 Symfony 中的 Swift_Mailer 有疑问。我正在发送包含大量“à é è”字符的法语电子邮件。起初,当我尝试发送这些字符时,在我的电子邮件客户端中显示正常,但在我同事的电子邮件客户
抱歉,可能只是一个新手问题,但这里有, 我有一个脚本可以循环使用如下代码发送电子邮件的一堆(有时是数千个)成员: $transport = Swift_SmtpTransport::newIn
在我的 Symfony4.1 项目中,我试图通过单元测试测试一种方法,该方法应该使用 SwiftMailer 发送邮件。 我的测试课看起来像这样 namespace App\Tests; use Ap
我已经将 monolog 配置为通过电子邮件发送错误,如 symfony 文档中所述:https://symfony.com/doc/4.3/logging/monolog_email.html 适用
我想向地址列表发送电子邮件,但我希望每个人都收到包含他的电子邮件地址的电子邮件:(而不是扩散列表中的其他电子邮件地址)。 我正在使用 symfony 和 Swift 邮件。我的代码目前看起来像这样(它
我正在使用 Swift_Mailer 开发 Symfony 4 应用程序发送电子邮件。 由于在我的情况下不可能使用 SMTP(不要问为什么......)我必须使用类似 sendmail 的东西。 .
我是一名优秀的程序员,十分优秀!