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\{DocumentException, Exists, Field};
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SQLite integration tests for the Exists class
|
|
|
|
*/
|
|
|
|
#[TestDox('Exists (SQLite integration)')]
|
|
|
|
class ExistsTest 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('By ID succeeds when a document exists')]
|
|
|
|
public function testByIdSucceedsWhenADocumentExists(): void
|
|
|
|
{
|
|
|
|
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('By ID succeeds when a document does not exist')]
|
|
|
|
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
|
|
|
|
{
|
|
|
|
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
|
|
|
'There should not have been an existing document');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
|
|
|
{
|
|
|
|
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]),
|
|
|
|
'There should have been existing documents');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
|
|
|
{
|
|
|
|
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]),
|
|
|
|
'There should not have been any existing documents');
|
|
|
|
}
|
2024-06-21 13:46:41 +00:00
|
|
|
|
|
|
|
public function testByContainsFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Exists::byContains('', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[TestDox('By JSON Path fails')]
|
|
|
|
public function testByJsonPathFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Exists::byJsonPath('', '');
|
|
|
|
}
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
2024-06-21 13:46:41 +00:00
|
|
|
|