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, Delete, DocumentException, Field};
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SQLite integration tests for the Delete class
|
|
|
|
*/
|
|
|
|
#[TestDox('Delete (SQLite 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();
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byId() succeeds when a document is deleted')]
|
2024-06-08 23:58:45 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byId() succeeds when a document is not deleted')]
|
2024-06-08 23:58:45 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byFields() succeeds when documents are deleted')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
2024-09-27 02:15:00 +00:00
|
|
|
Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byFields() succeeds when documents are not deleted')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
2024-09-27 02:15:00 +00:00
|
|
|
Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
|
|
|
}
|
2024-06-21 13:46:41 +00:00
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byContains() fails')]
|
2024-06-21 13:46:41 +00:00
|
|
|
public function testByContainsFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Delete::byContains('', []);
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('byJsonPath() fails')]
|
2024-06-21 13:46:41 +00:00
|
|
|
public function testByJsonPathFails(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Delete::byJsonPath('', '');
|
|
|
|
}
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|