Skip to content

Commit 94da388

Browse files
committed
Report proxy connection issues
1 parent 9a7c21d commit 94da388

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public function connect($uri)
160160
return $this->connector->connect($socksUri)->then(
161161
function (ConnectionInterface $stream) use ($that, $host, $port) {
162162
return $that->handleConnectedSocks($stream, $host, $port);
163+
},
164+
function (Exception $e) {
165+
throw new RuntimeException('Unable to connect to proxy (ECONNREFUSED)', defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111, $e);
163166
}
164167
);
165168
}

tests/ClientTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ public function testCreateWithInvalidPortDoesNotConnect()
120120
$this->assertInstanceOf('\React\Promise\PromiseInterface', $promise);
121121
}
122122

123+
public function testConnectorRejectsWillRejectConnection()
124+
{
125+
$promise = \React\Promise\Reject(new RuntimeException());
126+
127+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:1080?hostname=google.com')->willReturn($promise);
128+
129+
$promise = $this->client->connect('google.com:80');
130+
131+
$promise->then(null, $this->expectCallableOnceWithExceptionCode(SOCKET_ECONNREFUSED));
132+
}
133+
123134
public function testCancelConnectionDuringConnectionWillCancelConnection()
124135
{
125136
$promise = new Promise(function () { }, function () {

tests/bootstrap.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ protected function expectCallableNever()
3333
return $mock;
3434
}
3535

36+
protected function expectCallableOnceWithExceptionCode($code)
37+
{
38+
$mock = $this->createCallableMock();
39+
$mock
40+
->expects($this->once())
41+
->method('__invoke')
42+
->with($this->callback(function ($e) use ($code) {
43+
return $e->getCode() === $code;
44+
}));
45+
46+
return $mock;
47+
}
48+
3649
protected function expectCallableOnceParameter($type)
3750
{
3851
$mock = $this->createCallableMock();

0 commit comments

Comments
 (0)