2024-06-08 23:58:45 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Test\Unit\Query;
|
|
|
|
|
2024-06-11 11:07:56 +00:00
|
|
|
use BitBadger\PDODocument\{Configuration, Field, FieldMatch, Mode};
|
2024-06-08 23:58:45 +00:00
|
|
|
use BitBadger\PDODocument\Query\Find;
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Find class
|
|
|
|
*/
|
|
|
|
class FindTest extends TestCase
|
|
|
|
{
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
Configuration::$mode = Mode::SQLite;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
Configuration::$mode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('By ID succeeds')]
|
|
|
|
public function testByIdSucceeds(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals("SELECT data FROM here WHERE data->>'id' = :id", Find::byId('here'),
|
|
|
|
'SELECT query not generated correctly');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testByFieldsSucceeds(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals("SELECT data FROM there WHERE data->>'active' = :act OR data->>'locked' = :lock",
|
2024-06-11 11:07:56 +00:00
|
|
|
Find::byFields('there', [Field::EQ('active', true, ':act'), Field::EQ('locked', true, ':lock')],
|
|
|
|
FieldMatch::Any),
|
2024-06-08 23:58:45 +00:00
|
|
|
'SELECT query not generated correctly');
|
|
|
|
}
|
|
|
|
}
|