Add PostgreSQL Support (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2024-06-21 13:46:41 +00:00
parent 330e272187
commit 124426fa12
61 changed files with 2290 additions and 223 deletions

View File

@@ -2,7 +2,7 @@
namespace Test\Unit\Query;
use BitBadger\PDODocument\{Configuration, Field, FieldMatch, Mode};
use BitBadger\PDODocument\{Configuration, DocumentException, Field, FieldMatch, Mode};
use BitBadger\PDODocument\Query\Find;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
@@ -10,13 +10,9 @@ use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Find class
*/
#[TestDox('Find Queries (Unit tests)')]
class FindTest extends TestCase
{
protected function setUp(): void
{
Configuration::$mode = Mode::SQLite;
}
protected function tearDown(): void
{
Configuration::$mode = null;
@@ -25,15 +21,47 @@ class FindTest extends TestCase
#[TestDox('By ID succeeds')]
public function testByIdSucceeds(): void
{
Configuration::$mode = Mode::SQLite;
$this->assertEquals("SELECT data FROM here WHERE data->>'id' = :id", Find::byId('here'),
'SELECT query not generated correctly');
}
public function testByFieldsSucceeds(): void
{
Configuration::$mode = 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')],
FieldMatch::Any),
'SELECT query not generated correctly');
}
#[TestDox('By contains succeeds for PostgreSQL')]
public function testByContainsSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('SELECT data FROM disc WHERE data @> :criteria', Find::byContains('disc'),
'SELECT query not generated correctly');
}
#[TestDox('By contains fails for non PostgreSQL')]
public function testByContainsFailsForNonPostgreSQL(): void
{
$this->expectException(DocumentException::class);
Find::byContains('');
}
#[TestDox('By JSON Path succeeds for PostgreSQL')]
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('SELECT data FROM light WHERE jsonb_path_exists(data, :path::jsonpath)',
Find::byJsonPath('light'), 'SELECT query not generated correctly');
}
#[TestDox('By JSON Path fails for non PostgreSQL')]
public function testByJsonPathFailsForNonPostgreSQL(): void
{
$this->expectException(DocumentException::class);
Find::byJsonPath('');
}
}