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

Commit

Permalink
Merge pull request #67 from 1dal/issue/66
Browse files Browse the repository at this point in the history
emit error when secure connection fails before initializeStream()
  • Loading branch information
svpernova09 authored Jul 27, 2018
2 parents 7a05fd0 + b34ac39 commit ca53d50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ protected function addSecureConnection(ConnectionInterface $connection)
function(DuplexStreamInterface $stream) use ($connection) {
$this->initializeStream($stream, $connection);
$this->emit('connect.after.each', array($connection, $connection->getData('write')));
},
function($error) use($connection) {
$this->emitConnectionError($error, $connection);
}
);
}
Expand Down
34 changes: 32 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,33 @@ public function testErrorCallbackResolverReject()
$this->assertSame($logger, $params[2]);
}


/**
* Tests that the client emits an event when a secure connection failed.
*/
public function testErrorCallbackSecureConnectorReject()
{
$connection = $this->getMockConnectionForAddConnection();
Phake::when($connection)->getOption('transport')->thenReturn('ssl');
Phake::when($this->client)->getSecureConnector($connection)->thenReturn($this->getMockSecureConnector(true));

$logger = $this->getMockLogger();
$this->client->setLogger($logger);
$this->client->setLoop($this->getMockLoop());
$this->client->addConnection($connection);

Phake::verify($this->client)->emit('connect.error', Phake::capture($params));
$this->assertInternalType('array', $params);
$this->assertCount(3, $params);
$this->assertSame('Connection failed', $params[0]);
$this->assertSame($connection, $params[1]);
$this->assertSame($logger, $params[2]);

Phake::verify($this->client, Phake::never())->addActiveConnection($connection);
$this->assertSame(array(), $this->client->getActiveConnections());
}


/**
* Tests that the client emits an event when a connection is terminated.
*/
Expand Down Expand Up @@ -920,12 +947,15 @@ protected function getMockResolver($type = 'string', $reject = false)
/**
* Returns a mock secure connector.
*
* @param bool $reject
* @return \React\SocketClient\SecureConnector
*/
protected function getMockSecureConnector()
protected function getMockSecureConnector($reject = false)
{
$connector = Phake::mock('\React\Socket\ConnectorInterface');
$promise = new FakePromiseResolve($this->getMockStream());
$promise = ($reject)
? new FakePromiseReject(new Exception('Connection failed'))
: new FakePromiseResolve($this->getMockStream());
Phake::when($connector)->connect('0.0.0.0' . ':' . $this->port)->thenReturn($promise);
return $connector;
}
Expand Down

0 comments on commit ca53d50

Please sign in to comment.