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-11 11:07:56 +00:00
|
|
|
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Document, DocumentException, Field, Find};
|
|
|
|
use BitBadger\PDODocument\Mapper\ArrayMapper;
|
2024-06-08 23:58:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2024-06-11 11:07:56 +00:00
|
|
|
use Test\Integration\{NumDocument, SubDocument, TestDocument};
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SQLite integration tests for the Document class
|
|
|
|
*/
|
|
|
|
#[TestDox('Document (SQLite integration)')]
|
|
|
|
class DocumentTest 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('insert() succeeds for array no auto ID')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayNoAutoId(): void
|
|
|
|
{
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
2024-06-25 02:04:11 +00:00
|
|
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($tryDoc->isSome, 'There should have been a document inserted');
|
|
|
|
$doc = $tryDoc->value;
|
2024-06-11 11:07:56 +00:00
|
|
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
|
|
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
|
|
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
|
|
|
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
|
|
|
$this->assertEquals('gobble', $doc->sub->foo, 'The sub-document foo property was incorrect');
|
|
|
|
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto number ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::Number;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'new', 'num_value' => 8]);
|
|
|
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$obj = json_decode($doc->value['data']);
|
2024-06-11 11:07:56 +00:00
|
|
|
$this->assertEquals(1, $obj->id, 'The ID 1 should have been auto-generated');
|
|
|
|
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => 0, 'value' => 'again', 'num_value' => 7]);
|
|
|
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = 2", [],
|
|
|
|
new ArrayMapper());
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$obj = json_decode($doc->value['data']);
|
2024-06-11 11:07:56 +00:00
|
|
|
$this->assertEquals(2, $obj->id, 'The ID 2 should have been auto-generated');
|
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto number ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::Number;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => 7, 'value' => 'new', 'num_value' => 8]);
|
|
|
|
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE, [], new ArrayMapper());
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$obj = json_decode($doc->value['data']);
|
2024-06-11 11:07:56 +00:00
|
|
|
$this->assertEquals(7, $obj->id, 'The ID 7 should have been stored');
|
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto UUID ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::UUID;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto UUID ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::UUID;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
$uuid = AutoId::generateUUID();
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto string ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::RandomString;
|
|
|
|
Configuration::$idStringLength = 6;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals(6, strlen($doc->value->id),
|
2024-06-25 02:04:11 +00:00
|
|
|
'The ID should have been auto-generated and had 6 characters');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
Configuration::$idStringLength = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for array with auto string ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::RandomString;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object no auto ID')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectNoAutoId(): void
|
2024-06-08 23:58:45 +00:00
|
|
|
{
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
2024-06-25 02:04:11 +00:00
|
|
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'turkey', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertNotFalse($tryDoc->isSome, 'There should have been a document inserted');
|
|
|
|
$doc = $tryDoc->value;
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('turkey', $doc->id, 'The ID was incorrect');
|
|
|
|
$this->assertEquals('', $doc->value, 'The value was incorrect');
|
|
|
|
$this->assertEquals(0, $doc->num_value, 'The numeric value was incorrect');
|
|
|
|
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
|
|
|
$this->assertEquals('gobble', $doc->sub->foo, 'The sub-document foo property was incorrect');
|
|
|
|
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto number ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::Number;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals(1, $doc->value->id, 'The ID 1 should have been auto-generated');
|
2024-06-11 11:07:56 +00:00
|
|
|
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals(2, $doc->value->id, 'The ID 2 should have been auto-generated');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto number ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::Number;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals(64, $doc->value->id, 'The ID 64 should have been stored');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto UUID ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::UUID;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertNotEmpty($doc->value->id, 'The ID should have been auto-generated');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto UUID ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::UUID;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
$uuid = AutoId::generateUUID();
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals($uuid, $doc->value->id, 'The ID should not have been changed');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto string ID not provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::RandomString;
|
|
|
|
Configuration::$idStringLength = 40;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals(40, strlen($doc->value->id),
|
2024-06-25 02:04:11 +00:00
|
|
|
'The ID should have been auto-generated and had 40 characters');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
Configuration::$idStringLength = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() succeeds for object with auto string ID with ID provided')]
|
2024-06-11 11:07:56 +00:00
|
|
|
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
|
|
|
|
{
|
|
|
|
Configuration::$autoId = AutoId::RandomString;
|
|
|
|
try {
|
|
|
|
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
2024-09-27 02:15:00 +00:00
|
|
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
|
|
|
$this->assertEquals('my-key', $doc->value->id, 'The ID should not have been changed');
|
2024-06-11 11:07:56 +00:00
|
|
|
} finally {
|
|
|
|
Configuration::$autoId = AutoId::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('insert() fails for duplicate key')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testInsertFailsForDuplicateKey(): void
|
|
|
|
{
|
|
|
|
$this->expectException(DocumentException::class);
|
|
|
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('save() succeeds when a document is inserted')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
|
|
|
{
|
|
|
|
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
|
|
|
$doc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('save() succeeds when a document is updated')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
|
|
|
{
|
|
|
|
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
2024-06-25 02:04:11 +00:00
|
|
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
|
|
|
$doc = $tryDoc->value;
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals(44, $doc->num_value, 'The numeric value was not updated');
|
|
|
|
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('update() succeeds when replacing a document')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testUpdateSucceedsWhenReplacingADocument(): void
|
|
|
|
{
|
|
|
|
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
2024-06-25 02:04:11 +00:00
|
|
|
$tryDoc = Find::byId(ThrowawayDb::TABLE, 'one', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($tryDoc->isSome, 'There should have been a document returned');
|
|
|
|
$doc = $tryDoc->value;
|
2024-06-08 23:58:45 +00:00
|
|
|
$this->assertEquals('howdy', $doc->value, 'The value was incorrect');
|
|
|
|
$this->assertEquals(8, $doc->num_value, 'The numeric value was incorrect');
|
|
|
|
$this->assertNotNull($doc->sub, 'The sub-document should not have been null');
|
|
|
|
$this->assertEquals('y', $doc->sub->foo, 'The sub-document foo property was incorrect');
|
|
|
|
$this->assertEquals('z', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
|
|
|
}
|
|
|
|
|
2024-09-27 02:15:00 +00:00
|
|
|
#[TestDox('update() succeeds when no document is replaced')]
|
2024-06-08 23:58:45 +00:00
|
|
|
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
|
|
|
|
{
|
|
|
|
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
|
|
|
$doc = Find::byId(ThrowawayDb::TABLE, 'two-hundred', TestDocument::class);
|
2024-10-02 01:37:08 +00:00
|
|
|
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|