Skip to content

Commit

Permalink
CurlReqRes::__destruct - capture curl_close error
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Jul 5, 2024
1 parent 244b2e6 commit f04acb2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
20 changes: 10 additions & 10 deletions src/CurlHttpMessage/CurlReqRes.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ public function __construct(RequestInterface $request, callable $responseFactory
*/
public function __destruct()
{
if (\is_resource($this->curlHandle) && \get_resource_type($this->curlHandle) === 'Unknown') {
// already closed
$this->curlHandle = null;
if (!$this->curlHandle) {
return;
}
if ($this->curlHandle) {
try {
\curl_close($this->curlHandle);
} catch (ErrorException $e) {
// ignore exception
}
$this->curlHandle = null;
\set_error_handler(function ($type, $message) {
// ignore error
});
try {
\curl_close($this->curlHandle);
} catch (ErrorException $e) {
// ignore exception
}
\restore_error_handler();
$this->curlHandle = null;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions tests/Backtrace/NormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ public function testNormalize()

public function testNormalizeInclude()
{
$GLOBALS['gautf'] = true;
$filepath = __DIR__ . '/Fixture/include.php';
require $filepath;

$this->assertIncludeDebugBacktrace($filepath);
$this->assertIncludeXdebug($filepath);
$GLOBALS['gautf'] = false;
}

protected function assertIncludeDebugBacktrace($filepath)
Expand Down Expand Up @@ -111,9 +109,7 @@ protected function assertIncludeDebugBacktrace($filepath)
protected function assertIncludeXdebug($filepath)
{
$trace = \array_reverse($GLOBALS['xdebug_trace']);
empty($GLOBALS['gautf']) || var_dump(\array_slice($trace, 0, 8));
$trace = Normalizer::normalize($trace);
empty($GLOBALS['gautf']) || var_dump(\array_slice($trace, 0, 8));

self::assertSame($filepath, $trace[0]['file']);
self::assertSame('bdk\\Backtrace\\Xdebug::getFunctionStack', $trace[0]['function']);
Expand Down
15 changes: 1 addition & 14 deletions tests/Debug/Collector/GuzzleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,6 @@ public function testAsynchronous()
'channel' => 'general.Guzzle',
),
),
/*
3 => array(
'method' => 'log',
'args' => array(
'request body',
null,
),
'meta' => array(
'redact' => true,
'channel' => 'general.Guzzle',
),
),
*/
3 => array(
'method' => 'groupEnd',
'args' => array(),
Expand Down Expand Up @@ -280,7 +267,7 @@ public function testAsynchronous()
),
);
$this->assertSame($expect, $messages);
}
},
));
}

Expand Down
9 changes: 7 additions & 2 deletions tests/ErrorHandler/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public function tearTown(): void
$this->errorHandler->eventManager->unsubscribe(ErrorHandler::EVENT_ERROR, array($this, 'onError'));
}

public static function tearDownAfterClass(): void
{
foreach (self::$subscribersBackup as $subscriberInfo) {
ErrorHandler::getInstance()->eventManager->subscribe(ErrorHandler::EVENT_ERROR, $subscriberInfo['callable'], $subscriberInfo['priority']);
}
}

public function onError(Error $error)
{
foreach ($this->onErrorUpdate as $k => $v) {
Expand All @@ -110,8 +117,6 @@ public function onError(Error $error)
}
$error['continueToPrevHandler'] = true;
$error['throw'] = true;


}

public function emailMock($to, $subject, $body, $addHeadersStr)
Expand Down

0 comments on commit f04acb2

Please sign in to comment.