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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('Append parameter succeeds for notExists')]
|
|
|
|
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-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-06-08 23:58:45 +00:00
|
|
|
'BT should have appended min and max parameters');
|
|
|
|
}
|
|
|
|
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where succeeds for exists without qualifier for PostgreSQL')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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-21 00:29:47 +00:00
|
|
|
#[TestDox('To where 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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds for others without qualifier for PostgreSQL')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds for others without qualifier for SQLite')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with qualifier no parameter for PostgreSQL')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with qualifier no parameter for SQLite')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with qualifier and parameter for PostgreSQL')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with qualifier and parameter for SQLite')]
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with sub-document for PostgreSQL')]
|
|
|
|
public function testToWhereSucceedsWithSubDocumentForPostgreSQL(): 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::equal('sub.foo.bar', 22, '@it');
|
2024-06-21 13:46:41 +00:00
|
|
|
$this->assertEquals("(data#>>'{sub,foo,bar}')::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('To where succeeds with sub-document for SQLite')]
|
|
|
|
public function testToWhereSucceedsWithSubDocumentForSQLite(): 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::equal('sub.foo.bar', 22, '@it');
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals("data->>'sub'->>'foo'->>'bar' = @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-21 00:29:47 +00:00
|
|
|
#[TestDox('equal succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('equal succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('greater succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('greater succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('greaterOrEqual succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('greaterOrEqual succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('less succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('less succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('lessOrEqual succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('lessOrEqual succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('notEqual succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('notEqual succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('between succeeds without parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('between succeeds with parameter')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('exists succeeds')]
|
|
|
|
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-21 00:29:47 +00:00
|
|
|
#[TestDox('notExists succeeds')]
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|