Add in/inArray; expand Field ctr func names
This commit is contained in:
@@ -41,13 +41,13 @@ class CountTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsForANumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('num_value', 10, 20)]);
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
||||
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsForANonNumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]);
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
||||
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
||||
}
|
||||
|
||||
|
||||
@@ -52,14 +52,14 @@ class DeleteTest extends TestCase
|
||||
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
|
||||
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -113,7 +113,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -129,7 +129,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
@@ -146,7 +146,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -177,12 +177,12 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
@@ -197,7 +197,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
@@ -212,7 +212,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -228,7 +228,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -244,7 +244,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
@@ -261,7 +261,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
|
||||
@@ -48,13 +48,13 @@ class ExistsTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
||||
{
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]),
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
||||
'There should have been existing documents');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||
{
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]),
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
||||
'There should not have been any existing documents');
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class FindTest extends TestCase
|
||||
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
||||
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
|
||||
{
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::NEX('absent')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absent')]);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 18, NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
@@ -78,7 +78,7 @@ class FindTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 15)], TestDocument::class);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
@@ -87,7 +87,7 @@ class FindTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 100)], TestDocument::class);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
@@ -128,21 +128,21 @@ class FindTest extends TestCase
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
|
||||
@@ -54,14 +54,14 @@ class PatchTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]);
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 77)]);
|
||||
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
||||
{
|
||||
$fields = [Field::EQ('value', 'burgundy')];
|
||||
$fields = [Field::equal('value', 'burgundy')];
|
||||
$this->assertEquals(0, Count::byFields(ThrowawayDb::TABLE, $fields), 'There should be no matching documents');
|
||||
Patch::byFields(ThrowawayDb::TABLE, $fields, ['foo' => 'green']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
|
||||
@@ -61,21 +61,21 @@ class RemoveFieldsTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['nada']);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::NE('missing', 'nope')], ['value']);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,13 @@ class CountTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsForANumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('num_value', 10, 20)]);
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
||||
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsForANonNumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]);
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
||||
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
||||
}
|
||||
|
||||
|
||||
@@ -52,14 +52,14 @@ class DeleteTest extends TestCase
|
||||
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
|
||||
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -113,7 +113,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -129,7 +129,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
@@ -146,7 +146,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -177,12 +177,12 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
@@ -197,7 +197,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
@@ -212,7 +212,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -228,7 +228,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -244,7 +244,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
@@ -261,7 +261,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
|
||||
@@ -48,13 +48,13 @@ class ExistsTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
||||
{
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]),
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
||||
'There should have been existing documents');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||
{
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]),
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
||||
'There should not have been any existing documents');
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class FindTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 15)], TestDocument::class);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
@@ -86,7 +86,7 @@ class FindTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 100)], TestDocument::class);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
@@ -106,21 +106,21 @@ class FindTest extends TestCase
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'absent')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
|
||||
@@ -52,14 +52,14 @@ class PatchTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]);
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 77)]);
|
||||
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burgundy')], ['foo' => 'green']);
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'burgundy')], ['foo' => 'green']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
|
||||
@@ -61,21 +61,21 @@ class RemoveFieldsTest extends TestCase
|
||||
|
||||
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['nada']);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::NE('missing', 'nope')], ['value']);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
|
||||
@@ -18,121 +18,123 @@ use PHPUnit\Framework\TestCase;
|
||||
#[TestDox('Field (Unit tests)')]
|
||||
class FieldTest extends TestCase
|
||||
{
|
||||
#[TestDox('Append parameter succeeds for EX')]
|
||||
public function testAppendParameterSucceedsForEX(): void
|
||||
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('Append parameter 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
|
||||
public function testAppendParameterSucceedsForBetween(): void
|
||||
{
|
||||
$this->assertEquals(['@nummin' => 5, '@nummax' => 9], Field::BT('exists', 5, 9, '@num')->appendParameter([]),
|
||||
$this->assertEquals(['@nummin' => 5, '@nummax' => 9],
|
||||
Field::between('exists', 5, 9, '@num')->appendParameter([]),
|
||||
'BT should have appended min and max parameters');
|
||||
}
|
||||
|
||||
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('To where 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::EX('that_field')->toWhere(),
|
||||
$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 EX without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForEXWithoutQualifierForSQLite(): void
|
||||
#[TestDox('To where 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::EX('that_field')->toWhere(),
|
||||
$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 NEX without qualifier for PostgreSQL')]
|
||||
public function testToWhereSucceedsForNEXWithoutQualifierForPostgreSQL(): void
|
||||
#[TestDox('To where succeeds for notExists without qualifier for PostgreSQL')]
|
||||
public function testToWhereSucceedsForNotExistsWithoutQualifierForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(),
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for NEX without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForNEXWithoutQualifierForSQLite(): void
|
||||
#[TestDox('To where succeeds for notExists without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForNotExistsWithoutQualifierForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::NEX('a_field')->toWhere(),
|
||||
$this->assertEquals("data->>'a_field' IS NULL", Field::notExists('a_field')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
Configuration::overrideMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT without qualifier for SQLite')]
|
||||
public function testToWhereSucceedsForBTWithoutQualifierForSQLite(): void
|
||||
#[TestDox('To where 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::BT('age', 13, 17, '@age')->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
$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('To where succeeds for BT without qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBTWithoutQualifierForPostgreSQLWithNumericRange(): void
|
||||
#[TestDox('To where 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('To where 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('To where 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 +143,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with numeric range')]
|
||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNumericRange(): void
|
||||
#[TestDox('To where 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 +157,12 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('To where succeeds for BT with qualifier for PostgreSQL with non-numeric range')]
|
||||
public function testToWhereSucceedsForBTWithQualifierForPostgreSQLWithNonNumericRange(): void
|
||||
#[TestDox('To where 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');
|
||||
@@ -174,7 +176,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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);
|
||||
@@ -186,7 +188,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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);
|
||||
@@ -198,7 +200,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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');
|
||||
@@ -212,7 +214,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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');
|
||||
@@ -226,7 +228,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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');
|
||||
@@ -240,7 +242,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
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');
|
||||
@@ -254,7 +256,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
||||
$field = Field::equal('sub.foo.bar', 22, '@it');
|
||||
$this->assertEquals("(data#>>'{sub,foo,bar}')::numeric = @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
@@ -267,7 +269,7 @@ class FieldTest extends TestCase
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
$field = Field::EQ('sub.foo.bar', 22, '@it');
|
||||
$field = Field::equal('sub.foo.bar', 22, '@it');
|
||||
$this->assertEquals("data->>'sub'->>'foo'->>'bar' = @it", $field->toWhere(),
|
||||
'WHERE fragment not generated correctly');
|
||||
} finally {
|
||||
@@ -275,178 +277,178 @@ class FieldTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('EQ succeeds without parameter')]
|
||||
public function testEQSucceedsWithoutParameter(): void
|
||||
#[TestDox('equal succeeds without parameter')]
|
||||
public function testEqualSucceedsWithoutParameter(): 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('exists succeeds')]
|
||||
public function testExistsSucceeds(): void
|
||||
{
|
||||
$field = Field::EX('be_there');
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -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('To SQL 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('To SQL 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('To SQL 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('To SQL 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('To SQL 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('To SQL 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('To SQL 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('To SQL 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('To SQL succeeds for InArray')]
|
||||
public function testToSQLSucceedsForInArray(): void
|
||||
{
|
||||
$this->assertEquals('?|', Op::InArray->toSQL(), 'InArray SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL succeeds for Exists')]
|
||||
public function testToSQLSucceedsForExists(): void
|
||||
{
|
||||
$this->assertEquals('IS NOT NULL', Op::Exists->toSQL(), 'Exists SQL operator incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('To SQL 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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ class ParametersTest extends TestCase
|
||||
|
||||
public function testNameFieldsSucceeds(): void
|
||||
{
|
||||
$named = Parameters::nameFields([Field::EQ('it', 17), Field::EQ('also', 22, ':also'), Field::EQ('other', 24)]);
|
||||
$named = Parameters::nameFields(
|
||||
[Field::equal('it', 17), Field::equal('also', 22, ':also'), Field::equal('other', 24)]);
|
||||
$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');
|
||||
@@ -89,7 +90,7 @@ class ParametersTest extends TestCase
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class CountTest extends TestCase
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ class DeleteTest extends TestCase
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class ExistsTest extends TestCase
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class PatchTest extends TestCase
|
||||
{
|
||||
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')]
|
||||
@@ -61,7 +61,8 @@ class PatchTest extends TestCase
|
||||
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');
|
||||
}
|
||||
|
||||
public function testByFieldsFailsWhenModeNotSet(): void
|
||||
|
||||
@@ -76,7 +76,7 @@ class RemoveFieldsTest extends TestCase
|
||||
{
|
||||
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');
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class RemoveFieldsTest extends TestCase
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -37,20 +37,23 @@ class QueryTest extends TestCase
|
||||
public function testWhereByFieldsSucceedsForSingleField(): void
|
||||
{
|
||||
$this->assertEquals("data->>'test_field' <= :it",
|
||||
Query::whereByFields([Field::LE('test_field', '', ':it')]), 'WHERE fragment not constructed correctly');
|
||||
Query::whereByFields([Field::lessOrEqual('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'), Field::equal('other_field', '', ':other')]),
|
||||
'WHERE fragment not constructed correctly');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user