Use Option for single doc queries

This commit is contained in:
2024-06-24 22:04:11 -04:00
parent 124426fa12
commit 0c9490e394
14 changed files with 233 additions and 139 deletions

View File

@@ -87,15 +87,15 @@ class CustomTest extends TestCase
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
new DocumentMapper(TestDocument::class));
$this->assertNotNull($doc, 'There should have been a document returned');
$this->assertEquals('one', $doc->id, 'The incorrect document was returned');
$this->assertTrue($doc->isDefined(), 'There should have been a document returned');
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
}
public function testSingleSucceedsWhenARowIsNotFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
[':id' => 'eighty'], new DocumentMapper(TestDocument::class));
$this->assertFalse($doc, 'There should not have been a document returned');
$this->assertTrue($doc->isEmpty(), 'There should not have been a document returned');
}
public function testNonQuerySucceedsWhenOperatingOnData()