Skip to content

Commit 3337099

Browse files
committed
[Mailer] Catch missing scheme in DSN.
1 parent 20542d3 commit 3337099

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Tests/TransportTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ 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 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.');
76-
Transport::fromDsn('?!');
82+
$this->expectExceptionMessage('The "file:///some/path" mailer DSN must contain a mailer name.');
83+
Transport::fromDsn('file:///some/path');
7784
}
7885

7986
public function testFromInvalidTransportName()

Transport.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ 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['scheme'])) {
68+
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a transport scheme.', $dsn));
69+
}
70+
6771
if (!isset($parsedDsn['host'])) {
6872
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn));
6973
}

0 commit comments

Comments
 (0)