Derive mode from DSN function

- Add headers in all files
- Minor field name changes
This commit is contained in:
2024-07-20 21:47:21 -04:00
parent 1a37b009ea
commit d8330d828a
81 changed files with 1053 additions and 551 deletions

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Unit\Query;
@@ -15,12 +21,12 @@ class ExistsTest extends TestCase
{
protected function tearDown(): void
{
Configuration::$mode = null;
Configuration::overrideMode(null);
}
public function testQuerySucceeds(): void
{
Configuration::$mode = Mode::SQLite;
Configuration::overrideMode(Mode::SQLite);
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM abc WHERE def)', Exists::query('abc', 'def'),
'Existence query not generated correctly');
}
@@ -28,14 +34,14 @@ class ExistsTest extends TestCase
#[TestDox('By ID succeeds')]
public function testByIdSucceeds(): void
{
Configuration::$mode = Mode::SQLite;
Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM dox WHERE data->>'id' = :id)", Exists::byId('dox'),
'Existence query not generated correctly');
}
public function testByFieldsSucceeds(): void
{
Configuration::$mode = Mode::SQLite;
Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM box WHERE data->>'status' <> :status)",
Exists::byFields('box', [Field::NE('status', 'occupied', ':status')]),
'Existence query not generated correctly');
@@ -44,7 +50,7 @@ class ExistsTest extends TestCase
#[TestDox('By contains succeeds for PostgreSQL')]
public function testByContainsSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM pocket WHERE data @> :criteria)',
Exists::byContains('pocket'), 'Existence query not generated correctly');
}
@@ -59,7 +65,7 @@ class ExistsTest extends TestCase
#[TestDox('By JSON Path succeeds for PostgreSQL')]
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM lint WHERE jsonb_path_exists(data, :path::jsonpath))',
Exists::byJsonPath('lint'), 'Existence query not generated correctly');
}