Daniel J. Summers
2d8f8b6e87
- Add sub-doc handling for SQLite fields - Add casting for PostgreSQL BT on numeric value - Add hasItems() to DocumentList - Fix SQL syntax problems exposed by tests
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Test\Integration\SQLite;
|
|
|
|
use BitBadger\PDODocument\{Count, Field, Find, Patch};
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Test\Integration\TestDocument;
|
|
|
|
/**
|
|
* SQLite integration tests for the Patch class
|
|
*/
|
|
#[TestDox('Patch (SQLite integration)')]
|
|
class PatchTest 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 updated')]
|
|
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
|
{
|
|
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
|
$this->assertNotFalse($doc, 'There should have been a document returned');
|
|
$this->assertEquals(44, $doc->num_value, 'The updated document is not correct');
|
|
}
|
|
|
|
#[TestDox('By ID succeeds when no document is updated')]
|
|
public function testByIdSucceedsWhenNoDocumentIsUpdated(): void
|
|
{
|
|
Patch::byId(ThrowawayDb::TABLE, 'forty-seven', ['foo' => 'green']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
|
|
|
|
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
|
{
|
|
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]);
|
|
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]);
|
|
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
|
}
|
|
|
|
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
|
{
|
|
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burgundy')], ['foo' => 'green']);
|
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
|
}
|
|
}
|