From bd4ad625c2f325cc2c3e9f733d8368f0eb7649ef Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Fri, 13 Nov 2026 16:43:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HttpTransport.php | 3 ++- tests/cases/database.php | 19 +++++++++++++------ tests/run.php | 3 ++- tests/support.php | 12 ++++++++++++ tools/CsvQueryTool.php | 4 +++- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/HttpTransport.php b/src/HttpTransport.php index fdc0edd..1469f7a 100644 --- a/src/HttpTransport.php +++ b/src/HttpTransport.php @@ -167,7 +167,8 @@ final class HttpTransport $status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $errno = curl_errno($ch); $error = curl_error($ch); - curl_close($ch); + // curl_close() не нужен: с PHP 8.0 дескриптор — объект и закрывается + // сам, а в PHP 8.5 вызов объявлен устаревшим. // 23 = CURLE_WRITE_ERROR: это мы сами оборвали слишком большой ответ. if ($errno !== 0 && !($truncated && $errno === 23)) { diff --git a/tests/cases/database.php b/tests/cases/database.php index 4b8e306..66b79db 100644 --- a/tests/cases/database.php +++ b/tests/cases/database.php @@ -7,6 +7,19 @@ declare(strict_types=1); use Rsgrinko\AiSdk\Tools\DatabaseTool; use Rsgrinko\AiSdk\Tools\Support\TextTable; +test('TextTable: кириллица выравнивается по символам', function (): void { + $table = TextTable::render([['город', 'n'], ['Тула', '1'], ['Москва', '22']]); + + assertSame("город | n\n-------+---\nТула | 1\nМосква | 22", $table); +}); + +// Дальше нужен SQLite: без драйвера тесты пропускаются, а не падают. +if (!in_array('sqlite', PDO::getAvailableDrivers(), true)) { + skip('sql_query: 11 тестов', 'нет драйвера pdo_sqlite'); + + return; +} + function demoDb(): PDO { $pdo = new PDO('sqlite::memory:'); @@ -129,9 +142,3 @@ test('sql_query: описание зависит от режима и имени assertContains('INSERT, UPDATE, DELETE', $full->description()); assertSame('billing_sql', $full->name()); }); - -test('TextTable: кириллица выравнивается по символам', function (): void { - $table = TextTable::render([['город', 'n'], ['Тула', '1'], ['Москва', '22']]); - - assertSame("город | n\n-------+---\nТула | 1\nМосква | 22", $table); -}); diff --git a/tests/run.php b/tests/run.php index d80eb7a..e124763 100644 --- a/tests/run.php +++ b/tests/run.php @@ -20,6 +20,7 @@ foreach ($cases as $case) { removeDir(__DIR__ . '/tmp'); -echo PHP_EOL . 'пройдено: ' . $passed . ', провалено: ' . $failed . PHP_EOL; +echo PHP_EOL . 'пройдено: ' . $passed . ', провалено: ' . $failed + . ($skipped > 0 ? ', пропущено: ' . $skipped : '') . PHP_EOL; exit($failed === 0 ? 0 : 1); diff --git a/tests/support.php b/tests/support.php index 6f5e91e..11e4366 100644 --- a/tests/support.php +++ b/tests/support.php @@ -23,6 +23,18 @@ mb_internal_encoding('UTF-8'); $passed = 0; $failed = 0; +$skipped = 0; + +/** + * Пропустить тест, которому не хватает окружения (драйвера, расширения). + */ +function skip(string $name, string $reason): void +{ + global $skipped; + + $skipped++; + echo 'skip ' . $name . ' — ' . $reason . PHP_EOL; +} function test(string $name, callable $fn): void { diff --git a/tools/CsvQueryTool.php b/tools/CsvQueryTool.php index bf25246..553324a 100644 --- a/tools/CsvQueryTool.php +++ b/tools/CsvQueryTool.php @@ -119,7 +119,9 @@ final class CsvQueryTool implements Tool $rows = []; - while (($row = fgetcsv($handle, 0, $delimiter)) !== false) { + // enclosure и escape — явно: в PHP 8.4+ без escape предупреждение + // (значение по умолчанию поменяется). Поведение прежнее. + while (($row = fgetcsv($handle, 0, $delimiter, '"', '\\')) !== false) { $rows[] = array_map(static fn ($cell): string => trim((string) $cell), $row); }