8000 Fix invalid references in exception stack trace · clue/reactphp-http-proxy@d8cd8ba · GitHub
[go: up one dir, main page]

Skip to content

Commit d8cd8ba

Browse files
committed
Fix invalid references in exception stack trace
1 parent e3cae6f commit d8cd8ba

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/ProxyConnector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ public function connect($uri)
256256

257257
// Exception trace arguments are not available on some PHP 7.4 installs
258258
// @codeCoverageIgnoreStart
259-
foreach ($trace as &$one) {
259+
foreach ($trace as $ti => $one) {
260260
if (isset($one['args'])) {
261-
foreach ($one['args'] as &$arg) {
261+
foreach ($one['args'] as $ai => $arg) {
262262
if ($arg instanceof \Closure) {
263-
$arg = 'Object(' . get_class($arg) . ')';
263+
$trace[$ti]['args'][$ai] = 'Object(' . get_class($arg) . ')';
264264
}
265265
}
266266
}

tests/ProxyConnectorTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,17 @@ public function testRejectsWithPreviousIfConnectorRejects()
302302

303303
$promise = $proxy->connect('google.com:80');
304304

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

311-
$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
312-
return $e->getPrevious() === $previous;
313-
})));
310+
assert($exception instanceof \RuntimeException);
311+
$this->assertInstanceOf('RuntimeException', $exception);
312+
$this->assertEquals('Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)', $exception->getMessage());
313+
$this->assertEquals(defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111, $exception->getCode());
314+
$this->assertSame($previous, $exception->getPrevious());
315+
$this->assertNotEquals('', $exception->getTraceAsString());
314316
}
315317

316318
public function testRejectsAndClosesIfStreamWritesNonHttp()

0 commit comments

Comments
 (0)
0