[Mailer] Catch missing scheme in DSN.

This commit is contained in:
Alexander M. Turek 2019-06-11 12:37:46 +02:00
parent cf728f5da2
commit 3eba36c088
2 changed files with 13 additions and 2 deletions

View File

@ -69,11 +69,18 @@ class TransportTest extends TestCase
Transport::fromDsn('some://'); 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() public function testFromInvalidDsnNoHost()
{ {
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "?!" mailer DSN must contain a mailer name.'); $this->expectExceptionMessage('The "file:///some/path" mailer DSN must contain a mailer name.');
Transport::fromDsn('?!'); Transport::fromDsn('file:///some/path');
} }
public function testFromInvalidTransportName() public function testFromInvalidTransportName()

View File

@ -64,6 +64,10 @@ class Transport
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn)); 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'])) { if (!isset($parsedDsn['host'])) {
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn)); throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn));
} }