minor #33433 [Mailer] Add a more precise exception (fabpot)
This PR was merged into the 4.4 branch.
Discussion
----------
[Mailer] Add a more precise exception
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.
Additionally (see https://symfony.com/roadmap):
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against branch 4.4.
- Legacy code removals go to the master branch.
-->
Commits
-------
561f9b7345
[Mailer] Add a more precise exception
This commit is contained in:
commit
e69336feed
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Mailer\Tests\Transport;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||
use Symfony\Component\Mailer\Transport\Transports;
|
||||
use Symfony\Component\Mime\Header\Headers;
|
||||
@ -48,4 +49,19 @@ class TransportsTest extends TestCase
|
||||
$email = new Message($headers, new TextPart('...'));
|
||||
$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');
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user