Changes for beta10 (#5)
- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
@@ -18,14 +18,14 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Configuration (Unit tests)')]
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
#[TestDox('ID field default succeeds')]
|
||||
#[TestDox('id default succeeds')]
|
||||
public function testIdFieldDefaultSucceeds(): void
|
||||
{
|
||||
$this->assertEquals('id', Configuration::$idField, 'Default ID field should be "id"');
|
||||
}
|
||||
|
||||
#[TestDox('ID field change succeeds')]
|
||||
public function testIdFieldChangeSucceeds()
|
||||
#[TestDox('id change succeeds')]
|
||||
public function testIdFieldChangeSucceeds(): void
|
||||
{
|
||||
try {
|
||||
Configuration::$idField = 'EyeDee';
|
||||
@@ -36,19 +36,19 @@ class ConfigurationTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Auto ID default succeeds')]
|
||||
#[TestDox('autoId default succeeds')]
|
||||
public function testAutoIdDefaultSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(AutoId::None, Configuration::$autoId, 'Auto ID should default to None');
|
||||
}
|
||||
|
||||
#[TestDox('ID string length default succeeds')]
|
||||
#[TestDox('idStringLength default succeeds')]
|
||||
public function testIdStringLengthDefaultSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(16, Configuration::$idStringLength, 'ID string length should default to 16');
|
||||
}
|
||||
|
||||
#[TestDox("Db conn fails when no DSN specified")]
|
||||
#[TestDox("dbConn() fails when no DSN specified")]
|
||||
public function testDbConnFailsWhenNoDSNSpecified(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -38,6 +38,7 @@ class DocumentExceptionTest extends TestCase
|
||||
$this->assertNull($ex->getPrevious(), 'Prior exception should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('toString() succeeds without code')]
|
||||
public function testToStringSucceedsWithoutCode(): void
|
||||
{
|
||||
$ex = new DocumentException('Test failure');
|
||||
@@ -45,6 +46,7 @@ class DocumentExceptionTest extends TestCase
|
||||
'toString not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('toString() succeeds with code')]
|
||||
public function testToStringSucceedsWithCode(): void
|
||||
{
|
||||
$ex = new DocumentException('Oof', -6);
|
||||
|
||||
@@ -18,13 +18,13 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Field Match (Unit tests)')]
|
||||
class FieldMatchTest extends TestCase
|
||||
{
|
||||
#[TestDox('To SQL succeeds for all')]
|
||||
#[TestDox('toSQL() succeeds for All')]
|
||||
public function testToSQLSucceedsForAll(): void
|
||||
{
|
||||
$this->assertEquals('AND', FieldMatch::All->toSQL(), 'All should have returned AND');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for any')]
|
||||
#[TestDox('toSQL() succeeds for Any')]
|
||||
public function testToSQLSucceedsForAny(): void
|
||||
{
|
||||
$this->assertEquals('OR', FieldMatch::Any->toSQL(), 'Any should have returned OR');
|
||||
|
||||
@@ -18,121 +18,256 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Field (Unit tests)')]
|
||||
class FieldTest extends TestCase
|
||||
{
|
||||
#[TestDox('Append parameter succeeds for EX')]
|
||||
public function testAppendParameterSucceedsForEX(): void
|
||||
#[TestDox('appendParameter() succeeds for exists')]
|
||||
public function testAppendParameterSucceedsForExists(): void
|
||||
{
|
||||
$this->assertEquals([], Field::EX('exists')->appendParameter([]), 'EX should not have appended a parameter');
|
||||
$this->assertEquals([], Field::exists('exists')->appendParameter([]),
|
||||
'exists should not have appended a parameter');
|
||||
}
|
||||
|
||||
#[TestDox('Append parameter succeeds for NEX')]
|
||||
public function testAppendParameterSucceedsForNEX(): void
|
||||
#[TestDox('appendParameter() succeeds for notExists')]
|
||||
public function testAppendParameterSucceedsForNotExists(): void
|
||||
{
|
||||
$this->assertEquals([], Field::NEX('absent')->appendParameter([]), 'NEX should not have appended a parameter');
|
||||
$this->assertEquals([], Field::notExists('absent')->appendParameter([]),
|
||||
'notExists should not have appended a parameter');
|
||||
}
|
||||
|
||||
#[TestDox('Append parameter succeeds for BT')]
|
||||
public function testAppendParameterSucceedsForBT(): void
|
||||
#[TestDox('appendParameter() succeeds for between')]
|
||||
public function testAppendParameterSucceedsForBetween(): void
|
||||
{
|
||||
$this->assertEquals(['@nummin' => 5, '@nummax' => 9], Field::BT('exists', 5, 9, '@num')->appendParameter([]),
|
||||
'BT should have appended min and max parameters');
|
||||
$this->assertEquals(['@nummin' => 5, '@nummax' => 9],
|
||||
Field::between('exists', 5, 9, '@num')->appendParameter([]),
|
||||
'Between should have appended min and max parameters');
|
||||
}
|
||||
|
||||
#[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')]
|
||||
public function testAppendParameterSucceedsForOthers(): void
|
||||
{
|
||||
$this->assertEquals(['@test' => 33], Field::EQ('the_field', 33, '@test')->appendParameter([]),
|
||||
$this->assertEquals(['@test' => 33], Field::equal('the_field', 33, '@test')->appendParameter([]),
|
||||
'Field parameter not returned correctly');
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for EX without qualifier for PostgreSQL')]
|
||||
public function testToWhereSucceedsForEXWithoutQualifierForPostgreSQL(): void
|
||||
#[TestDox('path() succeeds for simple SQL path for PostgreSQL')]
|
||||
public function testPathSucceedsForSimpleSqlPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::EX('that_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
$this->assertEquals("data->>'it'", Field::equal('it', 'that')->path(),
|
||||
'SQL value path not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for EX without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForEXWithoutQualifierForSQLite(): void
|
||||
#[TestDox('path() succeeds for simple SQL path for SQLite')]
|
||||
public function testPathSucceedsForSimpleSqlPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::EX('that_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
$this->assertEquals("data->>'top'", Field::equal('top', 'that')->path(),
|
||||
'SQL value path not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for NEX without qualifier for PostgreSQL')]
|
||||
public function testToWhereSucceedsForNEXWithoutQualifierForPostgreSQL(): void
|
||||
#[TestDox('path() succeeds for nested SQL path for PostgreSQL')]
|
||||
public function testPathSucceedsForNestedSqlPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
$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('To where succeeds for NEX without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForNEXWithoutQualifierForSQLite(): void
|
||||
#[TestDox('path() succeeds for nested SQL path for SQLite')]
|
||||
public function testPathSucceedsForNestedSqlPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
$this->assertEquals("data->'one'->'two'->>'three'", Field::equal('one.two.three', '')->path(),
|
||||
'SQL value path not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForBTWithoutQualifierForSQLite(): void
|
||||
#[TestDox('path() succeeds for simple JSON path for PostgreSQL')]
|
||||
public function testPathSucceedsForSimpleJsonPathForPostgreSQL(): void
|
||||
{
|
||||
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')]
|
||||
public function testPathSucceedsForSimpleJsonPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'age' BETWEEN @agemin AND @agemax", Field::BT('age', 13, 17, '@age')->toWhere(),
|
||||
$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(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNumericRange(): void
|
||||
#[TestDox('toWhere() succeeds for exists without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForExistsWithoutQualifierForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'that_field' IS NOT NULL", Field::exists('that_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('toWhere() succeeds for notExists without qualifier for PostgreSQL')]
|
||||
public function testToWhereSucceedsForNotExistsWithoutQualifierForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('toWhere() succeeds for notExists without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForNotExistsWithoutQualifierForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('toWhere() succeeds for between without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForBetweenWithoutQualifierForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'age' BETWEEN @agemin AND @agemax",
|
||||
Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNumericRange(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("(data->>'age')::numeric BETWEEN @agemin AND @agemax",
|
||||
Field::BT('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
||||
Field::between('age', 13, 17, '@age')->toWhere(), 'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT without qualifier for PostgreSQL with non-numeric range')]
|
||||
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNonNumericRange(): void
|
||||
#[TestDox('toWhere() succeeds for between without qualifier for PostgreSQL with non-numeric range')]
|
||||
public function testToWhereSucceedsForBetweenWithoutQualifierForPostgreSQLWithNonNumericRange(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'city' BETWEEN :citymin AND :citymax",
|
||||
Field::BT('city', 'Atlanta', 'Chicago', ':city')->toWhere(), 'WHERE fragment not generated correctly');
|
||||
Field::between('city', 'Atlanta', 'Chicago', ':city')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT with qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForBTWithQualifierForSQLite(): void
|
||||
#[TestDox('toWhere() succeeds for between with qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForBetweenWithQualifierForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$field = Field::BT('age', 13, 17, '@age');
|
||||
$field = Field::between('age', 13, 17, '@age');
|
||||
$field->qualifier = 'me';
|
||||
$this->assertEquals("me.data->>'age' BETWEEN @agemin AND @agemax", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -141,12 +276,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNumericRange(): void
|
||||
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNumericRange(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::BT('age', 13, 17, '@age');
|
||||
$field = Field::between('age', 13, 17, '@age');
|
||||
$field->qualifier = 'me';
|
||||
$this->assertEquals("(me.data->>'age')::numeric BETWEEN @agemin AND @agemax", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -155,12 +290,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with non-numeric range')]
|
||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNonNumericRange(): void
|
||||
#[TestDox('toWhere() succeeds for between with qualifier for PostgreSQL with non-numeric range')]
|
||||
public function testToWhereSucceedsForBetweenWithQualifierForPostgreSQLWithNonNumericRange(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::BT('city', 'Atlanta', 'Chicago', ':city');
|
||||
$field = Field::between('city', 'Atlanta', 'Chicago', ':city');
|
||||
$field->qualifier = 'me';
|
||||
$this->assertEquals("me.data->>'city' BETWEEN :citymin AND :citymax", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -169,36 +304,102 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for others without qualifier for PostgreSQL')]
|
||||
#[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');
|
||||
$this->assertEquals("data->'even' ??| ARRAY[:it_0, :it_1, :it_2, :it_3]", $field->toWhere(),
|
||||
'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')]
|
||||
public function testToWhereSucceedsForOthersWithoutQualifierForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'some_field' = @value", Field::EQ('some_field', '', '@value')->toWhere(),
|
||||
$this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for others without qualifier for SQLite')]
|
||||
#[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::EQ('some_field', '', '@value')->toWhere(),
|
||||
$this->assertEquals("data->>'some_field' = @value", Field::equal('some_field', '', '@value')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with qualifier no parameter for PostgreSQL')]
|
||||
#[TestDox('toWhere() succeeds with qualifier no parameter for PostgreSQL')]
|
||||
public function testToWhereSucceedsWithQualifierNoParameterForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::EX('no_field');
|
||||
$field = Field::exists('no_field');
|
||||
$field->qualifier = 'test';
|
||||
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -207,12 +408,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with qualifier no parameter for SQLite')]
|
||||
#[TestDox('toWhere() succeeds with qualifier no parameter for SQLite')]
|
||||
public function testToWhereSucceedsWithQualifierNoParameterForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$field = Field::EX('no_field');
|
||||
$field = Field::exists('no_field');
|
||||
$field->qualifier = 'test';
|
||||
$this->assertEquals("test.data->>'no_field' IS NOT NULL", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -221,12 +422,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with qualifier and parameter for PostgreSQL')]
|
||||
#[TestDox('toWhere() succeeds with qualifier and parameter for PostgreSQL')]
|
||||
public function testToWhereSucceedsWithQualifierAndParameterForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::LE('le_field', 18, '@it');
|
||||
$field = Field::lessOrEqual('le_field', 18, '@it');
|
||||
$field->qualifier = 'q';
|
||||
$this->assertEquals("(q.data->>'le_field')::numeric <= @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -235,12 +436,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with qualifier and parameter for SQLite')]
|
||||
#[TestDox('toWhere() succeeds with qualifier and parameter for SQLite')]
|
||||
public function testToWhereSucceedsWithQualifierAndParameterForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$field = Field::LE('le_field', 18, '@it');
|
||||
$field = Field::lessOrEqual('le_field', 18, '@it');
|
||||
$field->qualifier = 'q';
|
||||
$this->assertEquals("q.data->>'le_field' <= @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
@@ -249,204 +450,233 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with sub-document for PostgreSQL')]
|
||||
public function testToWhereSucceedsWithSubDocumentForPostgreSQL(): void
|
||||
#[TestDox('equal() succeeds without parameter')]
|
||||
public function testEqualSucceedsWithoutParameter(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
||||
$this->assertEquals("(data#>>'{sub,foo,bar}')::numeric = @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds with sub-document for SQLite')]
|
||||
public function testToWhereSucceedsWithSubDocumentForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
||||
$this->assertEquals("data->>'sub'->>'foo'->>'bar' = @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('EQ succeeds without parameter')]
|
||||
public function testEQSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::EQ('my_test', 9);
|
||||
$field = Field::equal('my_test', 9);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('my_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::EQ, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(9, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('EQ succeeds with parameter')]
|
||||
public function testEQSucceedsWithParameter(): void
|
||||
#[TestDox('equal() succeeds with parameter')]
|
||||
public function testEqualSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::EQ('another_test', 'turkey', '@test');
|
||||
$field = Field::equal('another_test', 'turkey', '@test');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('another_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::EQ, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('turkey', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@test', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('GT succeeds without parameter')]
|
||||
public function testGTSucceedsWithoutParameter(): void
|
||||
#[TestDox('greater() succeeds without parameter')]
|
||||
public function testGreaterSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::GT('your_test', 4);
|
||||
$field = Field::greater('your_test', 4);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('your_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::GT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(4, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('GT succeeds with parameter')]
|
||||
public function testGTSucceedsWithParameter(): void
|
||||
#[TestDox('greater() succeeds with parameter')]
|
||||
public function testGreaterSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::GT('more_test', 'chicken', '@value');
|
||||
$field = Field::greater('more_test', 'chicken', '@value');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('more_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::GT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Greater, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('chicken', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@value', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('GE succeeds without parameter')]
|
||||
public function testGESucceedsWithoutParameter(): void
|
||||
#[TestDox('greaterOrEqual() succeeds without parameter')]
|
||||
public function testGreaterOrEqualSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::GE('their_test', 6);
|
||||
$field = Field::greaterOrEqual('their_test', 6);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('their_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::GE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(6, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('GE succeeds with parameter')]
|
||||
public function testGESucceedsWithParameter(): void
|
||||
#[TestDox('greaterOrEqual() succeeds with parameter')]
|
||||
public function testGreaterOrEqualSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::GE('greater_test', 'poultry', '@cluck');
|
||||
$field = Field::greaterOrEqual('greater_test', 'poultry', '@cluck');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('greater_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::GE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::GreaterOrEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('poultry', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@cluck', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('LT succeeds without parameter')]
|
||||
public function testLTSucceedsWithoutParameter(): void
|
||||
#[TestDox('less() succeeds without parameter')]
|
||||
public function testLessSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::LT('z', 32);
|
||||
$field = Field::less('z', 32);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('z', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::LT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(32, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('LT succeeds with parameter')]
|
||||
public function testLTSucceedsWithParameter(): void
|
||||
#[TestDox('less() succeeds with parameter')]
|
||||
public function testLessSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::LT('additional_test', 'fowl', '@boo');
|
||||
$field = Field::less('additional_test', 'fowl', '@boo');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('additional_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::LT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Less, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('fowl', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@boo', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('LE succeeds without parameter')]
|
||||
public function testLESucceedsWithoutParameter(): void
|
||||
#[TestDox('lessOrEqual() succeeds without parameter')]
|
||||
public function testLessOrEqualSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::LE('g', 87);
|
||||
$field = Field::lessOrEqual('g', 87);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('g', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::LE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(87, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('LE succeeds with parameter')]
|
||||
public function testLESucceedsWithParameter(): void
|
||||
#[TestDox('lessOrEqual() succeeds with parameter')]
|
||||
public function testLessOrEqualSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::LE('lesser_test', 'hen', '@woo');
|
||||
$field = Field::lessOrEqual('lesser_test', 'hen', '@woo');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('lesser_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::LE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::LessOrEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('hen', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@woo', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('NE succeeds without parameter')]
|
||||
public function testNESucceedsWithoutParameter(): void
|
||||
#[TestDox('notEqual() succeeds without parameter')]
|
||||
public function testNotEqualSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::NE('j', 65);
|
||||
$field = Field::notEqual('j', 65);
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('j', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::NE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(65, $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('NE succeeds with parameter')]
|
||||
public function testNESucceedsWithParameter(): void
|
||||
#[TestDox('notEqual() succeeds with parameter')]
|
||||
public function testNotEqualSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::NE('unequal_test', 'egg', '@zoo');
|
||||
$field = Field::notEqual('unequal_test', 'egg', '@zoo');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('unequal_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::NE, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::NotEqual, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('egg', $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@zoo', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('BT succeeds without parameter')]
|
||||
public function testBTSucceedsWithoutParameter(): void
|
||||
#[TestDox('between() succeeds without parameter')]
|
||||
public function testBetweenSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::BT('k', 'alpha', 'zed');
|
||||
$field = Field::between('k', 'alpha', 'zed');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('k', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::BT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(['alpha', 'zed'], $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('BT succeeds with parameter')]
|
||||
public function testBTSucceedsWithParameter(): void
|
||||
#[TestDox('between() succeeds with parameter')]
|
||||
public function testBetweenSucceedsWithParameter(): void
|
||||
{
|
||||
$field = Field::BT('between_test', 18, 49, '@count');
|
||||
$field = Field::between('between_test', 18, 49, '@count');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('between_test', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::BT, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Between, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals([18, 49], $field->value, 'Value not filled correctly');
|
||||
$this->assertEquals('@count', $field->paramName, 'Parameter name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('EX succeeds')]
|
||||
public function testEXSucceeds(): void
|
||||
#[TestDox('in() succeeds without parameter')]
|
||||
public function testInSucceedsWithoutParameter(): void
|
||||
{
|
||||
$field = Field::EX('be_there');
|
||||
$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')]
|
||||
public function testExistsSucceeds(): void
|
||||
{
|
||||
$field = Field::exists('be_there');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('be_there', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::EX, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals(Op::Exists, $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('NEX succeeds')]
|
||||
public function testNEXSucceeds(): void
|
||||
#[TestDox('notExists() succeeds')]
|
||||
public function testNotExistsSucceeds(): void
|
||||
{
|
||||
$field = Field::NEX('be_absent');
|
||||
$field = Field::notExists('be_absent');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('be_absent', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::NEX, $field->op, 'Operation not filled correctly');
|
||||
$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');
|
||||
$this->assertEquals('', $field->value, 'Value should have been blank');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Array Mapper (Unit tests)')]
|
||||
class ArrayMapperTest extends TestCase
|
||||
{
|
||||
#[TestDox('map() succeeds')]
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$result = ['one' => 2, 'three' => 4, 'eight' => 'five'];
|
||||
|
||||
@@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Count Mapper (Unit tests)')]
|
||||
class CountMapperTest extends TestCase
|
||||
{
|
||||
#[TestDox('map() succeeds')]
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(5, (new CountMapper())->map([5, 8, 10]), 'Count not correct');
|
||||
|
||||
@@ -44,7 +44,7 @@ class DocumentMapperTest extends TestCase
|
||||
$this->assertEquals('json', $mapper->fieldName, 'Field name not recorded correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds with valid JSON')]
|
||||
#[TestDox('map() succeeds with valid JSON')]
|
||||
public function testMapSucceedsWithValidJSON(): void
|
||||
{
|
||||
$doc = (new DocumentMapper(TestDocument::class))->map(['data' => '{"id":7,"subDoc":{"id":22,"name":"tester"}}']);
|
||||
@@ -55,7 +55,7 @@ class DocumentMapperTest extends TestCase
|
||||
$this->assertEquals('tester', $doc->subDoc->name, 'Sub-document name not filled correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds with valid JSON for pjson class')]
|
||||
#[TestDox('map() succeeds with valid JSON for Pjson class')]
|
||||
public function testMapSucceedsWithValidJSONForPjsonClass(): void
|
||||
{
|
||||
$doc = (new DocumentMapper(PjsonDocument::class))->map(['data' => '{"id":"seven","name":"bob","num_value":8}']);
|
||||
@@ -66,14 +66,14 @@ class DocumentMapperTest extends TestCase
|
||||
$this->assertFalse(isset($doc->skipped), 'Non-JSON field has not been set');
|
||||
}
|
||||
|
||||
#[TestDox('Map fails with invalid JSON')]
|
||||
#[TestDox('map() fails with invalid JSON')]
|
||||
public function testMapFailsWithInvalidJSON(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
(new DocumentMapper(TestDocument::class))->map(['data' => 'this is not valid']);
|
||||
}
|
||||
|
||||
#[TestDox('Map fails with invalid JSON for pjson class')]
|
||||
#[TestDox('map() fails with invalid JSON for Pjson class')]
|
||||
public function testMapFailsWithInvalidJSONForPjsonClass(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Exists Mapper (Unit tests)')]
|
||||
class ExistsMapperTest extends TestCase
|
||||
{
|
||||
#[TestDox('Map succeeds for PostgreSQL')]
|
||||
#[TestDox('map() succeeds for PostgreSQL')]
|
||||
public function testMapSucceedsForPostgreSQL(): void
|
||||
{
|
||||
try {
|
||||
@@ -30,7 +30,7 @@ class ExistsMapperTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds for SQLite')]
|
||||
#[TestDox('map() succeeds for SQLite')]
|
||||
public function testMapSucceedsForSQLite(): void
|
||||
{
|
||||
try {
|
||||
@@ -41,6 +41,7 @@ class ExistsMapperTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('map() fails when mode not set')]
|
||||
public function testMapFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -18,21 +18,24 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('String Mapper (Unit tests)')]
|
||||
class StringMapperTest extends TestCase
|
||||
{
|
||||
public function testMapSucceedsWhenFieldIsPresentAndString()
|
||||
#[TestDox('map() succeeds when field is present and string')]
|
||||
public function testMapSucceedsWhenFieldIsPresentAndString(): void
|
||||
{
|
||||
$result = ['test_field' => 'test_value'];
|
||||
$mapper = new StringMapper('test_field');
|
||||
$this->assertEquals('test_value', $mapper->map($result), 'String value not returned correctly');
|
||||
}
|
||||
|
||||
public function testMapSucceedsWhenFieldIsPresentAndNotString()
|
||||
#[TestDox('map() succeeds when field is present and not string')]
|
||||
public function testMapSucceedsWhenFieldIsPresentAndNotString(): void
|
||||
{
|
||||
$result = ['a_number' => 6.7];
|
||||
$mapper = new StringMapper('a_number');
|
||||
$this->assertEquals('6.7', $mapper->map($result), 'Number value not returned correctly');
|
||||
}
|
||||
|
||||
public function testMapSucceedsWhenFieldIsNotPresent()
|
||||
#[TestDox('map() succeeds when field is not present')]
|
||||
public function testMapSucceedsWhenFieldIsNotPresent(): void
|
||||
{
|
||||
$mapper = new StringMapper('something_else');
|
||||
$this->assertNull($mapper->map([]), 'Missing value not returned correctly');
|
||||
|
||||
@@ -18,19 +18,19 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Mode (Unit tests)')]
|
||||
class ModeTest extends TestCase
|
||||
{
|
||||
#[TestDox('Derive from DSN succeeds for PostgreSQL')]
|
||||
#[TestDox('deriveFromDSN() succeeds for PostgreSQL')]
|
||||
public function testDeriveFromDSNSucceedsForPostgreSQL(): void
|
||||
{
|
||||
$this->assertEquals(Mode::PgSQL, Mode::deriveFromDSN('pgsql:Host=localhost'), 'PostgreSQL mode incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Derive from DSN succeeds for SQLite')]
|
||||
#[TestDox('deriveFromDSN() succeeds for SQLite')]
|
||||
public function testDeriveFromDSNSucceedsForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(Mode::SQLite, Mode::deriveFromDSN('sqlite:data.db'), 'SQLite mode incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Derive from DSN fails for MySQL')]
|
||||
#[TestDox('deriveFromDSN() fails for MySQL')]
|
||||
public function testDeriveFromDSNFailsForMySQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -18,57 +18,69 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Op (Unit tests)')]
|
||||
class OpTest extends TestCase
|
||||
{
|
||||
#[TestDox('To SQL succeeds for EQ')]
|
||||
public function testToSQLSucceedsForEQ(): void
|
||||
#[TestDox('toSQL() succeeds for Equal')]
|
||||
public function testToSQLSucceedsForEqual(): void
|
||||
{
|
||||
$this->assertEquals('=', Op::EQ->toSQL(), 'EQ operator incorrect');
|
||||
$this->assertEquals('=', Op::Equal->toSQL(), 'Equal SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for GT')]
|
||||
public function testToSQLSucceedsForGT(): void
|
||||
#[TestDox('toSQL() succeeds for Greater')]
|
||||
public function testToSQLSucceedsForGreater(): void
|
||||
{
|
||||
$this->assertEquals('>', Op::GT->toSQL(), 'GT operator incorrect');
|
||||
$this->assertEquals('>', Op::Greater->toSQL(), 'Greater SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for GE')]
|
||||
public function testToSQLSucceedsForGE(): void
|
||||
#[TestDox('toSQL() succeeds for GreaterOrEqual')]
|
||||
public function testToSQLSucceedsForGreaterOrEqual(): void
|
||||
{
|
||||
$this->assertEquals('>=', Op::GE->toSQL(), 'GE operator incorrect');
|
||||
$this->assertEquals('>=', Op::GreaterOrEqual->toSQL(), 'GreaterOrEqual SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for LT')]
|
||||
public function testToSQLSucceedsForLT(): void
|
||||
#[TestDox('toSQL() succeeds for Less')]
|
||||
public function testToSQLSucceedsForLess(): void
|
||||
{
|
||||
$this->assertEquals('<', Op::LT->toSQL(), 'LT operator incorrect');
|
||||
$this->assertEquals('<', Op::Less->toSQL(), 'Less SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for LE')]
|
||||
public function testToSQLSucceedsForLE(): void
|
||||
#[TestDox('toSQL() succeeds for LessOrEqual')]
|
||||
public function testToSQLSucceedsForLessOrEqual(): void
|
||||
{
|
||||
$this->assertEquals('<=', Op::LE->toSQL(), 'LE operator incorrect');
|
||||
$this->assertEquals('<=', Op::LessOrEqual->toSQL(), 'LessOrEqual SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for NE')]
|
||||
public function testToSQLSucceedsForNE(): void
|
||||
#[TestDox('toSQL() succeeds for NotEqual')]
|
||||
public function testToSQLSucceedsForNotEqual(): void
|
||||
{
|
||||
$this->assertEquals('<>', Op::NE->toSQL(), 'NE operator incorrect');
|
||||
$this->assertEquals('<>', Op::NotEqual->toSQL(), 'NotEqual SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for BT')]
|
||||
public function testToSQLSucceedsForBT(): void
|
||||
#[TestDox('toSQL() succeeds for Between')]
|
||||
public function testToSQLSucceedsForBetween(): void
|
||||
{
|
||||
$this->assertEquals('BETWEEN', Op::BT->toSQL(), 'BT operator incorrect');
|
||||
$this->assertEquals('BETWEEN', Op::Between->toSQL(), 'Between SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for EX')]
|
||||
public function testToSQLSucceedsForEX(): void
|
||||
#[TestDox('toSQL() succeeds for In')]
|
||||
public function testToSQLSucceedsForIn(): void
|
||||
{
|
||||
$this->assertEquals('IS NOT NULL', Op::EX->toSQL(), 'EX operator incorrect');
|
||||
$this->assertEquals('IN', Op::In->toSQL(), 'In SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for NEX')]
|
||||
#[TestDox('toSQL() succeeds for InArray')]
|
||||
public function testToSQLSucceedsForInArray(): void
|
||||
{
|
||||
$this->assertEquals('??|', Op::InArray->toSQL(), 'InArray SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('toSQL() succeeds for Exists')]
|
||||
public function testToSQLSucceedsForExists(): void
|
||||
{
|
||||
$this->assertEquals('IS NOT NULL', Op::Exists->toSQL(), 'Exists SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('toSQL() succeeds for NotExists')]
|
||||
public function testToSQLSucceedsForNEX(): void
|
||||
{
|
||||
$this->assertEquals('IS NULL', Op::NEX->toSQL(), 'NEX operator incorrect');
|
||||
$this->assertEquals('IS NULL', Op::NotExists->toSQL(), 'NotExists SQL operator incorrect');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@ use Test\{PjsonDocument, PjsonId};
|
||||
#[TestDox('Parameters (Unit tests)')]
|
||||
class ParametersTest extends TestCase
|
||||
{
|
||||
#[TestDox('ID succeeds with string')]
|
||||
#[TestDox('id() succeeds with string')]
|
||||
public function testIdSucceedsWithString(): void
|
||||
{
|
||||
$this->assertEquals([':id' => 'key'], Parameters::id('key'), 'ID parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('ID succeeds with non string')]
|
||||
#[TestDox('id() succeeds with non string')]
|
||||
public function testIdSucceedsWithNonString(): void
|
||||
{
|
||||
$this->assertEquals([':id' => '7'], Parameters::id(7), 'ID parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json() succeeds for array')]
|
||||
public function testJsonSucceedsForArray(): void
|
||||
{
|
||||
$this->assertEquals([':it' => '{"id":18,"url":"https://www.unittest.com"}'],
|
||||
@@ -39,20 +40,21 @@ class ParametersTest extends TestCase
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json() succeeds for array with empty array parameter')]
|
||||
public function testJsonSucceedsForArrayWithEmptyArrayParameter(): void
|
||||
{
|
||||
$this->assertEquals([':it' => '{"id":18,"urls":[]}'], Parameters::json(':it', ['id' => 18, 'urls' => []]),
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json succeeds for 1D array with empty array parameter')]
|
||||
#[TestDox('json() succeeds for 1D array with empty array parameter')]
|
||||
public function testJsonSucceedsFor1DArrayWithEmptyArrayParameter(): void
|
||||
{
|
||||
$this->assertEquals([':it' => '{"urls":[]}'], Parameters::json(':it', ['urls' => []]),
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json succeeds for stdClass')]
|
||||
#[TestDox('json() succeeds for stdClass')]
|
||||
public function testJsonSucceedsForStdClass(): void
|
||||
{
|
||||
$obj = new stdClass();
|
||||
@@ -62,6 +64,7 @@ class ParametersTest extends TestCase
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json() succeeds for Pjson class')]
|
||||
public function testJsonSucceedsForPjsonClass(): void
|
||||
{
|
||||
$this->assertEquals([':it' => '{"id":"999","name":"a test","num_value":98}'],
|
||||
@@ -69,6 +72,7 @@ class ParametersTest extends TestCase
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('json() succeeds for array of Pjson class')]
|
||||
public function testJsonSucceedsForArrayOfPjsonClass(): void
|
||||
{
|
||||
$this->assertEquals([':it' => '{"pjson":[{"id":"997","name":"another test","num_value":94}]}'],
|
||||
@@ -77,23 +81,26 @@ class ParametersTest extends TestCase
|
||||
'JSON parameter not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('nameFields() succeeds')]
|
||||
public function testNameFieldsSucceeds(): void
|
||||
{
|
||||
$named = Parameters::nameFields([Field::EQ('it', 17), Field::EQ('also', 22, ':also'), Field::EQ('other', 24)]);
|
||||
$named = [Field::equal('it', 17), Field::equal('also', 22, ':also'), Field::equal('other', 24)];
|
||||
Parameters::nameFields($named);
|
||||
$this->assertCount(3, $named, 'There should be 3 parameters in the array');
|
||||
$this->assertEquals(':field0', $named[0]->paramName, 'Parameter 1 not named correctly');
|
||||
$this->assertEquals(':also', $named[1]->paramName, 'Parameter 2 not named correctly');
|
||||
$this->assertEquals(':field2', $named[2]->paramName, 'Parameter 3 not named correctly');
|
||||
}
|
||||
|
||||
#[TestDox('addFields() succeeds')]
|
||||
public function testAddFieldsSucceeds(): void
|
||||
{
|
||||
$this->assertEquals([':a' => 1, ':b' => 'two', ':z' => 18],
|
||||
Parameters::addFields([Field::EQ('b', 'two', ':b'), Field::EQ('z', 18, ':z')], [':a' => 1]),
|
||||
Parameters::addFields([Field::equal('b', 'two', ':b'), Field::equal('z', 18, ':z')], [':a' => 1]),
|
||||
'Field parameters not added correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Field names succeeds for PostgreSQL')]
|
||||
#[TestDox('fieldNames() succeeds for PostgreSQL')]
|
||||
public function testFieldNamesSucceedsForPostgreSQL(): void
|
||||
{
|
||||
try {
|
||||
@@ -105,7 +112,7 @@ class ParametersTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Field names succeeds for SQLite')]
|
||||
#[TestDox('fieldNames() succeeds for SQLite')]
|
||||
public function testFieldNamesSucceedsForSQLite(): void
|
||||
{
|
||||
try {
|
||||
@@ -117,6 +124,7 @@ class ParametersTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('fieldNames() fails when mode not set')]
|
||||
public function testFieldNamesFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -25,21 +25,23 @@ class CountTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds')]
|
||||
public function testAllSucceeds(): void
|
||||
{
|
||||
$this->assertEquals('SELECT COUNT(*) FROM a_table', Count::all('a_table'),
|
||||
'SELECT statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds')]
|
||||
public function testByFieldsSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals("SELECT COUNT(*) FROM somewhere WHERE data->>'errors' > :errors",
|
||||
Count::byFields('somewhere', [Field::GT('errors', 10, ':errors')]),
|
||||
Count::byFields('somewhere', [Field::greater('errors', 10, ':errors')]),
|
||||
'SELECT statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -47,14 +49,14 @@ class CountTest extends TestCase
|
||||
'SELECT statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Count::byContains('');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -62,7 +64,7 @@ class CountTest extends TestCase
|
||||
Count::byJsonPath('a_table'), 'SELECT statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -25,7 +25,7 @@ class DefinitionTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('Ensure table succeeds for PosgtreSQL')]
|
||||
#[TestDox('ensureTable() succeeds for PosgtreSQL')]
|
||||
public function testEnsureTableSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -33,7 +33,7 @@ class DefinitionTest extends TestCase
|
||||
Definition::ensureTable('documents'), 'CREATE TABLE statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Ensure table succeeds for SQLite')]
|
||||
#[TestDox('ensureTable() succeeds for SQLite')]
|
||||
public function testEnsureTableSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -41,18 +41,21 @@ class DefinitionTest extends TestCase
|
||||
'CREATE TABLE statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('ensureTable() fails when mode not set')]
|
||||
public function testEnsureTableFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Definition::ensureTable('boom');
|
||||
}
|
||||
|
||||
#[TestDox('ensureIndexOn() succeeds without schema single ascending field')]
|
||||
public function testEnsureIndexOnSucceedsWithoutSchemaSingleAscendingField(): void
|
||||
{
|
||||
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_test_fields ON test ((data->>'details'))",
|
||||
Definition::ensureIndexOn('test', 'fields', ['details']), 'CREATE INDEX statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('ensureIndexOn() succeeds with schema multiple fields')]
|
||||
public function testEnsureIndexOnSucceedsWithSchemaMultipleFields(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
@@ -61,12 +64,14 @@ class DefinitionTest extends TestCase
|
||||
'CREATE INDEX statement not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('ensureKey() succeeds')]
|
||||
public function testEnsureKeySucceeds(): void
|
||||
{
|
||||
$this->assertEquals("CREATE UNIQUE INDEX IF NOT EXISTS idx_tbl_key ON tbl ((data->>'id'))",
|
||||
Definition::ensureKey('tbl'), 'CREATE INDEX statement for document key not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('ensureDocumentIndexOn() succeeds for schema and Full')]
|
||||
public function testEnsureDocumentIndexOnSucceedsForSchemaAndFull(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -74,6 +79,7 @@ class DefinitionTest extends TestCase
|
||||
Definition::ensureDocumentIndexOn('my.tbl', DocumentIndex::Full));
|
||||
}
|
||||
|
||||
#[TestDox('ensureDocumentIndexOn() succeeds for no schema and Optimized')]
|
||||
public function testEnsureDocumentIndexOnSucceedsForNoSchemaAndOptimized(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -81,7 +87,7 @@ class DefinitionTest extends TestCase
|
||||
Definition::ensureDocumentIndexOn('it', DocumentIndex::Optimized));
|
||||
}
|
||||
|
||||
#[TestDox('Ensure document index on fails for non PostgreSQL')]
|
||||
#[TestDox('ensureDocumentIndexOn() fails for non PostgreSQL')]
|
||||
public function testEnsureDocumentIndexOnFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -24,7 +24,7 @@ class DeleteTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds')]
|
||||
#[TestDox('byId() succeeds')]
|
||||
public function testByIdSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -32,15 +32,17 @@ class DeleteTest extends TestCase
|
||||
'DELETE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds')]
|
||||
public function testByFieldsSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals("DELETE FROM my_table WHERE data->>'value' < :max AND data->>'value' >= :min",
|
||||
Delete::byFields('my_table', [Field::LT('value', 99, ':max'), Field::GE('value', 18, ':min')]),
|
||||
Delete::byFields('my_table',
|
||||
[Field::less('value', 99, ':max'), Field::greaterOrEqual('value', 18, ':min')]),
|
||||
'DELETE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -48,14 +50,14 @@ class DeleteTest extends TestCase
|
||||
'DELETE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Delete::byContains('');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -63,7 +65,7 @@ class DeleteTest extends TestCase
|
||||
Delete::byJsonPath('here'), 'DELETE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -24,6 +24,7 @@ class ExistsTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
|
||||
#[TestDox('query() succeeds')]
|
||||
public function testQuerySucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -31,7 +32,7 @@ class ExistsTest extends TestCase
|
||||
'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds')]
|
||||
#[TestDox('byId() succeeds')]
|
||||
public function testByIdSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -39,15 +40,16 @@ class ExistsTest extends TestCase
|
||||
'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds')]
|
||||
public function testByFieldsSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM box WHERE data->>'status' <> :status)",
|
||||
Exists::byFields('box', [Field::NE('status', 'occupied', ':status')]),
|
||||
Exists::byFields('box', [Field::notEqual('status', 'occupied', ':status')]),
|
||||
'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -55,14 +57,14 @@ class ExistsTest extends TestCase
|
||||
Exists::byContains('pocket'), 'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Exists::byContains('');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -70,7 +72,7 @@ class ExistsTest extends TestCase
|
||||
Exists::byJsonPath('lint'), 'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -24,7 +24,7 @@ class FindTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds')]
|
||||
#[TestDox('byId() succeeds')]
|
||||
public function testByIdSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -32,16 +32,17 @@ class FindTest extends TestCase
|
||||
'SELECT query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds')]
|
||||
public function testByFieldsSucceeds(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals("SELECT data FROM there WHERE data->>'active' = :act OR data->>'locked' = :lock",
|
||||
Find::byFields('there', [Field::EQ('active', true, ':act'), Field::EQ('locked', true, ':lock')],
|
||||
Find::byFields('there', [Field::equal('active', true, ':act'), Field::equal('locked', true, ':lock')],
|
||||
FieldMatch::Any),
|
||||
'SELECT query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -49,14 +50,14 @@ class FindTest extends TestCase
|
||||
'SELECT query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Find::byContains('');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -64,7 +65,7 @@ class FindTest extends TestCase
|
||||
Find::byJsonPath('light'), 'SELECT query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -24,7 +24,7 @@ class PatchTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
parent::tearDown();
|
||||
}
|
||||
#[TestDox('By ID succeeds for PostgreSQL')]
|
||||
#[TestDox('byId() succeeds for PostgreSQL')]
|
||||
public function testByIdSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -32,7 +32,7 @@ class PatchTest extends TestCase
|
||||
Patch::byId('doc_table'), 'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds for SQLite')]
|
||||
#[TestDox('byId() succeeds for SQLite')]
|
||||
public function testByIdSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -40,37 +40,39 @@ class PatchTest extends TestCase
|
||||
Patch::byId('my_table'), 'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By ID fails when mode not set')]
|
||||
#[TestDox('byId() fails when mode not set')]
|
||||
public function testByIdFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Patch::byId('oof');
|
||||
}
|
||||
|
||||
#[TestDox('By fields succeeds for PostgreSQL')]
|
||||
#[TestDox('byFields() succeeds for PostgreSQL')]
|
||||
public function testByFieldsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals("UPDATE that SET data = data || :data WHERE (data->>'something')::numeric < :some",
|
||||
Patch::byFields('that', [Field::LT('something', 17, ':some')]), 'Patch UPDATE statement is not correct');
|
||||
Patch::byFields('that', [Field::less('something', 17, ':some')]), 'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By fields succeeds for SQLite')]
|
||||
#[TestDox('byFields() succeeds for SQLite')]
|
||||
public function testByFieldsSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals(
|
||||
"UPDATE a_table SET data = json_patch(data, json(:data)) WHERE data->>'something' > :it",
|
||||
Patch::byFields('a_table', [Field::GT('something', 17, ':it')]), 'Patch UPDATE statement is not correct');
|
||||
Patch::byFields('a_table', [Field::greater('something', 17, ':it')]),
|
||||
'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() fails when mode not set')]
|
||||
public function testByFieldsFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Patch::byFields('oops', []);
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -78,14 +80,14 @@ class PatchTest extends TestCase
|
||||
'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Patch::byContains('');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -93,7 +95,7 @@ class PatchTest extends TestCase
|
||||
Patch::byJsonPath('that'), 'Patch UPDATE statement is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -24,7 +24,7 @@ class RemoveFieldsTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
|
||||
#[TestDox('Update succeeds for PostgreSQL')]
|
||||
#[TestDox('update() succeeds for PostgreSQL')]
|
||||
public function testUpdateSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -32,7 +32,7 @@ class RemoveFieldsTest extends TestCase
|
||||
RemoveFields::update('taco', [':names' => "{one,two}"], 'it = true'), 'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('Update succeeds for SQLite')]
|
||||
#[TestDox('update() succeeds for SQLite')]
|
||||
public function testUpdateSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
@@ -41,22 +41,23 @@ class RemoveFieldsTest extends TestCase
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('update() fails when mode not set')]
|
||||
public function testUpdateFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
RemoveFields::update('wow', [], '');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds for PostgreSQL')]
|
||||
public function testByIdSucceedsForPostgreSQL()
|
||||
#[TestDox('byId() succeeds for PostgreSQL')]
|
||||
public function testByIdSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals("UPDATE churro SET data = data - :bite::text[] WHERE data->>'id' = :id",
|
||||
RemoveFields::byId('churro', Parameters::fieldNames(':bite', ['byte'])), 'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds for SQLite')]
|
||||
public function testByIdSucceedsForSQLite()
|
||||
#[TestDox('byId() succeeds for SQLite')]
|
||||
public function testByIdSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals("UPDATE quesadilla SET data = json_remove(data, :bite0) WHERE data->>'id' = :id",
|
||||
@@ -64,41 +65,42 @@ class RemoveFieldsTest extends TestCase
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By ID fails when mode not set')]
|
||||
#[TestDox('byId() fails when mode not set')]
|
||||
public function testByIdFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
RemoveFields::byId('oof', []);
|
||||
}
|
||||
|
||||
#[TestDox('By fields succeeds for PostgreSQL')]
|
||||
public function testByFieldsSucceedsForPostgreSQL()
|
||||
#[TestDox('byFields() succeeds for PostgreSQL')]
|
||||
public function testByFieldsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals("UPDATE enchilada SET data = data - :sauce::text[] WHERE data->>'cheese' = :queso",
|
||||
RemoveFields::byFields('enchilada', [Field::EQ('cheese', 'jack', ':queso')],
|
||||
RemoveFields::byFields('enchilada', [Field::equal('cheese', 'jack', ':queso')],
|
||||
Parameters::fieldNames(':sauce', ['white'])),
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By fields succeeds for SQLite')]
|
||||
public function testByFieldsSucceedsForSQLite()
|
||||
#[TestDox('byFields() succeeds for SQLite')]
|
||||
public function testByFieldsSucceedsForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
$this->assertEquals(
|
||||
"UPDATE chimichanga SET data = json_remove(data, :filling0) WHERE data->>'side' = :rice",
|
||||
RemoveFields::byFields('chimichanga', [Field::EQ('side', 'beans', ':rice')],
|
||||
RemoveFields::byFields('chimichanga', [Field::equal('side', 'beans', ':rice')],
|
||||
Parameters::fieldNames(':filling', ['beef'])),
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() fails when mode not set')]
|
||||
public function testByFieldsFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
RemoveFields::byFields('boing', [], []);
|
||||
}
|
||||
|
||||
#[TestDox('By contains succeeds for PostgreSQL')]
|
||||
#[TestDox('byContains() succeeds for PostgreSQL')]
|
||||
public function testByContainsSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -107,14 +109,14 @@ class RemoveFieldsTest extends TestCase
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By contains fails for non PostgreSQL')]
|
||||
#[TestDox('byContains() fails for non PostgreSQL')]
|
||||
public function testByContainsFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
RemoveFields::byContains('', []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path succeeds for PostgreSQL')]
|
||||
#[TestDox('byJsonPath() succeeds for PostgreSQL')]
|
||||
public function testByJsonPathSucceedsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -124,7 +126,7 @@ class RemoveFieldsTest extends TestCase
|
||||
'UPDATE statement not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails for non PostgreSQL')]
|
||||
#[TestDox('byJsonPath() fails for non PostgreSQL')]
|
||||
public function testByJsonPathFailsForNonPostgreSQL(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -28,45 +28,53 @@ class QueryTest extends TestCase
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
|
||||
#[TestDox('selectFromTable() succeeds')]
|
||||
public function testSelectFromTableSucceeds(): void
|
||||
{
|
||||
$this->assertEquals('SELECT data FROM testing', Query::selectFromTable('testing'),
|
||||
'Query not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('whereByFields() succeeds for single field')]
|
||||
public function testWhereByFieldsSucceedsForSingleField(): void
|
||||
{
|
||||
$this->assertEquals("data->>'test_field' <= :it",
|
||||
Query::whereByFields([Field::LE('test_field', '', ':it')]), 'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
public function testWhereByFieldsSucceedsForMultipleFieldsAll(): void
|
||||
{
|
||||
$this->assertEquals("data->>'test_field' <= :it AND data->>'other_field' = :other",
|
||||
Query::whereByFields([Field::LE('test_field', '', ':it'), Field::EQ('other_field', '', ':other')]),
|
||||
Query::whereByFields([Field::lessOrEqual('test_field', '', ':it')]),
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('whereByFields() succeeds for multiple fields All')]
|
||||
public function testWhereByFieldsSucceedsForMultipleFieldsAll(): void
|
||||
{
|
||||
$this->assertEquals("data->>'test_field' <= :it AND data->>'other_field' = :other",
|
||||
Query::whereByFields(
|
||||
[Field::lessOrEqual('test_field', '', ':it'), Field::equal('other_field', '', ':other')]),
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('whereByFields() succeeds for multiple fields Any')]
|
||||
public function testWhereByFieldsSucceedsForMultipleFieldsAny(): void
|
||||
{
|
||||
$this->assertEquals("data->>'test_field' <= :it OR data->>'other_field' = :other",
|
||||
Query::whereByFields([Field::LE('test_field', '', ':it'), Field::EQ('other_field', '', ':other')],
|
||||
Query::whereByFields(
|
||||
[Field::lessOrEqual('test_field', '', ':it'), Field::equal('other_field', '', ':other')],
|
||||
FieldMatch::Any),
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Where by ID succeeds with default parameter')]
|
||||
#[TestDox('whereById() succeeds with default parameter')]
|
||||
public function testWhereByIdSucceedsWithDefaultParameter(): void
|
||||
{
|
||||
$this->assertEquals("data->>'id' = :id", Query::whereById(), 'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Where by ID succeeds with specific parameter')]
|
||||
#[TestDox('whereById() succeeds with specific parameter')]
|
||||
public function testWhereByIdSucceedsWithSpecificParameter(): void
|
||||
{
|
||||
$this->assertEquals("data->>'id' = :di", Query::whereById(':di'), 'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('whereDataContains() succeeds with default parameter')]
|
||||
public function testWhereDataContainsSucceedsWithDefaultParameter(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -74,13 +82,14 @@ class QueryTest extends TestCase
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('whereDataContains() succeeds with specific parameter')]
|
||||
public function testWhereDataContainsSucceedsWithSpecifiedParameter(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals('data @> :it', Query::whereDataContains(':it'), 'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Where data contains fails if not PostgreSQL')]
|
||||
#[TestDox('whereDataContains() fails if not PostgreSQL')]
|
||||
public function testWhereDataContainsFailsIfNotPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(null);
|
||||
@@ -88,7 +97,7 @@ class QueryTest extends TestCase
|
||||
Query::whereDataContains();
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches succeeds with default parameter')]
|
||||
#[TestDox('whereJsonPathMatches() succeeds with default parameter')]
|
||||
public function testWhereJsonPathMatchesSucceedsWithDefaultParameter(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -96,7 +105,7 @@ class QueryTest extends TestCase
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches succeeds with specified parameter')]
|
||||
#[TestDox('whereJsonPathMatches() succeeds with specified parameter')]
|
||||
public function testWhereJsonPathMatchesSucceedsWithSpecifiedParameter(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -104,7 +113,7 @@ class QueryTest extends TestCase
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches fails if not PostgreSQL')]
|
||||
#[TestDox('whereJsonPathMatches() fails if not PostgreSQL')]
|
||||
public function testWhereJsonPathMatchesFailsIfNotPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(null);
|
||||
@@ -112,7 +121,7 @@ class QueryTest extends TestCase
|
||||
Query::whereJsonPathMatches();
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with no auto-ID for PostgreSQL')]
|
||||
#[TestDox('insert() succeeds with no auto-ID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithNoAutoIdForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -120,14 +129,14 @@ class QueryTest extends TestCase
|
||||
'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with no auto-ID for SQLite')]
|
||||
#[TestDox('insert() succeeds with no auto-ID for SQLite')]
|
||||
public function testInsertSucceedsWithNoAutoIdForSQLite(): void
|
||||
{
|
||||
$this->assertEquals('INSERT INTO test_tbl VALUES (:data)', Query::insert('test_tbl'),
|
||||
'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto numeric ID for PostgreSQL')]
|
||||
#[TestDox('insert() succeeds with auto numeric ID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithAutoNumericIdForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -137,7 +146,7 @@ class QueryTest extends TestCase
|
||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto numeric ID for SQLite')]
|
||||
#[TestDox('insert() succeeds with auto numeric ID for SQLite')]
|
||||
public function testInsertSucceedsWithAutoNumericIdForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
@@ -146,7 +155,7 @@ class QueryTest extends TestCase
|
||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto UUID for PostgreSQL')]
|
||||
#[TestDox('insert() succeeds with auto UUID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithAutoUuidForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -156,7 +165,7 @@ class QueryTest extends TestCase
|
||||
$this->assertStringEndsWith("\"}')", $query, 'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto UUID for SQLite')]
|
||||
#[TestDox('insert() succeeds with auto UUID for SQLite')]
|
||||
public function testInsertSucceedsWithAutoUuidForSQLite(): void
|
||||
{
|
||||
$query = Query::insert('test_tbl', AutoId::UUID);
|
||||
@@ -165,7 +174,7 @@ class QueryTest extends TestCase
|
||||
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto random string for PostgreSQL')]
|
||||
#[TestDox('insert() succeeds with auto random string for PostgreSQL')]
|
||||
public function testInsertSucceedsWithAutoRandomStringForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
@@ -182,7 +191,7 @@ class QueryTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto random string for SQLite')]
|
||||
#[TestDox('insert() succeeds with auto random string for SQLite')]
|
||||
public function testInsertSucceedsWithAutoRandomStringForSQLite(): void
|
||||
{
|
||||
$query = Query::insert('test_tbl', AutoId::RandomString);
|
||||
@@ -193,6 +202,7 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals(16, strlen($id), "Generated ID [$id] should have been 16 characters long");
|
||||
}
|
||||
|
||||
#[TestDox('insert() fails when mode not set')]
|
||||
public function testInsertFailsWhenModeNotSet(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
@@ -200,6 +210,7 @@ class QueryTest extends TestCase
|
||||
Query::insert('kaboom');
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds')]
|
||||
public function testSaveSucceeds(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
@@ -207,9 +218,87 @@ class QueryTest extends TestCase
|
||||
Query::save('test_tbl'), 'INSERT ON CONFLICT statement not constructed correctly');
|
||||
}
|
||||
|
||||
public function testUpdateSucceeds()
|
||||
#[TestDox('update() succeeds')]
|
||||
public function testUpdateSucceeds(): void
|
||||
{
|
||||
$this->assertEquals("UPDATE testing SET data = :data WHERE data->>'id' = :id", Query::update('testing'),
|
||||
'UPDATE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with no fields for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithNoFieldsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals('', Query::orderBy([]), 'ORDER BY should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with no fields for SQLite')]
|
||||
public function testOrderBySucceedsWithNoFieldsForSQLite(): void
|
||||
{
|
||||
$this->assertEquals('', Query::orderBy([]), 'ORDER BY should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with one field and no direction for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithOneFieldAndNoDirectionForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY data->>'TestField'", Query::orderBy([Field::named('TestField')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with one field and no direction for SQLite')]
|
||||
public function testOrderBySucceedsWithOneFieldAndNoDirectionForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->>'TestField'", Query::orderBy([Field::named('TestField')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with multiple fields and direction for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithMultipleFieldsAndDirectionForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY data#>>'{Nested,Test,Field}' DESC, data->>'AnotherField', data->>'It' DESC",
|
||||
Query::orderBy(
|
||||
[Field::named('Nested.Test.Field DESC'), Field::named('AnotherField'), Field::named('It DESC')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with multiple fields and direction for SQLite')]
|
||||
public function testOrderBySucceedsWithMultipleFieldsAndDirectionForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->'Nested'->'Test'->>'Field' DESC, data->>'AnotherField', data->>'It' DESC",
|
||||
Query::orderBy(
|
||||
[Field::named('Nested.Test.Field DESC'), Field::named('AnotherField'), Field::named('It DESC')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with numeric field for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithNumericFieldForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY (data->>'Test')::numeric", Query::orderBy([Field::named('n:Test')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with numeric field for SQLite')]
|
||||
public function testOrderBySucceedsWithNumericFieldForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->>'Test'", Query::orderBy([Field::named('n:Test')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with case-insensitive ordering for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithCaseInsensitiveOrderingForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY LOWER(data#>>'{Test,Field}') DESC NULLS FIRST",
|
||||
Query::orderBy([Field::named('i:Test.Field DESC NULLS FIRST')]), 'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with case-insensitive ordering for SQLite')]
|
||||
public function testOrderBySucceedsWithCaseInsensitiveOrderingForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->'Test'->>'Field' COLLATE NOCASE ASC NULLS LAST",
|
||||
Query::orderBy([Field::named('i:Test.Field ASC NULLS LAST')]), 'ORDER BY not constructed correctly');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user