Daniel J. Summers
65fd46835c
- 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
60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Test\Integration\PostgreSQL;
|
|
|
|
use BitBadger\PDODocument\{Count, Delete, Field};
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* PostgreSQL integration tests for the Delete class
|
|
*/
|
|
#[TestDox('Delete (PostgreSQL integration)')]
|
|
class DeleteTest 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 is deleted')]
|
|
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
|
{
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
|
Delete::byId(ThrowawayDb::TABLE, 'four');
|
|
$this->assertEquals(4, Count::all(ThrowawayDb::TABLE), 'There should have been 4 documents remaining');
|
|
}
|
|
|
|
#[TestDox('By ID succeeds when a document is not deleted')]
|
|
public function testByIdSucceedsWhenADocumentIsNotDeleted(): void
|
|
{
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
|
Delete::byId(ThrowawayDb::TABLE, 'negative four');
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
|
}
|
|
|
|
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
|
{
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
|
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]);
|
|
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
|
|
}
|
|
|
|
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
|
{
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
|
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]);
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
|
}
|
|
}
|