pdo-document/tests/unit/Query/DeleteTest.php
Daniel J. Summers 2d8f8b6e87 Finish tests
- Add sub-doc handling for SQLite fields
- Add casting for PostgreSQL BT on numeric value
- Add hasItems() to DocumentList
- Fix SQL syntax problems exposed by tests
2024-06-08 10:49:52 -04:00

39 lines
1.1 KiB
PHP

<?php declare(strict_types=1);
namespace Test\Unit\Query;
use BitBadger\PDODocument\{Configuration, Field, Mode};
use BitBadger\PDODocument\Query\Delete;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Delete class
*/
class DeleteTest 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("DELETE FROM over_there WHERE data->>'id' = :id", Delete::byId('over_there'),
'DELETE statement not constructed correctly');
}
public function testByFieldsSucceeds(): void
{
$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 statement not constructed correctly');
}
}