Changes for beta10 #5

Merged
danieljsummers merged 7 commits from beta10 into main 2024-09-27 02:15:01 +00:00
20 changed files with 192 additions and 75 deletions
Showing only changes of commit 9a2cf4c204 - Show all commits

View File

@ -33,44 +33,49 @@ class CountTest extends TestCase
parent::tearDown();
}
#[TestDox('all() succeeds')]
public function testAllSucceeds(): void
{
$count = Count::all(ThrowawayDb::TABLE);
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
}
#[TestDox('byFields() succeeds for a numeric range')]
public function testByFieldsSucceedsForANumericRange(): void
{
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
}
#[TestDox('byFields() succeeds for a non-numeric range')]
public function testByFieldsSucceedsForANonNumericRange(): void
{
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
$this->assertEquals(1, $count, 'There should have been 1 matching document');
}
#[TestDox('byContains() succeeds when documents match')]
public function testByContainsSucceedsWhenDocumentsMatch(): void
{
$this->assertEquals(2, Count::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
'There should have been 2 matching documents');
}
#[TestDox('byContains() succeeds when no documents match')]
public function testByContainsSucceedsWhenNoDocumentsMatch(): void
{
$this->assertEquals(0, Count::byContains(ThrowawayDb::TABLE, ['value' => 'magenta']),
'There should have been no matching documents');
}
#[TestDox('By JSON Path succeeds when documents match')]
#[TestDox('byJsonPath() succeeds when documents match')]
public function testByJsonPathSucceedsWhenDocumentsMatch(): void
{
$this->assertEquals(2, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ < 5)'),
'There should have been 2 matching documents');
}
#[TestDox('By JSON Path succeeds when no documents match')]
#[TestDox('byJsonPath() succeeds when no documents match')]
public function testByJsonPathSucceedsWhenNoDocumentsMatch(): void
{
$this->assertEquals(0, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)'),

View File

@ -34,6 +34,7 @@ class CustomTest extends TestCase
ThrowawayDb::destroy($this->dbName);
}
#[TestDox('runQuery() succeeds with a valid query')]
public function testRunQuerySucceedsWithAValidQuery(): void
{
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
@ -44,6 +45,7 @@ class CustomTest extends TestCase
}
}
#[TestDox('runQuery() fails with an invalid query')]
public function testRunQueryFailsWithAnInvalidQuery(): void
{
$this->expectException(DocumentException::class);
@ -55,6 +57,7 @@ class CustomTest extends TestCase
}
}
#[TestDox('list() succeeds when data is found')]
public function testListSucceedsWhenDataIsFound(): void
{
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
@ -64,6 +67,7 @@ class CustomTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
}
#[TestDox('list() succeeds when no data is found')]
public function testListSucceedsWhenNoDataIsFound(): void
{
$list = Custom::list(
@ -73,6 +77,7 @@ class CustomTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('array() succeeds when data is found')]
public function testArraySucceedsWhenDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
@ -81,6 +86,7 @@ class CustomTest extends TestCase
$this->assertCount(2, $array, 'There should have been 2 documents in the array');
}
#[TestDox('array() succeeds when no data is found')]
public function testArraySucceedsWhenNoDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
@ -89,6 +95,7 @@ class CustomTest extends TestCase
$this->assertCount(0, $array, 'There should have been no documents in the array');
}
#[TestDox('single() succeeds when a row is found')]
public function testSingleSucceedsWhenARowIsFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
@ -97,6 +104,7 @@ class CustomTest extends TestCase
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('single() succeeds when a row is not found')]
public function testSingleSucceedsWhenARowIsNotFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
@ -104,6 +112,7 @@ class CustomTest extends TestCase
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('nonQuery() succeeds when operating on data')]
public function testNonQuerySucceedsWhenOperatingOnData(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
@ -111,6 +120,7 @@ class CustomTest extends TestCase
$this->assertEquals(0, $remaining, 'There should be no documents remaining in the table');
}
#[TestDox('nonQuery() succeeds when no data matches WHERE clause')]
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE (data->>'num_value')::numeric > :value",
@ -119,6 +129,7 @@ class CustomTest extends TestCase
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
}
#[TestDox('scalar() succeeds')]
public function testScalarSucceeds(): void
{
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());

View File

@ -47,6 +47,7 @@ class DefinitionTest extends TestCase
[':name' => $name], new ExistsMapper());
}
#[TestDox('ensureTable() succeeds')]
public function testEnsureTableSucceeds(): void
{
$this->assertFalse($this->itExists('ensured'), 'The table should not exist already');
@ -56,6 +57,7 @@ class DefinitionTest extends TestCase
$this->assertTrue($this->itExists('idx_ensured_key'), 'The key index should now exist');
}
#[TestDox('ensureFieldIndex() succeeds')]
public function testEnsureFieldIndexSucceeds(): void
{
$this->assertFalse($this->itExists('idx_ensured_test'), 'The index should not exist already');
@ -64,6 +66,7 @@ class DefinitionTest extends TestCase
$this->assertTrue($this->itExists('idx_ensured_test'), 'The index should now exist');
}
#[TestDox('ensureDocumentIndex() succeeds for Full')]
public function testEnsureDocumentIndexSucceedsForFull(): void
{
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';
@ -73,6 +76,7 @@ class DefinitionTest extends TestCase
$this->assertTrue($this->itExists($docIdx), 'The document index should now exist');
}
#[TestDox('ensureDocumentIndex() succeeds for Optimized')]
public function testEnsureDocumentIndexSucceedsForOptimized(): void
{
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';

View File

@ -33,7 +33,7 @@ class DeleteTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document is deleted')]
#[TestDox('byId() 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');
@ -41,7 +41,7 @@ class DeleteTest extends TestCase
$this->assertEquals(4, Count::all(ThrowawayDb::TABLE), 'There should have been 4 documents remaining');
}
#[TestDox('By ID succeeds when a document is not deleted')]
#[TestDox('byId() 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');
@ -49,6 +49,7 @@ class DeleteTest extends TestCase
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
}
#[TestDox('byFields() succeeds when documents are deleted')]
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -56,6 +57,7 @@ class DeleteTest extends TestCase
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
}
#[TestDox('byFields() succeeds when documents are not deleted')]
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -63,6 +65,7 @@ class DeleteTest extends TestCase
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
}
#[TestDox('byContains() succeeds when documents are deleted')]
public function testByContainsSucceedsWhenDocumentsAreDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -70,6 +73,7 @@ class DeleteTest extends TestCase
$this->assertEquals(3, Count::all(ThrowawayDb::TABLE), 'There should have been 3 documents remaining');
}
#[TestDox('byContains() succeeds when documents are not deleted')]
public function testByContainsSucceedsWhenDocumentsAreNotDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -77,7 +81,7 @@ class DeleteTest extends TestCase
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
}
#[TestDox('By JSON Path succeeds when documents are deleted')]
#[TestDox('byJsonPath() succeeds when documents are deleted')]
public function testByJsonPathSucceedsWhenDocumentsAreDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -85,7 +89,7 @@ class DeleteTest extends TestCase
$this->assertEquals(1, Count::all(ThrowawayDb::TABLE), 'There should have been 1 document remaining');
}
#[TestDox('By JSON Path succeeds when documents are not deleted')]
#[TestDox('byJsonPath() succeeds when documents are not deleted')]
public function testByJsonPathSucceedsWhenDocumentsAreNotDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');

View File

@ -35,6 +35,7 @@ class DocumentListTest extends TestCase
parent::tearDown();
}
#[TestDox('create() succeeds')]
public function testCreateSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -43,6 +44,7 @@ class DocumentListTest extends TestCase
$list = null;
}
#[TestDox('items() succeeds')]
public function testItemsSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -57,6 +59,7 @@ class DocumentListTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
}
#[TestDox('items() fails when already consumed')]
public function testItemsFailsWhenAlreadyConsumed(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -69,6 +72,7 @@ class DocumentListTest extends TestCase
iterator_to_array($list->items());
}
#[TestDox('hasItems() succeeds with empty results')]
public function testHasItemsSucceedsWithEmptyResults(): void
{
$list = DocumentList::create(
@ -78,6 +82,7 @@ class DocumentListTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
}
#[TestDox('hasItems() succeeds with non-empty results')]
public function testHasItemsSucceedsWithNonEmptyResults(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -90,6 +95,7 @@ class DocumentListTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
}
#[TestDox('map() succeeds')]
public function testMapSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -102,6 +108,7 @@ class DocumentListTest extends TestCase
}
}
#[TestDox('iter() succeeds')]
public function testIterSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -114,6 +121,7 @@ class DocumentListTest extends TestCase
'Iteration did not have the expected result');
}
#[TestDox('mapToArray() succeeds')]
public function testMapToArraySucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],

View File

@ -35,7 +35,7 @@ class DocumentTest extends TestCase
parent::tearDown();
}
#[TestDox('Insert succeeds for array no auto ID')]
#[TestDox('insert() succeeds for array no auto ID')]
public function testInsertSucceedsForArrayNoAutoId(): void
{
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
@ -50,7 +50,7 @@ class DocumentTest extends TestCase
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('Insert succeeds for array with auto number ID not provided')]
#[TestDox('insert() succeeds for array with auto number ID not provided')]
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -74,7 +74,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto number ID with ID provided')]
#[TestDox('insert() succeeds for array with auto number ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -90,7 +90,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto UUID ID not provided')]
#[TestDox('insert() succeeds for array with auto UUID ID not provided')]
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -105,7 +105,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto UUID ID with ID provided')]
#[TestDox('insert() succeeds for array with auto UUID ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -121,7 +121,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto string ID not provided')]
#[TestDox('insert() succeeds for array with auto string ID not provided')]
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -139,7 +139,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto string ID with ID provided')]
#[TestDox('insert() succeeds for array with auto string ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -154,7 +154,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object no auto ID')]
#[TestDox('insert() succeeds for object no auto ID')]
public function testInsertSucceedsForObjectNoAutoId(): void
{
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
@ -169,7 +169,7 @@ class DocumentTest extends TestCase
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('Insert succeeds for object with auto number ID not provided')]
#[TestDox('insert() succeeds for object with auto number ID not provided')]
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -190,7 +190,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto number ID with ID provided')]
#[TestDox('insert() succeeds for object with auto number ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -205,7 +205,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto UUID ID not provided')]
#[TestDox('insert() succeeds for object with auto UUID ID not provided')]
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -220,7 +220,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto UUID ID with ID provided')]
#[TestDox('insert() succeeds for object with auto UUID ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -236,7 +236,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto string ID not provided')]
#[TestDox('insert() succeeds for object with auto string ID not provided')]
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -254,7 +254,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto string ID with ID provided')]
#[TestDox('insert() succeeds for object with auto string ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -269,12 +269,14 @@ class DocumentTest extends TestCase
}
}
#[TestDox('insert() fails for duplicate key')]
public function testInsertFailsForDuplicateKey(): void
{
$this->expectException(DocumentException::class);
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
}
#[TestDox('save() succeeds when a document is inserted')]
public function testSaveSucceedsWhenADocumentIsInserted(): void
{
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
@ -282,6 +284,7 @@ class DocumentTest extends TestCase
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
}
#[TestDox('save() succeeds when a document is updated')]
public function testSaveSucceedsWhenADocumentIsUpdated(): void
{
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
@ -292,6 +295,7 @@ class DocumentTest extends TestCase
$this->assertNull($doc->sub, 'The sub-document should have been null');
}
#[TestDox('update() succeeds when replacing a document')]
public function testUpdateSucceedsWhenReplacingADocument(): void
{
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
@ -305,6 +309,7 @@ class DocumentTest extends TestCase
$this->assertEquals('z', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('update() succeeds when no document is replaced')]
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
{
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));

View File

@ -33,51 +33,55 @@ class ExistsTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document exists')]
#[TestDox('byId() succeeds when a document exists')]
public function testByIdSucceedsWhenADocumentExists(): void
{
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
}
#[TestDox('By ID succeeds when a document does not exist')]
#[TestDox('byId() succeeds when a document does not exist')]
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
{
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
'There should not have been an existing document');
}
#[TestDox('byFields() succeeds when documents exist')]
public function testByFieldsSucceedsWhenDocumentsExist(): void
{
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
'There should have been existing documents');
}
#[TestDox('byFields() succeeds when no matching documents exist')]
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
{
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
'There should not have been any existing documents');
}
#[TestDox('byContains() succeeds when documents exist')]
public function testByContainsSucceedsWhenDocumentsExist(): void
{
$this->assertTrue(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
'There should have been existing documents');
}
#[TestDox('byContains() succeeds when no matching documents exist')]
public function testByContainsSucceedsWhenNoMatchingDocumentsExist(): void
{
$this->assertFalse(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'violet']),
'There should not have been existing documents');
}
#[TestDox('By JSON Path succeeds when documents exist')]
#[TestDox('byJsonPath() succeeds when documents exist')]
public function testByJsonPathSucceedsWhenDocumentsExist(): void
{
$this->assertTrue(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)'),
'There should have been existing documents');
}
#[TestDox('By JSON Path succeeds when no matching documents exist')]
#[TestDox('byJsonPath() succeeds when no matching documents exist')]
public function testByJsonPathSucceedsWhenNoMatchingDocumentsExist(): void
{
$this->assertFalse(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10.1)'),

View File

@ -34,6 +34,7 @@ class FindTest extends TestCase
parent::tearDown();
}
#[TestDox('all() succeeds when there is data')]
public function testAllSucceedsWhenThereIsData(): void
{
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
@ -43,6 +44,7 @@ class FindTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
}
#[TestDox('all() succeeds when there is no data')]
public function testAllSucceedsWhenThereIsNoData(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
@ -51,7 +53,7 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('By ID succeeds when a document is found')]
#[TestDox('byId() succeeds when a document is found')]
public function testByIdSucceedsWhenADocumentIsFound(): void
{
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
@ -59,7 +61,7 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
}
#[TestDox('By ID succeeds when a document is found with numeric ID')]
#[TestDox('byId() succeeds when a document is found with numeric ID')]
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
{
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absent')]);
@ -69,13 +71,14 @@ class FindTest extends TestCase
$this->assertEquals(18, $doc->get()->id, 'An incorrect document was returned');
}
#[TestDox('By ID succeeds when a document is not found')]
#[TestDox('byId() succeeds when a document is not found')]
public function testByIdSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('byFields() succeeds when documents are found')]
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
{
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
@ -85,6 +88,7 @@ class FindTest extends TestCase
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
}
#[TestDox('byFields() succeeds when no documents are found')]
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
{
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
@ -92,6 +96,7 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('byContains() succeeds when documents are found')]
public function testByContainsSucceedsWhenDocumentsAreFound(): void
{
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
@ -101,6 +106,7 @@ class FindTest extends TestCase
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
}
#[TestDox('byContains() succeeds when no documents are found')]
public function testByContainsSucceedsWhenNoDocumentsAreFound(): void
{
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
@ -108,7 +114,7 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'The document list should be empty');
}
#[TestDox('By JSON Path succeeds when documents are found')]
#[TestDox('byJsonPath() succeeds when documents are found')]
public function testByJsonPathSucceedsWhenDocumentsAreFound(): void
{
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
@ -118,7 +124,7 @@ class FindTest extends TestCase
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
}
#[TestDox('By JSON Path succeeds when no documents are found')]
#[TestDox('byJsonPath() succeeds when no documents are found')]
public function testByJsonPathSucceedsWhenNoDocumentsAreFound(): void
{
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
@ -126,6 +132,7 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'The document list should be empty');
}
#[TestDox('firstByFields() succeeds when a document is found')]
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
@ -133,6 +140,7 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('firstByFields() succeeds when multiple documents are found')]
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
@ -140,12 +148,14 @@ class FindTest extends TestCase
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
}
#[TestDox('firstByFields() succeeds when a document is not found')]
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('firstByContains() succeeds when a document is found')]
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
{
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class);
@ -153,6 +163,7 @@ class FindTest extends TestCase
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('firstByContains() succeeds when multiple documents are found')]
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
{
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
@ -160,13 +171,14 @@ class FindTest extends TestCase
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
}
#[TestDox('firstByContains() succeeds when a document is not found')]
public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('First by JSON Path succeeds when a document is found')]
#[TestDox('firstByJsonPath() succeeds when a document is found')]
public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void
{
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class);
@ -174,7 +186,7 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('First by JSON Path succeeds when multiple documents are found')]
#[TestDox('firstByJsonPath() succeeds when multiple documents are found')]
public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void
{
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
@ -182,7 +194,7 @@ class FindTest extends TestCase
$this->assertContains($doc->get()->id, ['four', 'five'], 'An incorrect document was returned');
}
#[TestDox('First by JSON Path succeeds when a document is not found')]
#[TestDox('firstByJsonPath() succeeds when a document is not found')]
public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);

View File

@ -34,7 +34,7 @@ class PatchTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document is updated')]
#[TestDox('byId() succeeds when a document is updated')]
public function testByIdSucceedsWhenADocumentIsUpdated(): void
{
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
@ -43,7 +43,7 @@ class PatchTest extends TestCase
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
}
#[TestDox('By ID succeeds when no document is updated')]
#[TestDox('byId() succeeds when no document is updated')]
public function testByIdSucceedsWhenNoDocumentIsUpdated(): void
{
$id = 'forty-seven';
@ -52,6 +52,7 @@ class PatchTest extends TestCase
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byFields() succeeds when a document is updated')]
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
{
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
@ -59,6 +60,7 @@ class PatchTest extends TestCase
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
}
#[TestDox('byFields() succeeds when no document is updated')]
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
{
$fields = [Field::equal('value', 'burgundy')];
@ -67,6 +69,7 @@ class PatchTest extends TestCase
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byContains() succeeds when documents are updated')]
public function testByContainsSucceedsWhenDocumentsAreUpdated(): void
{
Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]);
@ -77,6 +80,7 @@ class PatchTest extends TestCase
$this->assertEquals(12, $doc->num_value, 'The document was not patched');
}
#[TestDox('byContains() succeeds when no documents are updated')]
public function testByContainsSucceedsWhenNoDocumentsAreUpdated(): void
{
$criteria = ['value' => 'updated'];
@ -86,7 +90,7 @@ class PatchTest extends TestCase
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('By JSON Path succeeds when documents are updated')]
#[TestDox('byJsonPath() succeeds when documents are updated')]
public function testByJsonPathSucceedsWhenDocumentsAreUpdated(): void
{
Patch::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', ['value' => 'blue']);
@ -99,7 +103,7 @@ class PatchTest extends TestCase
}
}
#[TestDox('By JSON Path succeeds when documents are not updated')]
#[TestDox('byJsonPath() succeeds when documents are not updated')]
public function testByJsonPathSucceedsWhenDocumentsAreNotUpdated(): void
{
$path = '$.num_value ? (@ > 100)';

View File

@ -34,7 +34,7 @@ class RemoveFieldsTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when fields are removed')]
#[TestDox('byId() succeeds when fields are removed')]
public function testByIdSucceedsWhenFieldsAreRemoved(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
@ -45,20 +45,21 @@ class RemoveFieldsTest extends TestCase
$this->assertNull($doc->sub, 'Sub-document should have been null');
}
#[TestDox('By ID succeeds when a field is not removed')]
#[TestDox('byId() succeeds when a field is not removed')]
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('By ID succeeds when no document is matched')]
#[TestDox('byId() succeeds when no document is matched')]
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byFields() succeeds when a field is removed')]
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
@ -67,18 +68,21 @@ class RemoveFieldsTest extends TestCase
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
}
#[TestDox('byFields() succeeds when a field is not removed')]
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byFields() succeeds when no document is matched')]
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byContains() succeeds when a field is removed')]
public function testByContainsSucceedsWhenAFieldIsRemoved(): void
{
$criteria = ['sub' => ['foo' => 'green']];
@ -92,19 +96,21 @@ class RemoveFieldsTest extends TestCase
}
}
#[TestDox('byContains() succeeds when a field is not removed')]
public function testByContainsSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byContains(ThrowawayDb::TABLE, ['sub' => ['foo' => 'green']], ['invalid_field']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byContains() succeeds when no document is matched')]
public function testByContainsSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byContains(ThrowawayDb::TABLE, ['value' => 'substantial'], ['num_value']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('By JSON Path succeeds when a field is removed')]
#[TestDox('byJsonPath() succeeds when a field is removed')]
public function testByJsonPathSucceedsWhenAFieldIsRemoved(): void
{
$path = '$.value ? (@ == "purple")';
@ -118,14 +124,14 @@ class RemoveFieldsTest extends TestCase
}
}
#[TestDox('By JSON Path succeeds when a field is not removed')]
#[TestDox('byJsonPath() succeeds when a field is not removed')]
public function testByJsonPathSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "purple")', ['submarine']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('By JSON Path succeeds when no document is matched')]
#[TestDox('byJsonPath() succeeds when no document is matched')]
public function testByJsonPathSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "mauve")', ['value']);

View File

@ -33,31 +33,35 @@ class CountTest extends TestCase
parent::tearDown();
}
#[TestDox('all() succeeds')]
public function testAllSucceeds(): void
{
$count = Count::all(ThrowawayDb::TABLE);
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
}
#[TestDox('byFields() succeeds for a numeric range')]
public function testByFieldsSucceedsForANumericRange(): void
{
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
}
#[TestDox('byFields() succeeds for a non-numeric range')]
public function testByFieldsSucceedsForANonNumericRange(): void
{
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
$this->assertEquals(1, $count, 'There should have been 1 matching document');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Count::byContains('', []);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -34,6 +34,7 @@ class CustomTest extends TestCase
ThrowawayDb::destroy($this->dbName);
}
#[TestDox('runQuery() succeeds with a valid query')]
public function testRunQuerySucceedsWithAValidQuery(): void
{
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
@ -44,6 +45,7 @@ class CustomTest extends TestCase
}
}
#[TestDox('runQuery() fails with an invalid query')]
public function testRunQueryFailsWithAnInvalidQuery(): void
{
$this->expectException(DocumentException::class);
@ -55,6 +57,7 @@ class CustomTest extends TestCase
}
}
#[TestDox('list() succeeds when data is found')]
public function testListSucceedsWhenDataIsFound(): void
{
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
@ -64,6 +67,7 @@ class CustomTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
}
#[TestDox('list() succeeds when no data is found')]
public function testListSucceedsWhenNoDataIsFound(): void
{
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' > :value",
@ -72,6 +76,7 @@ class CustomTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('array() succeeds when data is found')]
public function testArraySucceedsWhenDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
@ -80,6 +85,7 @@ class CustomTest extends TestCase
$this->assertCount(2, $array, 'There should have been 2 documents in the array');
}
#[TestDox('array() succeeds when no data is found')]
public function testArraySucceedsWhenNoDataIsFound(): void
{
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
@ -88,6 +94,7 @@ class CustomTest extends TestCase
$this->assertCount(0, $array, 'There should have been no documents in the array');
}
#[TestDox('single() succeeds when a row is found')]
public function testSingleSucceedsWhenARowIsFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
@ -96,6 +103,7 @@ class CustomTest extends TestCase
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('single() succeeds when a row is not found')]
public function testSingleSucceedsWhenARowIsNotFound(): void
{
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
@ -103,6 +111,7 @@ class CustomTest extends TestCase
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('nonQuery() succeeds when operating on data')]
public function testNonQuerySucceedsWhenOperatingOnData(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
@ -110,6 +119,7 @@ class CustomTest extends TestCase
$this->assertEquals(0, $remaining, 'There should be no documents remaining in the table');
}
#[TestDox('nonQuery() succeeds when no data matches WHERE clause')]
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE data->>'num_value' > :value", [':value' => 100]);
@ -117,6 +127,7 @@ class CustomTest extends TestCase
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
}
#[TestDox('scalar() succeeds')]
public function testScalarSucceeds(): void
{
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());

View File

@ -47,6 +47,7 @@ class DefinitionTest extends TestCase
[':name' => $name], new ExistsMapper());
}
#[TestDox('ensureTable() succeeds')]
public function testEnsureTableSucceeds(): void
{
$this->assertFalse($this->itExists('ensured'), 'The table should not exist already');
@ -56,6 +57,7 @@ class DefinitionTest extends TestCase
$this->assertTrue($this->itExists('idx_ensured_key'), 'The key index should now exist');
}
#[TestDox('ensureFieldIndex() succeeds')]
public function testEnsureFieldIndexSucceeds(): void
{
$this->assertFalse($this->itExists('idx_ensured_test'), 'The index should not exist already');
@ -64,6 +66,7 @@ class DefinitionTest extends TestCase
$this->assertTrue($this->itExists('idx_ensured_test'), 'The index should now exist');
}
#[TestDox('ensureDocumentIndex() fails')]
public function testEnsureDocumentIndexFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -33,7 +33,7 @@ class DeleteTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document is deleted')]
#[TestDox('byId() 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');
@ -41,7 +41,7 @@ class DeleteTest extends TestCase
$this->assertEquals(4, Count::all(ThrowawayDb::TABLE), 'There should have been 4 documents remaining');
}
#[TestDox('By ID succeeds when a document is not deleted')]
#[TestDox('byId() 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');
@ -49,6 +49,7 @@ class DeleteTest extends TestCase
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
}
#[TestDox('byFields() succeeds when documents are deleted')]
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -56,6 +57,7 @@ class DeleteTest extends TestCase
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
}
#[TestDox('byFields() succeeds when documents are not deleted')]
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
{
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
@ -63,13 +65,14 @@ class DeleteTest extends TestCase
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Delete::byContains('', []);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -35,6 +35,7 @@ class DocumentListTest extends TestCase
parent::tearDown();
}
#[TestDox('create() succeeds')]
public function testCreateSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -43,6 +44,7 @@ class DocumentListTest extends TestCase
$list = null;
}
#[TestDox('items() succeeds')]
public function testItemsSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -57,6 +59,7 @@ class DocumentListTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
}
#[TestDox('items() fails when already consumed')]
public function testItemsFailsWhenAlreadyConsumed(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -69,6 +72,7 @@ class DocumentListTest extends TestCase
iterator_to_array($list->items());
}
#[TestDox('hasItems() succeeds with empty results')]
public function testHasItemsSucceedsWithEmptyResults(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' < 0", [],
@ -77,6 +81,7 @@ class DocumentListTest extends TestCase
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
}
#[TestDox('hasItems() succeeds with non-empty results')]
public function testHasItemsSucceedsWithNonEmptyResults(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -88,6 +93,8 @@ class DocumentListTest extends TestCase
}
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
}
#[TestDox('map() succeeds')]
public function testMapSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -100,6 +107,7 @@ class DocumentListTest extends TestCase
}
}
#[TestDox('iter() succeeds')]
public function testIterSucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
@ -112,6 +120,7 @@ class DocumentListTest extends TestCase
'Iteration did not have the expected result');
}
#[TestDox('mapToArray() succeeds')]
public function testMapToArraySucceeds(): void
{
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],

View File

@ -35,7 +35,7 @@ class DocumentTest extends TestCase
parent::tearDown();
}
#[TestDox('Insert succeeds for array no auto ID')]
#[TestDox('insert() succeeds for array no auto ID')]
public function testInsertSucceedsForArrayNoAutoId(): void
{
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
@ -50,7 +50,7 @@ class DocumentTest extends TestCase
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('Insert succeeds for array with auto number ID not provided')]
#[TestDox('insert() succeeds for array with auto number ID not provided')]
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -74,7 +74,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto number ID with ID provided')]
#[TestDox('insert() succeeds for array with auto number ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -90,7 +90,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto UUID ID not provided')]
#[TestDox('insert() succeeds for array with auto UUID ID not provided')]
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -105,7 +105,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto UUID ID with ID provided')]
#[TestDox('insert() succeeds for array with auto UUID ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -121,7 +121,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto string ID not provided')]
#[TestDox('insert() succeeds for array with auto string ID not provided')]
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -139,7 +139,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for array with auto string ID with ID provided')]
#[TestDox('insert() succeeds for array with auto string ID with ID provided')]
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -154,7 +154,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object no auto ID')]
#[TestDox('insert() succeeds for object no auto ID')]
public function testInsertSucceedsForObjectNoAutoId(): void
{
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
@ -169,7 +169,7 @@ class DocumentTest extends TestCase
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('Insert succeeds for object with auto number ID not provided')]
#[TestDox('insert() succeeds for object with auto number ID not provided')]
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -190,7 +190,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto number ID with ID provided')]
#[TestDox('insert() succeeds for object with auto number ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::Number;
@ -205,7 +205,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto UUID ID not provided')]
#[TestDox('insert() succeeds for object with auto UUID ID not provided')]
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -220,7 +220,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto UUID ID with ID provided')]
#[TestDox('insert() succeeds for object with auto UUID ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::UUID;
@ -236,7 +236,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto string ID not provided')]
#[TestDox('insert() succeeds for object with auto string ID not provided')]
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -254,7 +254,7 @@ class DocumentTest extends TestCase
}
}
#[TestDox('Insert succeeds for object with auto string ID with ID provided')]
#[TestDox('insert() succeeds for object with auto string ID with ID provided')]
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
{
Configuration::$autoId = AutoId::RandomString;
@ -269,12 +269,14 @@ class DocumentTest extends TestCase
}
}
#[TestDox('insert() fails for duplicate key')]
public function testInsertFailsForDuplicateKey(): void
{
$this->expectException(DocumentException::class);
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
}
#[TestDox('save() succeeds when a document is inserted')]
public function testSaveSucceedsWhenADocumentIsInserted(): void
{
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
@ -282,6 +284,7 @@ class DocumentTest extends TestCase
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
}
#[TestDox('save() succeeds when a document is updated')]
public function testSaveSucceedsWhenADocumentIsUpdated(): void
{
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
@ -292,6 +295,7 @@ class DocumentTest extends TestCase
$this->assertNull($doc->sub, 'The sub-document should have been null');
}
#[TestDox('update() succeeds when replacing a document')]
public function testUpdateSucceedsWhenReplacingADocument(): void
{
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
@ -305,6 +309,7 @@ class DocumentTest extends TestCase
$this->assertEquals('z', $doc->sub->bar, 'The sub-document bar property was incorrect');
}
#[TestDox('update() succeeds when no document is replaced')]
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
{
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));

View File

@ -33,38 +33,41 @@ class ExistsTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document exists')]
#[TestDox('byId() succeeds when a document exists')]
public function testByIdSucceedsWhenADocumentExists(): void
{
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
}
#[TestDox('By ID succeeds when a document does not exist')]
#[TestDox('byId() succeeds when a document does not exist')]
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
{
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
'There should not have been an existing document');
}
#[TestDox('byFields() succeeds when documents exist')]
public function testByFieldsSucceedsWhenDocumentsExist(): void
{
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
'There should have been existing documents');
}
#[TestDox('byFields() succeeds when no matching documents exist')]
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
{
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
'There should not have been any existing documents');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Exists::byContains('', []);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -34,6 +34,7 @@ class FindTest extends TestCase
parent::tearDown();
}
#[TestDox('all() succeeds when there is data')]
public function testAllSucceedsWhenThereIsData(): void
{
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
@ -43,6 +44,7 @@ class FindTest extends TestCase
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
}
#[TestDox('all() succeeds when there is no data')]
public function testAllSucceedsWhenThereIsNoData(): void
{
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
@ -51,7 +53,7 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('By ID succeeds when a document is found')]
#[TestDox('byId() succeeds when a document is found')]
public function testByIdSucceedsWhenADocumentIsFound(): void
{
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
@ -59,7 +61,7 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
}
#[TestDox('By ID succeeds when a document is found with numeric ID')]
#[TestDox('byId() succeeds when a document is found with numeric ID')]
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
{
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
@ -68,13 +70,14 @@ class FindTest extends TestCase
$this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned');
}
#[TestDox('By ID succeeds when a document is not found')]
#[TestDox('byId() succeeds when a document is not found')]
public function testByIdSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('byFields() succeeds when documents are found')]
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
{
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
@ -84,6 +87,7 @@ class FindTest extends TestCase
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
}
#[TestDox('byFields() succeeds when no documents are found')]
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
{
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
@ -91,19 +95,21 @@ class FindTest extends TestCase
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Find::byContains('', [], TestDocument::class);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);
Find::byJsonPath('', '', TestDocument::class);
}
#[TestDox('firstByFields() succeeds when a document is found')]
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
@ -111,6 +117,7 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
}
#[TestDox('firstByFields() succeeds when multiple documents are found')]
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
@ -118,19 +125,21 @@ class FindTest extends TestCase
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
}
#[TestDox('firstByFields() succeeds when a document is not found')]
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
{
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
}
#[TestDox('firstByContains() fails')]
public function testFirstByContainsFails(): void
{
$this->expectException(DocumentException::class);
Find::firstByContains('', [], TestDocument::class);
}
#[TestDox('First by JSON Path fails')]
#[TestDox('firstByJsonPath() fails')]
public function testFirstByJsonPathFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -34,7 +34,7 @@ class PatchTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when a document is updated')]
#[TestDox('byId() succeeds when a document is updated')]
public function testByIdSucceedsWhenADocumentIsUpdated(): void
{
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
@ -43,13 +43,14 @@ class PatchTest extends TestCase
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
}
#[TestDox('By ID succeeds when no document is updated')]
#[TestDox('byId() 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');
}
#[TestDox('byFields() succeeds when a document is updated')]
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
{
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
@ -57,19 +58,21 @@ class PatchTest extends TestCase
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
}
#[TestDox('byFields() succeeds when no document is updated')]
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
{
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'burgundy')], ['foo' => 'green']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
Patch::byContains('', [], []);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);

View File

@ -34,7 +34,7 @@ class RemoveFieldsTest extends TestCase
parent::tearDown();
}
#[TestDox('By ID succeeds when fields are removed')]
#[TestDox('byId() succeeds when fields are removed')]
public function testByIdSucceedsWhenFieldsAreRemoved(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
@ -45,20 +45,21 @@ class RemoveFieldsTest extends TestCase
$this->assertNull($doc->sub, 'Sub-document should have been null');
}
#[TestDox('By ID succeeds when a field is not removed')]
#[TestDox('byId() succeeds when a field is not removed')]
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('By ID succeeds when no document is matched')]
#[TestDox('byId() succeeds when no document is matched')]
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byFields() succeeds when a field is removed')]
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
@ -67,25 +68,28 @@ class RemoveFieldsTest extends TestCase
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
}
#[TestDox('byFields() succeeds when a field is not removed')]
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byFields() succeeds when no document is matched')]
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
{
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
$this->assertTrue(true, 'The above not throwing an exception is the test');
}
#[TestDox('byContains() fails')]
public function testByContainsFails(): void
{
$this->expectException(DocumentException::class);
RemoveFields::byContains('', [], []);
}
#[TestDox('By JSON Path fails')]
#[TestDox('byJsonPath() fails')]
public function testByJsonPathFails(): void
{
$this->expectException(DocumentException::class);