pdo-document/tests/unit/Query/CountTest.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

32 lines
827 B
PHP

<?php declare(strict_types=1);
namespace Test\Unit\Query;
use BitBadger\PDODocument\{Configuration, Field, Mode};
use BitBadger\PDODocument\Query\Count;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Count class
*/
class CountTest extends TestCase
{
public function testAllSucceeds()
{
$this->assertEquals('SELECT COUNT(*) FROM a_table', Count::all('a_table'),
'SELECT statement not generated correctly');
}
public function testByFieldsSucceeds()
{
Configuration::$mode = Mode::SQLite;
try {
$this->assertEquals("SELECT COUNT(*) FROM somewhere WHERE data->>'errors' > :errors",
Count::byFields('somewhere', [Field::GT('errors', 10, ':errors')]));
} finally {
Configuration::$mode = null;
}
}
}