Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"infection": "infection --threads=max",
"psalm": "psalm",
"rector": "rector",
"test": "phpunit",
"test": "phpunit --display-deprecations",
"test-real": "phpunit --group=realApi"
}
}
6 changes: 0 additions & 6 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use CurlHandle;
use CurlShareHandle;

use function curl_close;
use function curl_errno;
use function curl_error;
use function curl_exec;
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/Curl/CurlInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
interface CurlInterface
{
public function close(CurlHandle $handle): void;

/**
* @throws CurlException
*/
Expand Down
24 changes: 9 additions & 15 deletions src/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions tests/Curl/CurlMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ final class CurlMock implements CurlInterface
{
private ?array $options = null;
private array $shareOptions = [];
private int $countCallOfClose = 0;

public function __construct(
private readonly string|Throwable $execResult = '',
private readonly array $getinfoResult = [],
private readonly ?Throwable $initException = null,
) {}

public function close(CurlHandle $handle): void
{
$this->countCallOfClose++;
}

public function exec(CurlHandle $handle): string
{
if ($this->execResult instanceof Throwable) {
Expand Down Expand Up @@ -74,9 +68,4 @@ public function getShareOptions(): array
{
return $this->shareOptions;
}

public function getCountCallOfClose(): int
{
return $this->countCallOfClose;
}
}
14 changes: 0 additions & 14 deletions tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
15 changes: 0 additions & 15 deletions tests/Transport/CurlTransport/CurlTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Loading