[Mailer][DX] Improve exception message for unsupported scheme
This commit is contained in:
parent
edd4a74f5c
commit
8c24a537c7
@ -41,7 +41,7 @@ final class SesTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -86,7 +86,10 @@ class SesTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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
|
||||
|
@ -28,7 +28,7 @@ final class GmailTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -38,7 +38,10 @@ class GmailTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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
|
||||
|
@ -41,7 +41,7 @@ final class MandrillTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -71,7 +71,10 @@ class MandrillTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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
|
||||
|
@ -41,7 +41,7 @@ final class MailgunTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -76,7 +76,10 @@ class MailgunTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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
|
||||
|
@ -35,7 +35,7 @@ final class PostmarkTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -60,7 +60,10 @@ class PostmarkTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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
|
||||
|
@ -34,7 +34,7 @@ final class SendgridTransportFactory extends AbstractTransportFactory
|
||||
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
|
||||
|
@ -60,6 +60,9 @@ class SendgridTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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".',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ use Symfony\Component\Mailer\Transport\Dsn;
|
||||
*/
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ class NullTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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".',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ class SendmailTransportFactoryTest extends TransportFactoryTestCase
|
||||
|
||||
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".',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +69,15 @@ abstract class TransportFactoryTestCase extends TestCase
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ final class NullTransportFactory extends AbstractTransportFactory
|
||||
return new NullTransport($this->dispatcher, $this->logger);
|
||||
}
|
||||
|
||||
throw new UnsupportedSchemeException($dsn);
|
||||
throw new UnsupportedSchemeException($dsn, ['smtp']);
|
||||
}
|
||||
|
||||
public function supports(Dsn $dsn): bool
|
||||
|
@ -24,7 +24,7 @@ final class SendmailTransportFactory extends AbstractTransportFactory
|
||||
return new SendmailTransport(null, $this->dispatcher, $this->logger);
|
||||
}
|
||||
|
||||
throw new UnsupportedSchemeException($dsn);
|
||||
throw new UnsupportedSchemeException($dsn, ['smtp']);
|
||||
}
|
||||
|
||||
public function supports(Dsn $dsn): bool
|
||||
|
Reference in New Issue
Block a user