pdo-document/tests/integration/postgresql/ExistsTest.php
Daniel J. Summers 65fd46835c Add PostgreSQL version of SQLite integ tests
- Add PostgreSQL throwaway database
- Add optional length parameter for random string
- Fix syntax for PostgreSQL in several areas
- Add optional ID for whereById type determination
2024-06-12 15:21:53 -04:00

55 lines
1.6 KiB
PHP

<?php declare(strict_types=1);
namespace Test\Integration\PostgreSQL;
use BitBadger\PDODocument\{Exists, Field};
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
/**
* PostgreSQL integration tests for the Exists class
*/
#[TestDox('Exists (PostgreSQL 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');
}
}