Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
44
tests/unit/Query/ExistsTest.php
Normal file
44
tests/unit/Query/ExistsTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Test\Unit\Query;
|
||||
|
||||
use BitBadger\PDODocument\{Configuration, Field, Mode};
|
||||
use BitBadger\PDODocument\Query\Exists;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the Exists class
|
||||
*/
|
||||
class ExistsTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
|
||||
public function testQuerySucceeds(): void
|
||||
{
|
||||
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM abc WHERE def)', Exists::query('abc', 'def'),
|
||||
'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds')]
|
||||
public function testByIdSucceeds(): void
|
||||
{
|
||||
$this->assertEquals("SELECT EXISTS (SELECT 1 FROM dox WHERE data->>'id' = :id)", Exists::byId('dox'),
|
||||
'Existence query not generated correctly');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceeds(): void
|
||||
{
|
||||
$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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user