diff --git a/src/ProxyConnector.php b/src/ProxyConnector.php index 0bca17e..a3dc166 100644 --- a/src/ProxyConnector.php +++ b/src/ProxyConnector.php @@ -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) . ')'; } } } diff --git a/tests/ProxyConnectorTest.php b/tests/ProxyConnectorTest.php index 6272d6a..59fc466 100644 --- a/tests/ProxyConnectorTest.php +++ b/tests/ProxyConnectorTest.php @@ -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()