8000 [Mailer] Catch missing scheme in DSN. · symfony/symfony@c00966a · GitHub
[go: up one dir, main page]

Skip to content

Commit c00966a

Browse files
committed
[Mailer] Catch missing scheme in DSN.
1 parent cf728f5 commit c00966a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ public function testFromInvalidDsn()
6969
Transport::fromDsn('some://');
7070
}
7171

72+
public function testNoScheme()
73+
{
74+
$this->expectException(InvalidArgumentException::class);
75+
$this->expectExceptionMessage('The "//sendmail" mailer DSN must contain a mailer name and transport scheme.');
76+
Transport::fromDsn('//sendmail');
77+
}
78+
7279
public function testFromInvalidDsnNoHost()
7380
{
7481
$this->expectException(InvalidArgumentException::class);
75-
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name.');
82+
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name and transport scheme.');
7683
Transport::fromDsn('?!');
7784
}
7885

src/Symfony/Component/Mailer/Transport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ private static function createTransport(string $dsn, EventDispatcherInterface $d
6464
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn));
6565
}
6666

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

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

0 commit comments

Comments
 (0)
0