8000 [Mailer][DX] Improve exception message for unsupported scheme by Koc · Pull Request #32608 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer][DX] Improve exception message for unsupported scheme #32608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function create(Dsn $dsn): TransportInterface
return new Amazon\Smtp\SesTransport($user, $password, $region, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'ses', self::USER, self::PASSWORD)];
yield [
new Dsn('foo', 'ses', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "ses". Supported schemes are: "api", "http", "smtp".',
];
}

public function incompleteDsnProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function create(Dsn $dsn): TransportInterface
return new GmailTransport($this->getUser($dsn), $this->getPassword($dsn), $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('http', 'gmail', self::USER, self::PASSWORD)];
yield [
new Dsn('foo', 'gmail', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "gmail". Supported schemes are: "smtp".',
];
}

public function incompleteDsnProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function create(Dsn $dsn): TransportInterface
return new Mailchimp\Smtp\MandrillTransport($user, $password, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'mandrill', self::USER)];
yield [
new Dsn('foo', 'mandrill', self::USER),
'The "foo" scheme is not supported for mailer "mandrill". Supported schemes are: "api", "http", "smtp".',
];
}

public function incompleteDsnProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function create(Dsn $dsn): TransportInterface
return new Mailgun\Smtp\MailgunTransport($user, $password, $region, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['api', 'http', 'smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'mailgun', self::USER, self::PASSWORD)];
yield [
new Dsn('foo', 'mailgun', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "mailgun". Supported schemes are: "api", "http", "smtp".',
];
}

public function incompleteDsnProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function create(Dsn $dsn): TransportInterface
return new Postmark\Smtp\PostmarkTransport($user, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'postmark', self::USER)];
yield [
new Dsn('foo', 'postmark', self::USER),
'The "foo" scheme is not supported for mailer "postmark". Supported schemes are: "api", "smtp".',
];
}

public function incompleteDsnProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function create(Dsn $dsn): TransportInterface
return new Sendgrid\Smtp\SendgridTransport($key, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['api', 'smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'sendgrid', self::USER)];
yield [
new Dsn('foo', 'sendgrid', self::USER),
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp".',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
class UnsupportedSchemeException extends LogicException
{
public function __construct(Dsn $dsn)
public function __construct(Dsn $dsn, array $supported)
{
parent::__construct(sprintf('The "%s" scheme is not supported for mailer "%s".', $dsn->getScheme(), $dsn->getHost()));
parent::__construct(sprintf('The "%s" scheme is not supported for mailer "%s". Supported schemes are: "%s".', $dsn->getScheme(), $dsn->getHost(), implode('", "', $supported)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('foo', 'null')];
yield [
new Dsn('foo', 'null'),
'The "foo" scheme is not supported for mailer "null". Supported schemes are: "smtp".',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function createProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield [new Dsn('http', 'sendmail')];
yield [
new Dsn('http', 'sendmail'),
'The "http" scheme is not supported for mailer "sendmail". Supported schemes are: "smtp".',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void
/**
* @dataProvider unsupportedSchemeProvider
*/
public function testUnsupportedSchemeException(Dsn $dsn): void
public function testUnsupportedSchemeException(Dsn $dsn, string $message = null): void
{
$factory = $this->getFactory();

$this->expectException(UnsupportedSchemeException::class);
if (null !== $message) {
$this->expectExceptionMessage($message);
}

$factory->create($dsn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function create(Dsn $dsn): TransportInterface
return new NullTransport($this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function create(Dsn $dsn): TransportInterface
return new SendmailTransport(null, $this->dispatcher, $this->logger);
}

throw new UnsupportedSchemeException($dsn);
throw new UnsupportedSchemeException($dsn, ['smtp']);
}

public function supports(Dsn $dsn): bool
Expand Down
0