[Mailer] Add a more precise exception
This commit is contained in:
parent
cf57ca81ee
commit
561f9b7345
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Mailer\Tests\Transport;
|
namespace Symfony\Component\Mailer\Tests\Transport;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||||
use Symfony\Component\Mailer\Transport\Transports;
|
use Symfony\Component\Mailer\Transport\Transports;
|
||||||
use Symfony\Component\Mime\Header\Headers;
|
use Symfony\Component\Mime\Header\Headers;
|
||||||
@ -48,4 +49,19 @@ class TransportsTest extends TestCase
|
|||||||
$email = new Message($headers, new TextPart('...'));
|
$email = new Message($headers, new TextPart('...'));
|
||||||
$transport->send($email);
|
$transport->send($email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransportDoesNotExist()
|
||||||
|
{
|
||||||
|
$transport = new Transports([
|
||||||
|
'foo' => $this->createMock(TransportInterface::class),
|
||||||
|
'bar' => $this->createMock(TransportInterface::class),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$headers = (new Headers())->addTextHeader('X-Transport', 'foobar');
|
||||||
|
$email = new Message($headers, new TextPart('...'));
|
||||||
|
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('The "foobar" transport does not exist (available transports: "foo", "bar").');
|
||||||
|
$transport->send($email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class Transports implements TransportInterface
|
|||||||
$headers->remove('X-Transport');
|
$headers->remove('X-Transport');
|
||||||
|
|
||||||
if (!isset($this->transports[$transport])) {
|
if (!isset($this->transports[$transport])) {
|
||||||
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist.', $transport));
|
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist (available transports: "%s").', $transport, implode('", "', array_keys($this->transports))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->transports[$transport]->send($message, $envelope);
|
return $this->transports[$transport]->send($message, $envelope);
|
||||||
|
Reference in New Issue
Block a user