Skip to content

Commit 5e1274d

Browse files
committed
[Mailer] fixed wrong behavior
1 parent dcdfc88 commit 5e1274d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

Tests/Transport/TransportsTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Transport\TransportInterface;
16+
use Symfony\Component\Mailer\Transport\Transports;
17+
use Symfony\Component\Mime\Header\Headers;
18+
use Symfony\Component\Mime\Message;
19+
use Symfony\Component\Mime\Part\TextPart;
20+
21+
class TransportsTest extends TestCase
22+
{
23+
public function testDefaultTransport()
24+
{
25+
$transport = new Transports([
26+
'foo' => $foo = $this->createMock(TransportInterface::class),
27+
'bar' => $bar = $this->createMock(TransportInterface::class),
28+
]);
29+
30+
$foo->expects($this->once())->method('send');
31+
$bar->expects($this->never())->method('send');
32+
33+
$email = new Message(new Headers(), new TextPart('...'));
34+
$transport->send($email);
35+
}
36+
37+
public function testOverrideTransport()
38+
{
39+
$transport = new Transports([
40+
'foo' => $foo = $this->createMock(TransportInterface::class),
41+
'bar' => $bar = $this->createMock(TransportInterface::class),
42+
]);
43+
44+
$foo->expects($this->never())->method('send');
45+
$bar->expects($this->once())->method('send');
46+
47+
$headers = (new Headers())->addTextHeader('X-Transport', 'bar');
48+
$email = new Message($headers, new TextPart('...'));
49+
$transport->send($email);
50+
}
51+
}

Transport/Transports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
5252
}
5353

5454
$headers = $message->getHeaders();
55-
$transport = $headers->get('X-Transport');
55+
$transport = $headers->get('X-Transport')->getBody();
5656
$headers->remove('X-Transport');
5757

5858
if (!isset($this->transports[$transport])) {

0 commit comments

Comments
 (0)