Add field match enum

This commit is contained in:
2024-06-10 11:00:08 -04:00
parent 1f1f06679f
commit 9729c50c00
19 changed files with 120 additions and 57 deletions

View File

@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
namespace Test\Unit;
use BitBadger\PDODocument\FieldMatch;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the FieldMatch enum
*/
class FieldMatchTest extends TestCase
{
public function testToStringSucceedsForAll(): void
{
$this->assertEquals('AND', FieldMatch::All->toString(), 'All should have returned AND');
}
public function testToStringSucceedsForAny(): void
{
$this->assertEquals('OR', FieldMatch::Any->toString(), 'Any should have returned OR');
}
}

View File

@@ -2,7 +2,7 @@
namespace Test\Unit\Query;
use BitBadger\PDODocument\{Configuration, Field, Mode};
use BitBadger\PDODocument\{Configuration, Field, FieldMatch, Mode};
use BitBadger\PDODocument\Query\Find;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
@@ -32,7 +32,8 @@ class FindTest extends TestCase
public function testByFieldsSucceeds(): void
{
$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')], 'OR'),
Find::byFields('there', [Field::EQ('active', true, ':act'), Field::EQ('locked', true, ':lock')],
FieldMatch::Any),
'SELECT query not generated correctly');
}
}

View File

@@ -2,7 +2,7 @@
namespace Test\Unit;
use BitBadger\PDODocument\{Configuration, Field, Mode, Query};
use BitBadger\PDODocument\{Configuration, Field, FieldMatch, Mode, Query};
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
@@ -33,17 +33,18 @@ class QueryTest extends TestCase
Query::whereByFields([Field::LE('test_field', '', ':it')]), 'WHERE fragment not constructed correctly');
}
public function testWhereByFieldsSucceedsForMultipleFields(): void
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')]),
'WHERE fragment not constructed correctly');
}
public function testWhereByFieldsSucceedsForMultipleFieldsWithOr(): void
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')], 'OR'),
Query::whereByFields([Field::LE('test_field', '', ':it'), Field::EQ('other_field', '', ':other')],
FieldMatch::Any),
'WHERE fragment not constructed correctly');
}