From 14500c47a6c90d7ac52ce0963063af438f8111e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 8 Feb 2022 09:05:28 +0100 Subject: [PATCH] Fix invalid references in exception stack trace --- src/Client.php | 6 +++--- tests/ClientTest.php | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5350b54..83970e6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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) . ')'; } } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 90451fb..e0e3520 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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()