|
12 | 12 | namespace Symfony\Component\Mailer\Tests\Transport;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Mailer\DelayedEnvelope; |
15 | 16 | use Symfony\Component\Mailer\Transport\SendmailTransport;
|
| 17 | +use Symfony\Component\Mime\Address; |
| 18 | +use Symfony\Component\Mime\Email; |
16 | 19 |
|
17 | 20 | class SendmailTransportTest extends TestCase
|
18 | 21 | {
|
| 22 | + private const FAKE_SENDMAIL = __DIR__.'/Fixtures/fake-sendmail.php -t'; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var string |
| 26 | + */ |
| 27 | + private $argsPath; |
| 28 | + |
| 29 | + protected function setUp(): void |
| 30 | + { |
| 31 | + $this->argsPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'sendmail_args'; |
| 32 | + } |
| 33 | + |
| 34 | + protected function tearDown(): void |
| 35 | + { |
| 36 | + if (file_exists($this->argsPath)) { |
| 37 | + @unlink($this->argsPath); |
| 38 | + } |
| 39 | + unset($this->argsPath); |
| 40 | + } |
| 41 | + |
19 | 42 | public function testToString()
|
20 | 43 | {
|
21 | 44 | $t = new SendmailTransport();
|
22 | 45 | $this->assertEquals('smtp://sendmail', (string) $t);
|
23 | 46 | }
|
| 47 | + |
| 48 | + public function testToIsUsedWhenRecipientsAreNotSet() |
| 49 | + { |
| 50 | + if ('\\' === \DIRECTORY_SEPARATOR) { |
| 51 | + $this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams'); |
| 52 | + } |
| 53 | + |
| 54 | + $mail = new Email(); |
| 55 | + $mail |
| 56 | + |
| 57 | + |
| 58 | + ->subject('Subject') |
| 59 | + ->text('Some text') |
| 60 | + ; |
| 61 | + |
| 62 | + $envelope = new DelayedEnvelope($mail); |
| 63 | + |
| 64 | + $sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL); |
| 65 | + $sendmailTransport->send($mail, $envelope); |
| 66 | + |
| 67 | + $this-> assertStringEqualsFile( $this-> argsPath, __DIR__. '/Fixtures/fake-sendmail.php [email protected] [email protected]'); |
| 68 | + } |
| 69 | + |
| 70 | + public function testRecipientsAreUsedWhenSet() |
| 71 | + { |
| 72 | + if ('\\' === \DIRECTORY_SEPARATOR) { |
| 73 | + $this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams'); |
| 74 | + } |
| 75 | + |
| 76 | + $mail = new Email(); |
| 77 | + $mail |
| 78 | + |
| 79 | + |
| 80 | + ->subject('Subject') |
| 81 | + ->text('Some text') |
| 82 | + ; |
| 83 | + |
| 84 | + $envelope = new DelayedEnvelope($mail); |
| 85 | + $envelope-> setRecipients([ new Address( '[email protected]')]); |
| 86 | + |
| 87 | + $sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL); |
| 88 | + $sendmailTransport->send($mail, $envelope); |
| 89 | + |
| 90 | + $this-> assertStringEqualsFile( $this-> argsPath, __DIR__. '/Fixtures/fake-sendmail.php [email protected] [email protected]'); |
| 91 | + } |
24 | 92 | }
|
0 commit comments