Skip to content

Commit d583891

Browse files
authored
Merge pull request #104 from clue-labs/trace
Fix invalid references in exception stack trace
2 parents f90edf4 + 14500c4 commit d583891

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ function (Exception $e) use ($uri, $deferred) {
200200

201201
// Exception trace arguments are not available on some PHP 7.4 installs
202202
// @codeCoverageIgnoreStart
203-
foreach ($trace as &$one) {
203+
foreach ($trace as $ti => $one) {
204204
if (isset($one['args'])) {
205-
foreach ($one['args'] as &$arg) {
205+
foreach ($one['args'] as $ai => $arg) {
206206
if ($arg instanceof \Closure) {
207-
$arg = 'Object(' . \get_class($arg) . ')';
207+
$trace[$ti]['args'][$ai] = 'Object(' . \get_class($arg) . ')';
208208
}
209209
}
210210
}

tests/ClientTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,17 @@ public function testConnectorRejectsWillRejectConnection()
173173

174174
$promise = $this->client->connect('google.com:80');
175175

176-
$promise->then(null, $this->expectCallableOnceWithException(
177-
'RuntimeException',
178-
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
179-
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
180-
));
176+
$exception = null;
177+
$promise->then(null, function ($reason) use (&$exception) {
178+
$exception = $reason;
179+
});
180+
181+
assert($exception instanceof \RuntimeException);
182+
$this->assertInstanceOf('RuntimeException', $exception);
183+
$this->assertEquals('Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)', $exception->getMessage());
184+
$this->assertEquals(defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111, $exception->getCode());
185+
$this->assertInstanceOf('RuntimeException', $exception->getPrevious());
186+
$this->assertNotEquals('', $exception->getTraceAsString());
181187
}
182188

183189
public function testCancelConnectionDuringConnectionWillCancelConnection()

0 commit comments

Comments
 (0)