Skip to content

Commit

Permalink
[Mailer] Catch missing scheme in DSN.
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jun 11, 2019
1 parent cf728f5 commit c00966a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Symfony/Component/Mailer/Tests/TransportTest.php
Expand Up @@ -69,10 +69,17 @@ public function testFromInvalidDsn()
Transport::fromDsn('some://');
}

public function testNoScheme()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "//sendmail" mailer DSN must contain a mailer name and transport scheme.');
Transport::fromDsn('//sendmail');
}

public function testFromInvalidDsnNoHost()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name.');
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name and transport scheme.');
Transport::fromDsn('?!');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mailer/Transport.php
Expand Up @@ -64,8 +64,8 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn));
}

if (!isset($parsedDsn['host'])) {
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn));
if (!isset($parsedDsn['scheme'], $parsedDsn['host'])) {
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name and transport scheme.', $dsn));
}

$user = \urldecode($parsedDsn['user'] ?? '');
Expand Down

0 comments on commit c00966a

Please sign in to comment.