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-27 02:15:00 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for exists')]
|
|
|
|
public function testAppendParameterSucceedsForExists(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for notExists')]
|
|
|
|
public function testAppendParameterSucceedsForNotExists(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('appendParameter() succeeds for between')]
|
|
|
|
public function testAppendParameterSucceedsForBetween(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +00:00
|
|
|
$this->assertEquals(['@nummin' => 5, '@nummax' => 9],
|
|
|
|
Field::between('exists', 5, 9, '@num')->appendParameter([]),
|
|
|
|
'Between should have appended min and max parameters');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('path() succeeds for simple SQL path for PostgreSQL')]
|
|
|
|
public function testPathSucceedsForSimpleSqlPathForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForSimpleSqlPathForSQLite(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForNestedSqlPathForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForNestedSqlPathForSQLite(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForSimpleJsonPathForPostgreSQL(): 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-27 02:15:00 +00:00
|
|
|
$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')]
|
|
|
|
public function testPathSucceedsForSimpleJsonPathForSQLite(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForNestedJsonPathForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testPathSucceedsForNestedJsonPathForSQLite(): void
|
|
|
|
{
|
|
|
|
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')]
|
|
|
|
public function testToWhereSucceedsForExistsWithoutQualifierForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for exists without qualifier for SQLite')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for notExists without qualifier for PostgreSQL')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for notExists without qualifier for SQLite')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for SQLite')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with numeric range')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with non-numeric range')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for SQLite')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with numeric range')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with non-numeric range')]
|
|
|
|
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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for in for PostgreSQL with non-numeric values')]
|
|
|
|
public function testToWhereSucceedsForInForPostgreSQLWithNonNumericValues(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::in('test', ['Atlanta', 'Chicago'], ':city');
|
|
|
|
$this->assertEquals("data->>'test' IN (:city_0, :city_1)", $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-27 02:15:00 +00:00
|
|
|
#[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
|
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-27 02:15:00 +00:00
|
|
|
$field = Field::in('test', ['Atlanta', 'Chicago'], ':city');
|
|
|
|
$this->assertEquals("data->>'test' IN (:city_0, :city_1)", $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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for inArray for PostgreSQL')]
|
|
|
|
public function testToWhereSucceedsForInArrayForPostgreSQL(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::inArray('even', 'tbl', [2, 4, 6, 8], ':it');
|
|
|
|
$this->assertEquals("data->'even' ??| ARRAY[:it_0, :it_1, :it_2, :it_3]", $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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for inArray for SQLite')]
|
|
|
|
public function testToWhereSucceedsForInArrayForSQLite(): 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-27 02:15:00 +00:00
|
|
|
$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')]
|
|
|
|
public function testToWhereSucceedsForOthersWithoutQualifierForPostgreSQL(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::PgSQL);
|
|
|
|
try {
|
|
|
|
$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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds for others without qualifier for SQLite')]
|
|
|
|
public function testToWhereSucceedsForOthersWithoutQualifierForSQLite(): void
|
|
|
|
{
|
|
|
|
Configuration::overrideMode(Mode::SQLite);
|
|
|
|
try {
|
|
|
|
$this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
|
|
|
|
'WHERE fragment not generated correctly');
|
|
|
|
} finally {
|
|
|
|
Configuration::overrideMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('toWhere() succeeds with qualifier no parameter for PostgreSQL')]
|
|
|
|
public function testToWhereSucceedsWithQualifierNoParameterForPostgreSQL(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::exists('no_field');
|
|
|
|
$field->qualifier = 'test';
|
|
|
|
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier no parameter for SQLite')]
|
|
|
|
public function testToWhereSucceedsWithQualifierNoParameterForSQLite(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::exists('no_field');
|
|
|
|
$field->qualifier = 'test';
|
|
|
|
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier and parameter for PostgreSQL')]
|
|
|
|
public function testToWhereSucceedsWithQualifierAndParameterForPostgreSQL(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::lessOrEqual('le_field', 18, '@it');
|
|
|
|
$field->qualifier = 'q';
|
|
|
|
$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-27 02:15:00 +00:00
|
|
|
#[TestDox('toWhere() succeeds with qualifier and parameter for SQLite')]
|
|
|
|
public function testToWhereSucceedsWithQualifierAndParameterForSQLite(): 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-27 02:15:00 +00:00
|
|
|
$field = Field::lessOrEqual('le_field', 18, '@it');
|
|
|
|
$field->qualifier = 'q';
|
|
|
|
$this->assertEquals("q.data->>'le_field' <= @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-27 02:15:00 +00:00
|
|
|
#[TestDox('equal() succeeds without parameter')]
|
|
|
|
public function testEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('equal() succeeds with parameter')]
|
|
|
|
public function testEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('greater() succeeds without parameter')]
|
|
|
|
public function testGreaterSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('greater() succeeds with parameter')]
|
|
|
|
public function testGreaterSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('greaterOrEqual() succeeds without parameter')]
|
|
|
|
public function testGreaterOrEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('greaterOrEqual() succeeds with parameter')]
|
|
|
|
public function testGreaterOrEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('less() succeeds without parameter')]
|
|
|
|
public function testLessSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('less() succeeds with parameter')]
|
|
|
|
public function testLessSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('lessOrEqual() succeeds without parameter')]
|
|
|
|
public function testLessOrEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('lessOrEqual() succeeds with parameter')]
|
|
|
|
public function testLessOrEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('notEqual() succeeds without parameter')]
|
|
|
|
public function testNotEqualSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('notEqual() succeeds with parameter')]
|
|
|
|
public function testNotEqualSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('between() succeeds without parameter')]
|
|
|
|
public function testBetweenSucceedsWithoutParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('between() succeeds with parameter')]
|
|
|
|
public function testBetweenSucceedsWithParameter(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +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-27 02:15:00 +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
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +00:00
|
|
|
$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')]
|
|
|
|
public function testExistsSucceeds(): void
|
|
|
|
{
|
|
|
|
$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-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
#[TestDox('notExists() succeeds')]
|
|
|
|
public function testNotExistsSucceeds(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
2024-09-27 02:15:00 +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-27 02:15:00 +00:00
|
|
|
$this->assertEquals(Op::NotExists, $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');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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');
|
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');
|
|
|
|
}
|
|
|
|
}
|