Skip to content

Commit

Permalink
Fix invalid references in exception stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 22, 2022
1 parent e3cae6f commit d8cd8ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/ProxyConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ public function connect($uri)

// 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
18 changes: 10 additions & 8 deletions tests/ProxyConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,17 @@ public function testRejectsWithPreviousIfConnectorRejects()

$promise = $proxy->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;
});

$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
return $e->getPrevious() === $previous;
})));
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->assertSame($previous, $exception->getPrevious());
$this->assertNotEquals('', $exception->getTraceAsString());
}

public function testRejectsAndClosesIfStreamWritesNonHttp()
Expand Down

0 comments on commit d8cd8ba

Please sign in to comment.