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

Throwing Exception for bad URL formats #273

Merged
merged 1 commit into from Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion DependencyInjection/SwiftmailerTransportFactory.php
Expand Up @@ -99,7 +99,9 @@ public static function resolveOptions(array $options)
];

if (isset($options['url'])) {
$parts = parse_url($options['url']);
if (false === ($parts = parse_url($options['url']))) {
throw new \InvalidArgumentException(sprintf('Supplied url [%s] is not a valid format.', $options['url']));
}
if (isset($parts['scheme'])) {
$options['transport'] = $parts['scheme'];
}
Expand Down
27 changes: 27 additions & 0 deletions Tests/DependencyInjection/SwiftmailerTransportFactoryTest.php
Expand Up @@ -161,6 +161,33 @@ public function testCreateTransportWithSmtpAndWithoutRequestContext()
$this->assertSame($authHandler->getAuthMode(), $options['auth_mode']);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Supplied url [smtp://localhost:25&auth_mode=cra-md5] is not a valid format.
*/
public function testCreateTransportWithBadURLFormat()
{
$options = [
'url' => 'smtp://localhost:25&auth_mode=cra-md5',
'transport' => 'smtp',
'username' => null,
'password' => null,
'host' => 'localhost',
'port' => null,
'timeout' => 30,
'source_ip' => null,
'local_domain' => null,
'encryption' => null,
'auth_mode' => null,
];

SwiftmailerTransportFactory::createTransport(
$options,
null,
new \Swift_Events_SimpleEventDispatcher()
);
}

/**
* @dataProvider optionsAndResultExpected
*/
Expand Down