LogicException:Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector 中缺少默认数据

nur*_*abe 5 profiler phpunit swiftmailer symfony

在 Symfony 2.5.5 和 Swiftmailer 5.3.0 中出现此异常。我完全按照食谱的例子。调用时抛出错误MessageDataCollector#getMessages()

// Check that an e-mail was sent
$this->assertEquals(1, $mailCollector->getMessageCount());

$collectedMessages = $mailCollector->getMessages();
$message = $collectedMessages[0]; 
Run Code Online (Sandbox Code Playgroud)

消息计数断言也失败,值为零。

据我所知,收集者没有在行动中进行任何实际的收集。有任何想法吗?

小智 2

在应用kriswallsmith 的测试优化技巧后,我遇到了同样的问题。运行开发版本时,我可以在Web Profiler中看到邮件发送的结果,但在测试环境中无法获取数据。

应用 Kris 的技巧后,我注意到swiftmailer.mailer.default.plugin.messagelogger服务在测试期间未向容器注册,因此MessageDataCollector 类collect() 方法没有记录邮件发送的数据。这就是无法从 swiftmailer 收集器检索信息的原因。

解决方案是要么不重写AppKernel.php中的initializeContainer()方法,要么重写它,但确保消息记录器服务可用于发送邮件的测试用例。