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,13 +21,13 @@ class PatchTest extends TestCase
{
protected function tearDown(): void
{
Configuration::$mode = null;
Configuration::overrideMode(null);
parent::tearDown();
}
#[TestDox('By ID succeeds for PostgreSQL')]
public function testByIdSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals("UPDATE doc_table SET data = data || :data WHERE data->>'id' = :id",
Patch::byId('doc_table'), 'Patch UPDATE statement is not correct');
}
@@ -29,7 +35,7 @@ class PatchTest extends TestCase
#[TestDox('By ID succeeds for SQLite')]
public function testByIdSucceedsForSQLite(): void
{
Configuration::$mode = Mode::SQLite;
Configuration::overrideMode(Mode::SQLite);
$this->assertEquals("UPDATE my_table SET data = json_patch(data, json(:data)) WHERE data->>'id' = :id",
Patch::byId('my_table'), 'Patch UPDATE statement is not correct');
}
@@ -44,7 +50,7 @@ class PatchTest extends TestCase
#[TestDox('By fields succeeds for PostgreSQL')]
public function testByFieldsSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
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');
}
@@ -52,7 +58,7 @@ class PatchTest extends TestCase
#[TestDox('By fields succeeds for SQLite')]
public function testByFieldsSucceedsForSQLite(): void
{
Configuration::$mode = Mode::SQLite;
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');
@@ -67,7 +73,7 @@ class PatchTest extends TestCase
#[TestDox('By contains succeeds for PostgreSQL')]
public function testByContainsSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals('UPDATE this SET data = data || :data WHERE data @> :criteria', Patch::byContains('this'),
'Patch UPDATE statement is not correct');
}
@@ -82,7 +88,7 @@ class PatchTest extends TestCase
#[TestDox('By JSON Path succeeds for PostgreSQL')]
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
Configuration::overrideMode(Mode::PgSQL);
$this->assertEquals('UPDATE that SET data = data || :data WHERE jsonb_path_exists(data, :path::jsonpath)',
Patch::byJsonPath('that'), 'Patch UPDATE statement is not correct');
}