nur-sery/tests/db/sqlite/_queryTest.php

87 lines
3.2 KiB
PHP
Raw Normal View History

2024-05-09 11:33:53 +04:00
<?php
namespace nur\sery\db\sqlite;
use PHPUnit\Framework\TestCase;
2024-05-18 13:09:01 +04:00
class _queryTest extends TestCase {
2024-05-09 11:33:53 +04:00
function testParseConds(): void {
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds(null, $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertNull($sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds([], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertNull($sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds(["col = 'value'"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["col = 'value'"], $sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds([["col = 'value'"]], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["col = 'value'"], $sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds(["int" => 42, "string" => "value"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["(int = :int and string = :string)"], $sql);
self::assertSame(["int" => 42, "string" => "value"], $params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds(["or", "int" => 42, "string" => "value"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["(int = :int or string = :string)"], $sql);
self::assertSame(["int" => 42, "string" => "value"], $params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds([["int" => 42, "string" => "value"], ["int" => 24, "string" => "eulav"]], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["((int = :int and string = :string) and (int = :int1 and string = :string1))"], $sql);
self::assertSame(["int" => 42, "string" => "value", "int1" => 24, "string1" => "eulav"], $params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_conds(["int" => ["is null"], "string" => ["<>", "value"]], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["(int is null and string <> :string)"], $sql);
self::assertSame(["string" => "value"], $params);
}
function testParseValues(): void {
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values(null, $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertNull($sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values([], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertNull($sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values(["col = 'value'"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["col = 'value'"], $sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values([["col = 'value'"]], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["col = 'value'"], $sql);
self::assertNull($params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values(["int" => 42, "string" => "value"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["int = :int", "string = :string"], $sql);
self::assertSame(["int" => 42, "string" => "value"], $params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values(["int" => 42, "string" => "value"], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["int = :int", "string = :string"], $sql);
self::assertSame(["int" => 42, "string" => "value"], $params);
$sql = $params = null;
2024-05-15 21:11:05 +04:00
_query::parse_set_values([["int" => 42, "string" => "value"], ["int" => 24, "string" => "eulav"]], $sql, $params);
2024-05-09 11:33:53 +04:00
self::assertSame(["int = :int", "string = :string", "int = :int1", "string = :string1"], $sql);
self::assertSame(["int" => 42, "string" => "value", "int1" => 24, "string1" => "eulav"], $params);
}
}