8000 bug #166 Fixed smtp usage without request context (HeahDude) · symfony/swiftmailer-bundle@b59a70d · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.

Commit b59a70d

Browse files
committed
bug #166 Fixed smtp usage without request context (HeahDude)
This PR was merged into the 2.5-dev branch. Discussion ---------- Fixed smtp usage without request context Closes #163. Commits ------- 90a381a Fixed smtp usage without request context
2 parents 1dd5c98 + 90a381a commit b59a70d

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

DependencyInjection/SwiftmailerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function configureMailer($name, array $mailer, ContainerBuilder $conta
8989
$definitionDecorator->setFactory(array('Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerTransportFactory', 'createTransport'));
9090
$definitionDecorator->setArguments(array(
9191
$options,
92-
new Reference('router.request_context'),
92+
new Reference('router.request_context', ContainerInterface::NULL_ON_INVALID_REFERENCE),
9393
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
9494
));
9595
$container->setDefinition(sprintf('swiftmailer.mailer.%s.transport.dynamic', $name), $definitionDecorator);

DependencyInjection/SwiftmailerTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class SwiftmailerTransportFactory
2222
{
2323
/**
2424
* @param array $options
25-
* @param RequestContext $requestContext
25+
* @param RequestContext|null $requestContext
2626
* @param \Swift_Events_EventDispatcher $eventDispatcher
2727
*
2828
* @return \Swift_Transport
2929
*
3030
* @throws \InvalidArgumentException if the scheme is not a built-in Swiftmailer transport
3131
*/
32-
public static function createTransport(array $options, RequestContext $requestContext, \Swift_Events_EventDispatcher $eventDispatcher)
32+
public static function createTransport(array $options, RequestContext $requestContext = null, \Swift_Events_EventDispatcher $eventDispatcher)
3333
{
3434
$options = static::resolveOptions($options);
3535

Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,39 @@ public function testCreateTransportWithNull()
9494
$this->assertInstanceOf('Swift_Transport_NullTransport', $transport);
9595
}
9696

97+
public function testCreateTransportWithSmtpAndWithoutRequestContext()
98+
{
99+
$options = array(
100+
'transport' => 'smtp',
101+
'username' => 'user',
102+
'password' => 'pass',
103+
'host' => 'host',
104+
'port' => 1234,
105+
'timeout' => 42,
106+
'source_ip' => 'source_ip',
107+
'local_domain' => 'local_domain',
108+
'encryption' => 'encryption',
109+
'auth_mode' => 'auth_mode',
110+
);
111+
112+
$transport = SwiftmailerTransportFactory::createTransport(
113+
$options,
114+
null,
115+
new \Swift_Events_SimpleEventDispatcher()
116+
);
117+
$this->assertInstanceOf('Swift_Transport_EsmtpTransport', $transport);
118+
$this->assertSame($transport->getHost(), $options['host']);
119+
$this->assertSame($transport->getPort(), $options['port']);
120+
$this->assertSame($transport->getEncryption(), $options['encryption']);
121+
$this->assertSame($transport->getTimeout(), $options['timeout']);
122+
$this->assertSame($transport->getSourceIp(), $options['source_ip']);
123+
124+
$authHandler = current($transport->getExtensionHandlers());
125+
$this->assertSame($authHandler->getUsername(), $options['username']);
126+
$this->assertSame($authHandler->getPasswor 59BF d(), $options['password']);
127+
$this->assertSame($authHandler->getAuthMode(), $options['auth_mode']);
128+
}
129+
97130
/**
98131
* @dataProvider optionsAndResultExpected
99132
*/

0 commit comments

Comments
 (0)
0