Bicycle/tests/Unit/StatementTest.php
Egor Isaev 69ce89a695 dev
2026-08-11 17:05:39 +03:00

53 lines
1.5 KiB
PHP

<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use Services\DataBase\Classes\PdoConnection;
use Services\DataBase\Classes\Profiler;
use System\Classes\Config;
use System\Classes\MyException;
class StatementTest extends TestCase
{
private PdoConnection $connection;
protected function setUp(): void
{
$config = Config::get('db', 'default') ?? [];
$this->connection = new PdoConnection($config);
try {
$this->connection->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->connection->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->connection->query('SELECT :name AS name', ['name' => 'bicycle']);
$this->assertSame("SELECT 'bicycle' AS name", $statement->showQuery());
}
public function testSqIsAliasForShowQuery(): void
{
$statement = $this->connection->query('SELECT ? AS a', ['foo']);
$this->assertSame($statement->showQuery(), $statement->sq());
}
}