Skip to content

Commit

Permalink
Merge pull request #104 from clue-labs/trace
Browse files Browse the repository at this point in the history
Fix invalid references in exception stack trace
  • Loading branch information
SimonFrings authored Feb 8, 2022
2 parents f90edf4 + 14500c4 commit d583891
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ function (Exception $e) use ($uri, $deferred) {

// Exception trace arguments are not available on some PHP 7.4 installs
// @codeCoverageIgnoreStart
foreach ($trace as &$one) {
foreach ($trace as $ti => $one) {
if (isset($one['args'])) {
foreach ($one['args'] as &$arg) {
foreach ($one['args'] as $ai => $arg) {
if ($arg instanceof \Closure) {
$arg = 'Object(' . \get_class($arg) . ')';
$trace[$ti]['args'][$ai] = 'Object(' . \get_class($arg) . ')';
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ public function testConnectorRejectsWillRejectConnection()

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

$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
));
$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
$exception = $reason;
});

assert($exception instanceof \RuntimeException);
$this->assertInstanceOf('RuntimeException', $exception);
$this->assertEquals('Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)', $exception->getMessage());
$this->assertEquals(defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111, $exception->getCode());
$this->assertInstanceOf('RuntimeException', $exception->getPrevious());
$this->assertNotEquals('', $exception->getTraceAsString());
}

public function testCancelConnectionDuringConnectionWillCancelConnection()
Expand Down

0 comments on commit d583891

Please sign in to comment.