2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
namespace Test\Unit;
|
|
|
|
|
|
|
|
use BitBadger\PDODocument\{Configuration, Field, Mode, Op};
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Field class
|
|
|
|
*/
|
2024-06-21 13:46:41 +00:00
|
|
|
#[TestDox('Field (Unit tests)')]
|
2024-06-08 23:58:45 +00:00
|
|
|
class FieldTest extends TestCase
|
|
|
|
{
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for exists')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testAppendParameterSucceedsForExists(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals([], Field::exists('exists')->appendParameter([]),
|
|
|
|
'exists should not have appended a parameter');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for notExists')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testAppendParameterSucceedsForNotExists(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals([], Field::notExists('absent')->appendParameter([]),
|
|
|
|
'notExists should not have appended a parameter');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for between')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testAppendParameterSucceedsForBetween(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(['@nummin' => 5, '@nummax' => 9],
|
|
|
|
Field::between('exists', 5, 9, '@num')->appendParameter([]),
|
2024-09-22 21:44:07 +00:00
|
|
|
'Between should have appended min and max parameters');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for in')]
|
|
|
|
public function testAppendParameterSucceedsForIn(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals([':val_0' => 'test', ':val_1' => 'unit', ':val_2' => 'great'],
|
|
|
|
Field::in('it', ['test', 'unit', 'great'], ':val')->appendParameter([]),
|
|
|
|
'In should have appended 3 parameters for the input values');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('appendParameter() succeeds for inArray for PostgreSQL')]
|
|
|
|
public function testAppendParameterSucceedsForInArrayForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$this->assertEquals([':bit_0' => '2', ':bit_1' => '8', ':bit_2' => '64'],
|
|
|
|
Field::inArray('it', 'table', [2, 8, 64], ':bit')->appendParameter([]),
|
|
|
|
'InArray should have appended 3 string parameters for the input values');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('appendParameter() succeeds for inArray for SQLite')]
|
|
|
|
public function testAppendParameterSucceedsForInArrayForSQLite(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals([':bit_0' => 2, ':bit_1' => 8, ':bit_2' => 64],
|
|
|
|
Field::inArray('it', 'table', [2, 8, 64], ':bit')->appendParameter([]),
|
|
|
|
'InArray should have appended 3 parameters for the input values');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('appendParameter() succeeds for others')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testAppendParameterSucceedsForOthers(): void
|
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(['@test' => 33], Field::equal('the_field', 33, '@test')->appendParameter([]),
|
2024-06-08 23:58:45 +00:00
|
|
|
'Field parameter not returned correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('path() succeeds for simple SQL path for PostgreSQL')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForSimpleSqlPathForPostgreSQL(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->>'it'", Field::equal('it', 'that')->path(),
|
|
|
|
'SQL value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for simple SQL path for SQLite')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForSimpleSqlPathForSQLite(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->>'top'", Field::equal('top', 'that')->path(),
|
|
|
|
'SQL value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for nested SQL path for PostgreSQL')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForNestedSqlPathForPostgreSQL(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data#>>'{parts,to,the,path}'", Field::equal('parts.to.the.path', '')->path(),
|
|
|
|
'SQL value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for nested SQL path for SQLite')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForNestedSqlPathForSQLite(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->'one'->'two'->>'three'", Field::equal('one.two.three', '')->path(),
|
|
|
|
'SQL value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for simple JSON path for PostgreSQL')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForSimpleJsonPathForPostgreSQL(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->'it'", Field::equal('it', 'that')->path(true),
|
|
|
|
'JSON value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for simple JSON path for SQLite')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForSimpleJsonPathForSQLite(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->'top'", Field::equal('top', 'that')->path(true),
|
|
|
|
'JSON value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for nested JSON path for PostgreSQL')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForNestedJsonPathForPostgreSQL(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data#>'{parts,to,the,path}'", Field::equal('parts.to.the.path', '')->path(true),
|
|
|
|
'JSON value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('path() succeeds for nested JSON path for SQLite')]
|
2024-09-27 01:52:06 +00:00
|
|
|
public function testPathSucceedsForNestedJsonPathForSQLite(): void
|
2024-09-22 21:44:07 +00:00
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->'one'->'two'->'three'", Field::equal('one.two.three', '')->path(true),
|
|
|
|
'SQL value path not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for exists without qualifier for PostgreSQL')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForExistsWithoutQualifierForPostgreSQL(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::exists('that_field')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for exists without qualifier for SQLite')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForExistsWithoutQualifierForSQLite(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::exists('that_field')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for notExists without qualifier for PostgreSQL')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForNotExistsWithoutQualifierForPostgreSQL(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for notExists without qualifier for SQLite')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForNotExistsWithoutQualifierForSQLite(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for SQLite')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithoutQualifierForSQLite(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'age' BETWEEN @agemin AND @agemax",
|
|
|
|
Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with numeric range')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNumericRange(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
|
|
|
$this->assertEquals("(data->>'age')::numeric BETWEEN @agemin AND @agemax",
|
2024-09-21 00:29:47 +00:00
|
|
|
Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with non-numeric range')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNonNumericRange(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
|
|
|
$this->assertEquals("data->>'city' BETWEEN :citymin AND :citymax",
|
2024-09-21 00:29:47 +00:00
|
|
|
Field::between('city', 'Atlanta', 'Chicago', ':city')->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for SQLite')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithQualifierForSQLite(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::between('age', 13, 17, '@age');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'me';
|
|
|
|
$this->assertEquals("me.data->>'age' BETWEEN @agemin AND @agemax", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with numeric range')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNumericRange(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::between('age', 13, 17, '@age');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'me';
|
|
|
|
$this->assertEquals("(me.data->>'age')::numeric BETWEEN @agemin AND @agemax", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with non-numeric range')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNonNumericRange(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::between('city', 'Atlanta', 'Chicago', ':city');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'me';
|
|
|
|
$this->assertEquals("me.data->>'city' BETWEEN :citymin AND :citymax", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for in for PostgreSQL with non-numeric values')]
|
|
|
|
public function testToWhereSucceedsForInForPostgreSQLWithNonNumericValues(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$field = Field::in('test', ['Atlanta', 'Chicago'], ':city');
|
|
|
|
$this->assertEquals("data->>'test' IN (:city_0, :city_1)", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for in for PostgreSQL with numeric values')]
|
|
|
|
public function testToWhereSucceedsForInForPostgreSQLWithNumericValues(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$field = Field::in('even', [2, 4, 6], ':nbr');
|
|
|
|
$this->assertEquals("(data->>'even')::numeric IN (:nbr_0, :nbr_1, :nbr_2)", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for in for SQLite')]
|
|
|
|
public function testToWhereSucceedsForInForSQLite(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$field = Field::in('test', ['Atlanta', 'Chicago'], ':city');
|
|
|
|
$this->assertEquals("data->>'test' IN (:city_0, :city_1)", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for inArray for PostgreSQL')]
|
|
|
|
public function testToWhereSucceedsForInArrayForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$field = Field::inArray('even', 'tbl', [2, 4, 6, 8], ':it');
|
2024-09-26 00:03:17 +00:00
|
|
|
$this->assertEquals("data->'even' ??| ARRAY[:it_0, :it_1, :it_2, :it_3]", $field->toWhere(),
|
2024-09-22 21:44:07 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for inArray for SQLite')]
|
|
|
|
public function testToWhereSucceedsForInArrayForSQLite(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$field = Field::inArray('test', 'tbl', ['Atlanta', 'Chicago'], ':city');
|
|
|
|
$this->assertEquals(
|
|
|
|
"EXISTS (SELECT 1 FROM json_each(tbl.data, '\$.test') WHERE value IN (:city_0, :city_1))",
|
|
|
|
$field->toWhere(), 'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds for others without qualifier for PostgreSQL')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsForOthersWithoutQualifierForPostgreSQL(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds for others without qualifier for SQLite')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsForOthersWithoutQualifierForSQLite(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier no parameter for PostgreSQL')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsWithQualifierNoParameterForPostgreSQL(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::exists('no_field');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'test';
|
|
|
|
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier no parameter for SQLite')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsWithQualifierNoParameterForSQLite(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::exists('no_field');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'test';
|
|
|
|
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier and parameter for PostgreSQL')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsWithQualifierAndParameterForPostgreSQL(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::lessOrEqual('le_field', 18, '@it');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'q';
|
2024-06-21 13:46:41 +00:00
|
|
|
$this->assertEquals("(q.data->>'le_field')::numeric <= @it", $field->toWhere(),
|
2024-06-08 23:58:45 +00:00
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier and parameter for SQLite')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testToWhereSucceedsWithQualifierAndParameterForSQLite(): void
|
|
|
|
{
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
2024-06-08 23:58:45 +00:00
|
|
|
try {
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::lessOrEqual('le_field', 18, '@it');
|
2024-06-08 23:58:45 +00:00
|
|
|
$field->qualifier = 'q';
|
|
|
|
$this->assertEquals("q.data->>'le_field' <= @it", $field->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
2024-07-21 01:47:21 +00:00
|
|
|
Configuration::overrideMode(null);
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('equal() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::equal('my_test', 9);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('my_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(9, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('equal() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::equal('another_test', 'turkey', '@test');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('another_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('turkey', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@test', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('greater() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testGreaterSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::greater('your_test', 4);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('your_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(4, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('greater() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testGreaterSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::greater('more_test', 'chicken', '@value');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('more_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('chicken', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@value', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('greaterOrEqual() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testGreaterOrEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::greaterOrEqual('their_test', 6);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('their_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(6, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('greaterOrEqual() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testGreaterOrEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::greaterOrEqual('greater_test', 'poultry', '@cluck');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('greater_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('poultry', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@cluck', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('less() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testLessSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::less('z', 32);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('z', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(32, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('less() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testLessSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::less('additional_test', 'fowl', '@boo');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('additional_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('fowl', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@boo', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('lessOrEqual() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testLessOrEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::lessOrEqual('g', 87);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('g', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(87, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('lessOrEqual() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testLessOrEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::lessOrEqual('lesser_test', 'hen', '@woo');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('lesser_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('hen', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@woo', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('notEqual() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testNotEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::notEqual('j', 65);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('j', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(65, $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('notEqual() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testNotEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::notEqual('unequal_test', 'egg', '@zoo');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('unequal_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('egg', $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@zoo', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('between() succeeds without parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testBetweenSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::between('k', 'alpha', 'zed');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('k', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(['alpha', 'zed'], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('between() succeeds with parameter')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testBetweenSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::between('between_test', 18, 49, '@count');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('between_test', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals([18, 49], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@count', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('in() succeeds without parameter')]
|
|
|
|
public function testInSucceedsWithoutParameter(): void
|
|
|
|
{
|
|
|
|
$field = Field::in('test', [1, 2, 3]);
|
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('test', $field->fieldName, 'Field name not filled correctly');
|
|
|
|
$this->assertEquals(Op::In, $field->op, 'Operation not filled correctly');
|
|
|
|
$this->assertEquals([1, 2, 3], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('in() succeeds with parameter')]
|
|
|
|
public function testInSucceedsWithParameter(): void
|
|
|
|
{
|
|
|
|
$field = Field::in('unit', ['a', 'b'], '@inParam');
|
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('unit', $field->fieldName, 'Field name not filled correctly');
|
|
|
|
$this->assertEquals(Op::In, $field->op, 'Operation not filled correctly');
|
|
|
|
$this->assertEquals(['a', 'b'], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@inParam', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('inArray() succeeds without parameter')]
|
|
|
|
public function testInArraySucceedsWithoutParameter(): void
|
|
|
|
{
|
|
|
|
$field = Field::inArray('test', 'tbl', [1, 2, 3]);
|
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('test', $field->fieldName, 'Field name not filled correctly');
|
|
|
|
$this->assertEquals(Op::InArray, $field->op, 'Operation not filled correctly');
|
|
|
|
$this->assertEquals(['table' => 'tbl', 'values' => [1, 2, 3]], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('inArray() succeeds with parameter')]
|
|
|
|
public function testInArraySucceedsWithParameter(): void
|
|
|
|
{
|
|
|
|
$field = Field::inArray('unit', 'tab', ['a', 'b'], '@inAParam');
|
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('unit', $field->fieldName, 'Field name not filled correctly');
|
|
|
|
$this->assertEquals(Op::InArray, $field->op, 'Operation not filled correctly');
|
|
|
|
$this->assertEquals(['table' => 'tab', 'values' => ['a', 'b']], $field->value, 'Value not filled correctly');
|
|
|
|
$this->assertEquals('@inAParam', $field->paramName, 'Parameter name not filled correctly');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('exists() succeeds')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testExistsSucceeds(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::exists('be_there');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('be_there', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::Exists, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('', $field->value, 'Value should have been blank');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
|
|
|
|
2024-09-22 21:44:07 +00:00
|
|
|
#[TestDox('notExists() succeeds')]
|
2024-09-21 00:29:47 +00:00
|
|
|
public function testNotExistsSucceeds(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-21 00:29:47 +00:00
|
|
|
$field = Field::notExists('be_absent');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('be_absent', $field->fieldName, 'Field name not filled correctly');
|
2024-09-21 00:29:47 +00:00
|
|
|
$this->assertEquals(Op::NotExists, $field->op, 'Operation not filled correctly');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('', $field->value, 'Value should have been blank');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
2024-09-27 01:52:06 +00:00
|
|
|
|
|
|
|
#[TestDox('named() succeeds')]
|
|
|
|
public function testNamedSucceeds(): void
|
|
|
|
{
|
|
|
|
$field = Field::named('the_field');
|
|
|
|
$this->assertNotNull($field, 'The field should not have been null');
|
|
|
|
$this->assertEquals('the_field', $field->fieldName, 'Field name not filled correctly');
|
|
|
|
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
|
|
|
$this->assertEquals('', $field->value, 'Value should have been blank');
|
|
|
|
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
|
|
|
}
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|