Add byContains and byJsonPath
- Add document index functions
This commit is contained in:
@@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase;
|
||||
/**
|
||||
* Unit tests for the Query class
|
||||
*/
|
||||
#[TestDox('Query (Unit tests)')]
|
||||
class QueryTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
@@ -60,6 +61,68 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals("data->>'id' = :di", Query::whereById(':di'), 'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
public function testWhereDataContainsSucceedsWithDefaultParameter(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$this->assertEquals('data @> :criteria', Query::whereDataContains(),
|
||||
'WHERE fragment not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testWhereDataContainsSucceedsWithSpecifiedParameter(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$this->assertEquals('data @> :it', Query::whereDataContains(':it'),
|
||||
'WHERE fragment not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Where data contains fails if not PostgreSQL')]
|
||||
public function testWhereDataContainsFailsIfNotPostgreSQL(): void
|
||||
{
|
||||
Configuration::$mode = null;
|
||||
$this->expectException(DocumentException::class);
|
||||
Query::whereDataContains();
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches succeeds with default parameter')]
|
||||
public function testWhereJsonPathMatchesSucceedsWithDefaultParameter(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$this->assertEquals('data @? :path::jsonpath', Query::whereJsonPathMatches(),
|
||||
'WHERE fragment not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches succeeds with specified parameter')]
|
||||
public function testWhereJsonPathMatchesSucceedsWithSpecifiedParameter(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$this->assertEquals('data @? :road::jsonpath', Query::whereJsonPathMatches(':road'),
|
||||
'WHERE fragment not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Where JSON Path matches fails if not PostgreSQL')]
|
||||
public function testWhereJsonPathMatchesFailsIfNotPostgreSQL(): void
|
||||
{
|
||||
Configuration::$mode = null;
|
||||
$this->expectException(DocumentException::class);
|
||||
Query::whereJsonPathMatches();
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with no auto-ID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithNoAutoIdForPostgreSQL(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user