2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
namespace Test\Integration\SQLite;
|
|
|
|
|
2024-06-21 13:46:41 +00:00
|
|
|
use BitBadger\PDODocument\{Count, DocumentException, Field};
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SQLite integration tests for the Count class
|
|
|
|
*/
|
|
|
|
#[TestDox('Count (SQLite integration)')]
|
|
|
|
class CountTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var string Database name for throwaway database */
|
|
|
|
private string $dbName;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->dbName = ThrowawayDb::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
ThrowawayDb::destroy($this->dbName);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAllSucceeds(): void
|
|
|
|
{
|
|
|
|
$count = Count::all(ThrowawayDb::TABLE);
|
|
|
|
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testByFieldsSucceedsForANumericRange(): void
|
|
|
|
{
|
|
|
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('num_value', 10, 20)]);
|
|
|
|
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testByFieldsSucceedsForANonNumericRange(): void
|
|
|
|
{
|
|
|
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]);
|
|
|
|
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
|
|
|
}
|
2024-06-21 13:46:41 +00:00
|
|
|
|
|
|
|
public function testByContainsFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Count::byContains('', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('By JSON Path fails')]
|
|
|
|
public function testByJsonPathFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Count::byJsonPath('', '');
|
|
|
|
}
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|