我希望测试一个发送邮件的服务。我已经创建了一个单元测试,但是出现了一些过时警告,我想知道正确的使用方法。在我的setUp()函数中,我像这样获取服务:
$this->container = self::$kernel->getContainer();
$this->swiftMailer = $this->container->get('swiftmailer.mailer');
但我收到了这条信息。
The "swiftmailer.mailer" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.
什么是最佳实践? 我有一个与security.authentication.manager相关的相同消息。