diff --git a/src/Symfony/Component/Mailer/Tests/TransportTest.php b/src/Symfony/Component/Mailer/Tests/TransportTest.php index 0d1f143262..9f014c6fa5 100644 --- a/src/Symfony/Component/Mailer/Tests/TransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/TransportTest.php @@ -69,11 +69,18 @@ class TransportTest extends TestCase Transport::fromDsn('some://'); } + public function testNoScheme() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The "//sendmail" mailer DSN must contain a transport scheme.'); + Transport::fromDsn('//sendmail'); + } + public function testFromInvalidDsnNoHost() { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name.'); - Transport::fromDsn('?!'); + $this->expectExceptionMessage('The "file:///some/path" mailer DSN must contain a mailer name.'); + Transport::fromDsn('file:///some/path'); } public function testFromInvalidTransportName() diff --git a/src/Symfony/Component/Mailer/Transport.php b/src/Symfony/Component/Mailer/Transport.php index eeb1892fe8..c27dd35614 100644 --- a/src/Symfony/Component/Mailer/Transport.php +++ b/src/Symfony/Component/Mailer/Transport.php @@ -64,6 +64,10 @@ class Transport throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn)); } + if (!isset($parsedDsn['scheme'])) { + throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a transport scheme.', $dsn)); + } + if (!isset($parsedDsn['host'])) { throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn)); }