Skip to content

Commit d1fb781

Browse files
Merge branch '4.4'
* 4.4: [HttpClient] Fix a bug preventing Server Pushes to be handled properly [HttpClient] fix support for 103 Early Hints and other informational status codes fix typo [DI] fix failure [Validator] Add ConstraintValidator::formatValue() tests [HttpClient] improve handling of HTTP/2 PUSH Fix #33427 lint all templates from configured Twig paths if no argument was provided Nullable message id? [Validator] Only handle numeric values in DivisibleBy [Validator] Sync string to date behavior and throw a better exception Check phpunit configuration for listeners registering basic exception handler for late failures [DI] fix support for "!tagged_locator foo" [Mailer] Add a more precise exception [ErrorHandler][Bridge/PhpUnit] display deprecations for not-autoloaded classes
2 parents fac2d8c + ffc7871 commit d1fb781

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Tests/Transport/TransportsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
1516
use Symfony\Component\Mailer\Transport\TransportInterface;
1617
use Symfony\Component\Mailer\Transport\Transports;
1718
use Symfony\Component\Mime\Header\Headers;
@@ -48,4 +49,19 @@ public function testOverrideTransport()
4849
$email = new Message($headers, new TextPart('...'));
4950
$transport->send($email);
5051
}
52+
53+
public function testTransportDoesNotExist()
54+
{
55+
$transport = new Transports([
56+
'foo' => $this->createMock(TransportInterface::class),
57+
'bar' => $this->createMock(TransportInterface::class),
58+
]);
59+
60+
$headers = (new Headers())->addTextHeader('X-Transport', 'foobar');
61+
$email = new Message($headers, new TextPart('...'));
62+
63+
$this->expectException(InvalidArgumentException::class);
64+
$this->expectExceptionMessage('The "foobar" transport does not exist (available transports: "foo", "bar").');
65+
$transport->send($email);
66+
}
5167
}

Transport/Transports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
5656
$headers->remove('X-Transport');
5757

5858
if (!isset($this->transports[$transport])) {
59-
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist.', $transport));
59+
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist (available transports: "%s").', $transport, implode('", "', array_keys($this->transports))));
6060
}
6161

6262
return $this->transports[$transport]->send($message, $envelope);

Transports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
5656
$headers->remove('X-Transport');
5757

5858
if (!isset($this->transports[$transport])) {
59-
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist.', $transport));
59+
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist (available transports: "%s").', $transport, implode('", "', array_keys($this->transports))));
6060
}
6161

6262
return $this->transports[$transport]->send($message, $envelope);

TransportsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
1516
use Symfony\Component\Mailer\Transport\TransportInterface;
1617
use Symfony\Component\Mailer\Transport\Transports;
1718
use Symfony\Component\Mime\Header\Headers;
@@ -48,4 +49,19 @@ public function testOverrideTransport()
4849
$email = new Message($headers, new TextPart('...'));
4950
$transport->send($email);
5051
}
52+
53+
public function testTransportDoesNotExist()
54+
{
55+
$transport = new Transports([
56+
'foo' => $this->createMock(TransportInterface::class),
57+
'bar' => $this->createMock(TransportInterface::class),
58+
]);
59+
60+
$headers = (new Headers())->addTextHeader('X-Transport', 'foobar');
61+
$email = new Message($headers, new TextPart('...'));
62+
63+
$this->expectException(InvalidArgumentException::class);
64+
$this->expectExceptionMessage('The "foobar" transport does not exist (available transports: "foo", "bar").');
65+
$transport->send($email);
66+
}
5167
}

0 commit comments

Comments
 (0)