-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP][Mailer] Overwrite envelope sender and recipients from config
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Mailer\Mailer; | ||
use Symfony\Component\Mailer\SentMessage; | ||
use Symfony\Component\Mailer\Transport\AbstractTransport; | ||
use Symfony\Component\Mime\Address; | ||
use Symfony\Component\Mime\Email; | ||
|
||
class MailerTest extends WebTestCase | ||
{ | ||
public function testEnvelopeListener() | ||
{ | ||
self::bootKernel(['test_case' => 'Mailer']); | ||
|
||
$onDoSend = function (SentMessage $message) { | ||
$envelope = $message->getEnvelope(); | ||
|
||
$this->assertEquals( | ||
[new Address('redirected@example.org')], | ||
$envelope->getRecipients() | ||
); | ||
|
||
$this->assertEquals('sender@example.org', $envelope->getSender()->getAddress()); | ||
}; | ||
|
||
$eventDispatcher = self::$container->get(EventDispatcherInterface::class); | ||
$logger = self::$container->get('logger'); | ||
|
||
$testTransport = new class($eventDispatcher, $logger, $onDoSend) extends AbstractTransport { | ||
/** | ||
* @var callable | ||
*/ | ||
private $onDoSend; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, callable $onDoSend) | ||
{ | ||
parent::__construct($eventDispatcher, $logger); | ||
$this->onDoSend = $onDoSend; | ||
} | ||
|
||
protected function doSend(SentMessage $message): void | ||
{ | ||
$onDoSend = $this->onDoSend; | ||
$onDoSend($message); | ||
} | ||
}; | ||
|
||
$mailer = new Mailer($testTransport, null); | ||
|
||
$message = (new Email()) | ||
->subject('Test subject') | ||
->text('Hello world') | ||
->from('from@example.org') | ||
->to('to@example.org'); | ||
|
||
$mailer->send($message); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Mailer/bundles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; | ||
|
||
return [ | ||
new FrameworkBundle(), | ||
new TestBundle(), | ||
]; |
9 changes: 9 additions & 0 deletions
9
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Mailer/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
imports: | ||
- { resource: ../config/default.yml } | ||
|
||
framework: | ||
mailer: | ||
envelope: | ||
sender: sender@example.org | ||
recipients: | ||
- redirected@example.org |