Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 0b7466d

Browse files
committed
Merge branch 'hotfix/116'
Close #116
2 parents d7e75f2 + c04e4a4 commit 0b7466d

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ All notable changes to this project will be documented in this file, in reverse
2424
transport.
2525
- [#105](https://github.com/zendframework/zend-mail/pull/105) fixes the header
2626
implementation to allow zero (`0`) values for header values.
27+
- [#116](https://github.com/zendframework/zend-mail/pull/116) fixes how the
28+
`AbstractProtocol` handles `stream_socket_client()` errors, ensuring an
29+
exception is thrown with detailed information regarding the failure.
2730

2831
## 2.7.2 - 2016-12-19
2932

src/Protocol/AbstractProtocol.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,14 @@ protected function _connect($remote)
206206
$errorStr = '';
207207

208208
// open connection
209-
$this->socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
209+
set_error_handler(
210+
function ($error, $message = '') {
211+
throw new Exception\RuntimeException(sprintf('Could not open socket: %s', $message), $error);
212+
},
213+
E_WARNING
214+
);
215+
$this->socket = stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
216+
restore_error_handler();
210217

211218
if ($this->socket === false) {
212219
if ($errorNum == 0) {

test/Protocol/SmtpTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,13 @@ public function testDisconnectResetsAuthFlag()
102102
$this->connection->disconnect();
103103
$this->assertFalse($this->connection->getAuth());
104104
}
105+
106+
public function testConnectHasVerboseErrors()
107+
{
108+
$smtp = new TestAsset\ErroneousSmtp();
109+
110+
$this->setExpectedExceptionRegExp('Zend\Mail\Protocol\Exception\RuntimeException', '/nonexistentremote/');
111+
112+
$smtp->connect('nonexistentremote');
113+
}
105114
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-mail for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendTest\Mail\Protocol\TestAsset;
9+
10+
use Zend\Mail\Protocol\AbstractProtocol;
11+
12+
/**
13+
* Expose AbstractProtocol behaviour
14+
*/
15+
final class ErroneousSmtp extends AbstractProtocol
16+
{
17+
public function connect($customRemote = null)
18+
{
19+
return $this->_connect($customRemote);
20+
}
21+
}

0 commit comments

Comments
 (0)