pdo-document/tests/integration/sqlite/ExistsTest.php

78 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\SQLite;
use BitBadger\PDODocument\{DocumentException, Exists, Field};
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();
}
2024-09-23 02:13:51 +00:00
#[TestDox('byId() succeeds when a document exists')]
public function testByIdSucceedsWhenADocumentExists(): void
{
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
}
2024-09-23 02:13:51 +00:00
#[TestDox('byId() 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');
}
2024-09-23 02:13:51 +00:00
#[TestDox('byFields() succeeds when documents exist')]
public function testByFieldsSucceedsWhenDocumentsExist(): void
{
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
'There should have been existing documents');
}
2024-09-23 02:13:51 +00:00
#[TestDox('byFields() succeeds when no matching documents exist')]
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
{
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
'There should not have been any existing documents');
}
2024-09-23 02:13:51 +00:00
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Exists::byContains('', []);
}
2024-09-23 02:13:51 +00:00
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);
Exists::byJsonPath('', '');
}
}