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

Commit

Permalink
Merge branch 'hotfix/116' into develop
Browse files Browse the repository at this point in the history
Forward port #116
  • Loading branch information
weierophinney committed Feb 14, 2017
2 parents fd028bb + c04e4a4 commit dc629d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ All notable changes to this project will be documented in this file, in reverse
transport.
- [#105](https://github.com/zendframework/zend-mail/pull/105) fixes the header
implementation to allow zero (`0`) values for header values.
- [#116](https://github.com/zendframework/zend-mail/pull/116) fixes how the
`AbstractProtocol` handles `stream_socket_client()` errors, ensuring an
exception is thrown with detailed information regarding the failure.

## 2.7.2 - 2016-12-19

Expand Down
9 changes: 8 additions & 1 deletion src/Protocol/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ protected function _connect($remote)
$errorStr = '';

// open connection
$this->socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
set_error_handler(
function ($error, $message = '') {
throw new Exception\RuntimeException(sprintf('Could not open socket: %s', $message), $error);
},
E_WARNING
);
$this->socket = stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
restore_error_handler();

if ($this->socket === false) {
if ($errorNum == 0) {
Expand Down
9 changes: 9 additions & 0 deletions test/Protocol/SmtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ public function testDisconnectResetsAuthFlag()
$this->connection->disconnect();
$this->assertFalse($this->connection->getAuth());
}

public function testConnectHasVerboseErrors()
{
$smtp = new TestAsset\ErroneousSmtp();

$this->setExpectedExceptionRegExp('Zend\Mail\Protocol\Exception\RuntimeException', '/nonexistentremote/');

$smtp->connect('nonexistentremote');
}
}
21 changes: 21 additions & 0 deletions test/Protocol/TestAsset/ErroneousSmtp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* @see https://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Mail\Protocol\TestAsset;

use Zend\Mail\Protocol\AbstractProtocol;

/**
* Expose AbstractProtocol behaviour
*/
final class ErroneousSmtp extends AbstractProtocol
{
public function connect($customRemote = null)
{
return $this->_connect($customRemote);
}
}

0 comments on commit dc629d3

Please sign in to comment.