Skip to content

Commit b2c840d

Browse files
Merge branch '5.4' into 6.4
* 5.4: [VarDumper] Fix test suite with PHP 8.4 [DoctrineBridge] Add missing return type [Mailer] Fix sendmail transport not handling failure [HttpClient] Lazily initialize CurlClientState updating missing translations for Greek #53768 [Validator] Allow BICs’ first four characters to be digits [ErrorHandler] Fix exit code when an exception occurs and the exception handler has been unregistered [Validator] Review Arabic translations and add correct translations.
2 parents 791c5d3 + b8ff9a7 commit b2c840d

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env php
2+
<?php
3+
print "Sending failed";
4+
exit(42);

Tests/Transport/SendmailTransportTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Mailer\DelayedEnvelope;
16+
use Symfony\Component\Mailer\Exception\TransportException;
1617
use Symfony\Component\Mailer\Transport\SendmailTransport;
1718
use Symfony\Component\Mime\Address;
1819
use Symfony\Component\Mime\Email;
1920

2021
class SendmailTransportTest extends TestCase
2122
{
2223
private const FAKE_SENDMAIL = __DIR__.'/Fixtures/fake-sendmail.php -t';
24+
private const FAKE_FAILING_SENDMAIL = __DIR__.'/Fixtures/fake-failing-sendmail.php -t';
2325

2426
private string $argsPath;
2527

@@ -86,4 +88,27 @@ public function testRecipientsAreUsedWhenSet()
8688

8789
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php -ffrom@mail.com recipient@mail.com');
8890
}
91+
92+
public function testThrowsTransportExceptionOnFailure()
93+
{
94+
if ('\\' === \DIRECTORY_SEPARATOR) {
95+
$this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
96+
}
97+
98+
$mail = new Email();
99+
$mail
100+
->from('from@mail.com')
101+
->to('to@mail.com')
102+
->subject('Subject')
103+
->text('Some text')
104+
;
105+
106+
$envelope = new DelayedEnvelope($mail);
107+
$envelope->setRecipients([new Address('recipient@mail.com')]);
108+
109+
$sendmailTransport = new SendmailTransport(self::FAKE_FAILING_SENDMAIL);
110+
$this->expectException(TransportException::class);
111+
$this->expectExceptionMessage('Process failed with exit code 42: Sending failed');
112+
$sendmailTransport->send($mail, $envelope);
113+
}
89114
}

Transport/Smtp/Stream/AbstractStream.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ abstract class AbstractStream
3030
protected $in;
3131
/** @var resource|null */
3232
protected $out;
33+
protected $err;
3334

3435
private string $debug = '';
3536

@@ -68,7 +69,7 @@ abstract public function initialize(): void;
6869

6970
public function terminate(): void
7071
{
71-
$this->stream = $this->out = $this->in = null;
72+
$this->stream = $this->err = $this->out = $this->in = null;
7273
}
7374

7475
public function readLine(): string

Transport/Smtp/Stream/ProcessStream.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ public function initialize(): void
4545
}
4646
$this->in = &$pipes[0];
4747
$this->out = &$pipes[1];
48+
$this->err = &$pipes[2];
4849
}
4950

5051
public function terminate(): void
5152
{
5253
if (null !== $this->stream) {
5354
fclose($this->in);
55+
$out = stream_get_contents($this->out);
5456
fclose($this->out);
55-
proc_close($this->stream);
57+
$err = stream_get_contents($this->err);
58+
fclose($this->err);
59+
if (0 !== $exitCode = proc_close($this->stream)) {
60+
throw new TransportException('Process failed with exit code '.$exitCode.': '.$out.$err);
61+
}
5662
}
5763

5864
parent::terminate();

0 commit comments

Comments
 (0)