Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb15bff

Browse files
committed
[Mailer] fixed error message when connecting to a stream raises an error before connect()
1 parent791a212 commiteb15bff

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
namespaceSymfony\Component\Mailer\Tests\Transport\Smtp\Stream;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
16+
17+
class SocketStreamTestextends TestCase
18+
{
19+
/**
20+
* @expectedException \Symfony\Component\Mailer\Exception\TransportException
21+
* @expectedExceptionMessage Connection refused
22+
*/
23+
publicfunctiontestSocketErrorNoConnection()
24+
{
25+
$s =newSocketStream();
26+
$s->setTimeout(0.1);
27+
$s->setPort(9999);
28+
$s->initialize();
29+
}
30+
31+
/**
32+
* @expectedException \Symfony\Component\Mailer\Exception\TransportException
33+
* @expectedExceptionMessage no valid certs found cafile stream
34+
*/
35+
publicfunctiontestSocketErrorBeforeConnectError()
36+
{
37+
$s =newSocketStream();
38+
$s->setStreamOptions([
39+
'ssl' => [
40+
// not a CA file :)
41+
'cafile' =>__FILE__,
42+
],
43+
]);
44+
$s->setEncryption('ssl');
45+
$s->setHost('smtp.gmail.com');
46+
$s->setPort(465);
47+
$s->initialize();
48+
}
49+
}

‎src/Symfony/Component/Mailer/Transport/Smtp/Stream/SocketStream.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,16 @@ public function initialize(): void
144144
$options['ssl']['crypto_method'] =$options['ssl']['crypto_method'] ??STREAM_CRYPTO_METHOD_TLS_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
145145
}
146146
$streamContext =stream_context_create($options);
147-
$this->stream = @stream_socket_client($this->url,$errno,$errstr,$this->timeout,STREAM_CLIENT_CONNECT,$streamContext);
148-
if (false ===$this->stream) {
149-
thrownewTransportException(sprintf('Connection could not be established with host "%s": %s (%s)',$this->url,$errstr,$errno));
147+
148+
set_error_handler(function ($type,$msg) {
149+
thrownewTransportException(sprintf('Connection could not be established with host "%s": %s.',$this->url,$msg));
150+
});
151+
try {
152+
$this->stream =stream_socket_client($this->url,$errno,$errstr,$this->timeout,STREAM_CLIENT_CONNECT,$streamContext);
153+
}finally {
154+
restore_error_handler();
150155
}
156+
151157
stream_set_blocking($this->stream,true);
152158
stream_set_timeout($this->stream,$this->timeout);
153159
$this->in = &$this->stream;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp