Bicycle/tests/Unit/StatementTest.php
Egor Isaev 9d4edf147a dev
2026-08-07 11:40:03 +03:00

53 lines
1.5 KiB
PHP

<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use Services\DataBase\Classes\PdoDriver;
use Services\DataBase\Classes\Profiler;
use System\Classes\Config;
use System\Classes\MyException;
class StatementTest extends TestCase
{
private PdoDriver $driver;
protected function setUp(): void
{
$config = Config::get('db', 'default')['connection'] ?? [];
$this->driver = new PdoDriver($config);
try {
$this->driver->pdo();
} catch (MyException $e) {
$this->markTestSkipped('Нет живого подключения к MariaDB (заполните App/config/config.local.php): ' . $e->getMessage());
}
}
protected function tearDown(): void
{
Profiler::reset();
}
public function testShowQuerySubstitutesPositionalParams(): void
{
$statement = $this->driver->query('SELECT ? AS a, ? AS b', ['foo', 42]);
$this->assertSame("SELECT 'foo' AS a, 42 AS b", $statement->showQuery());
}
public function testShowQuerySubstitutesNamedParams(): void
{
$statement = $this->driver->query('SELECT :name AS name', ['name' => 'bicycle']);
$this->assertSame("SELECT 'bicycle' AS name", $statement->showQuery());
}
public function testSqIsAliasForShowQuery(): void
{
$statement = $this->driver->query('SELECT ? AS a', ['foo']);
$this->assertSame($statement->showQuery(), $statement->sq());
}
}