diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6c9f3a..3c06e158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Telegram Bot API for PHP Change Log +## 0.18.2 under construction + +- Enh #194: Remove deprecated `curl_close()` call in `CurlTransport`. + ## 0.18.1 April 5, 2026 - Bug #192: Add missed `certificate` parameter to `SetWebhook` method. diff --git a/composer.json b/composer.json index 84a9a216..f2d901d6 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "infection": "infection --threads=max", "psalm": "psalm", "rector": "rector", - "test": "phpunit", + "test": "phpunit --display-deprecations", "test-real": "phpunit --group=realApi" } } diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index ab03f25b..db02ae57 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -7,7 +7,6 @@ use CurlHandle; use CurlShareHandle; -use function curl_close; use function curl_errno; use function curl_error; use function curl_exec; @@ -21,11 +20,6 @@ */ final class Curl implements CurlInterface { - public function close(CurlHandle $handle): void - { - curl_close($handle); - } - public function exec(CurlHandle $handle): ?string { $result = curl_exec($handle); diff --git a/src/Curl/CurlInterface.php b/src/Curl/CurlInterface.php index 995f0d42..88db64f9 100644 --- a/src/Curl/CurlInterface.php +++ b/src/Curl/CurlInterface.php @@ -12,8 +12,6 @@ */ interface CurlInterface { - public function close(CurlHandle $handle): void; - /** * @throws CurlException */ diff --git a/src/Transport/CurlTransport.php b/src/Transport/CurlTransport.php index 9eb93c0f..b95bfeaf 100644 --- a/src/Transport/CurlTransport.php +++ b/src/Transport/CurlTransport.php @@ -101,8 +101,6 @@ public function downloadFile(string $url): mixed $this->curl->exec($curl); } catch (CurlException $exception) { throw new DownloadFileException($exception->getMessage(), previous: $exception); - } finally { - $this->curl->close($curl); } rewind($stream); @@ -117,20 +115,16 @@ private function send(array $options): ApiResponse $curl = $this->curl->init(); - try { - $this->curl->setopt_array($curl, $options); + $this->curl->setopt_array($curl, $options); + + /** + * @var string $body `curl_exec` returns string because `CURLOPT_RETURNTRANSFER` is set to `true`. + */ + $body = $this->curl->exec($curl); - /** - * @var string $body `curl_exec` returns string because `CURLOPT_RETURNTRANSFER` is set to `true`. - */ - $body = $this->curl->exec($curl); - - $statusCode = $this->curl->getinfo($curl, CURLINFO_HTTP_CODE); - if (!is_int($statusCode)) { - $statusCode = 0; - } - } finally { - $this->curl->close($curl); + $statusCode = $this->curl->getinfo($curl, CURLINFO_HTTP_CODE); + if (!is_int($statusCode)) { + $statusCode = 0; } return new ApiResponse($statusCode, $body); diff --git a/tests/Curl/CurlMock.php b/tests/Curl/CurlMock.php index 719817ae..9fc58f1f 100644 --- a/tests/Curl/CurlMock.php +++ b/tests/Curl/CurlMock.php @@ -16,7 +16,6 @@ final class CurlMock implements CurlInterface { private ?array $options = null; private array $shareOptions = []; - private int $countCallOfClose = 0; public function __construct( private readonly string|Throwable $execResult = '', @@ -24,11 +23,6 @@ public function __construct( private readonly ?Throwable $initException = null, ) {} - public function close(CurlHandle $handle): void - { - $this->countCallOfClose++; - } - public function exec(CurlHandle $handle): string { if ($this->execResult instanceof Throwable) { @@ -74,9 +68,4 @@ public function getShareOptions(): array { return $this->shareOptions; } - - public function getCountCallOfClose(): int - { - return $this->countCallOfClose; - } } diff --git a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php index 2ac683d2..990d5eba 100644 --- a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php +++ b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php @@ -6,7 +6,6 @@ use CurlShareHandle; use PHPUnit\Framework\TestCase; -use RuntimeException; use Throwable; use Phptg\BotApi\Curl\CurlException; use Phptg\BotApi\Tests\Curl\CurlMock; @@ -71,17 +70,4 @@ public function testExecException(): void assertSame('test', $exception->getMessage()); assertSame($execException, $exception->getPrevious()); } - - public function testCloseOnException(): void - { - $curl = new CurlMock(new RuntimeException()); - $transport = new CurlTransport(curl: $curl); - - try { - $transport->downloadFile('https://example.test/hello.jpg'); - } catch (Throwable) { - } - - assertSame(1, $curl->getCountCallOfClose()); - } } diff --git a/tests/Transport/CurlTransport/CurlTransportTest.php b/tests/Transport/CurlTransport/CurlTransportTest.php index 0d7b6873..8a9db0be 100644 --- a/tests/Transport/CurlTransport/CurlTransportTest.php +++ b/tests/Transport/CurlTransport/CurlTransportTest.php @@ -7,8 +7,6 @@ use CurlShareHandle; use CURLStringFile; use PHPUnit\Framework\TestCase; -use RuntimeException; -use Throwable; use Phptg\BotApi\Tests\Curl\CurlMock; use Phptg\BotApi\Transport\CurlTransport; use Phptg\BotApi\Type\InputFile; @@ -158,19 +156,6 @@ public function testSeekableResource(): void ); } - public function testCloseOnException(): void - { - $curl = new CurlMock(new RuntimeException()); - $transport = new CurlTransport(curl: $curl); - - try { - $transport->get('getMe'); - } catch (Throwable) { - } - - assertSame(1, $curl->getCountCallOfClose()); - } - public function testShareOptions(): void { $curl = new CurlMock(