Changes for beta10 #5
|
@ -33,44 +33,49 @@ class CountTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('all() succeeds')]
|
||||||
public function testAllSucceeds(): void
|
public function testAllSucceeds(): void
|
||||||
{
|
{
|
||||||
$count = Count::all(ThrowawayDb::TABLE);
|
$count = Count::all(ThrowawayDb::TABLE);
|
||||||
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds for a numeric range')]
|
||||||
public function testByFieldsSucceedsForANumericRange(): void
|
public function testByFieldsSucceedsForANumericRange(): void
|
||||||
{
|
{
|
||||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
||||||
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds for a non-numeric range')]
|
||||||
public function testByFieldsSucceedsForANonNumericRange(): void
|
public function testByFieldsSucceedsForANonNumericRange(): void
|
||||||
{
|
{
|
||||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
||||||
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when documents match')]
|
||||||
public function testByContainsSucceedsWhenDocumentsMatch(): void
|
public function testByContainsSucceedsWhenDocumentsMatch(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(2, Count::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
|
$this->assertEquals(2, Count::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
|
||||||
'There should have been 2 matching documents');
|
'There should have been 2 matching documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when no documents match')]
|
||||||
public function testByContainsSucceedsWhenNoDocumentsMatch(): void
|
public function testByContainsSucceedsWhenNoDocumentsMatch(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(0, Count::byContains(ThrowawayDb::TABLE, ['value' => 'magenta']),
|
$this->assertEquals(0, Count::byContains(ThrowawayDb::TABLE, ['value' => 'magenta']),
|
||||||
'There should have been no matching documents');
|
'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
|
public function testByJsonPathSucceedsWhenDocumentsMatch(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(2, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ < 5)'),
|
$this->assertEquals(2, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ < 5)'),
|
||||||
'There should have been 2 matching documents');
|
'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
|
public function testByJsonPathSucceedsWhenNoDocumentsMatch(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(0, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)'),
|
$this->assertEquals(0, Count::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)'),
|
||||||
|
|
|
@ -34,6 +34,7 @@ class CustomTest extends TestCase
|
||||||
ThrowawayDb::destroy($this->dbName);
|
ThrowawayDb::destroy($this->dbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('runQuery() succeeds with a valid query')]
|
||||||
public function testRunQuerySucceedsWithAValidQuery(): void
|
public function testRunQuerySucceedsWithAValidQuery(): void
|
||||||
{
|
{
|
||||||
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
|
$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
|
public function testRunQueryFailsWithAnInvalidQuery(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
@ -55,6 +57,7 @@ class CustomTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('list() succeeds when data is found')]
|
||||||
public function testListSucceedsWhenDataIsFound(): void
|
public function testListSucceedsWhenDataIsFound(): void
|
||||||
{
|
{
|
||||||
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
|
$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');
|
$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
|
public function testListSucceedsWhenNoDataIsFound(): void
|
||||||
{
|
{
|
||||||
$list = Custom::list(
|
$list = Custom::list(
|
||||||
|
@ -73,6 +77,7 @@ class CustomTest extends TestCase
|
||||||
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
|
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('array() succeeds when data is found')]
|
||||||
public function testArraySucceedsWhenDataIsFound(): void
|
public function testArraySucceedsWhenDataIsFound(): void
|
||||||
{
|
{
|
||||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
|
$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');
|
$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
|
public function testArraySucceedsWhenNoDataIsFound(): void
|
||||||
{
|
{
|
||||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
|
$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');
|
$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
|
public function testSingleSucceedsWhenARowIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
$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');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('single() succeeds when a row is not found')]
|
||||||
public function testSingleSucceedsWhenARowIsNotFound(): void
|
public function testSingleSucceedsWhenARowIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
$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');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('nonQuery() succeeds when operating on data')]
|
||||||
public function testNonQuerySucceedsWhenOperatingOnData(): void
|
public function testNonQuerySucceedsWhenOperatingOnData(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
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');
|
$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
|
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE (data->>'num_value')::numeric > :value",
|
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');
|
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('scalar() succeeds')]
|
||||||
public function testScalarSucceeds(): void
|
public function testScalarSucceeds(): void
|
||||||
{
|
{
|
||||||
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
|
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
|
||||||
|
|
|
@ -47,6 +47,7 @@ class DefinitionTest extends TestCase
|
||||||
[':name' => $name], new ExistsMapper());
|
[':name' => $name], new ExistsMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureTable() succeeds')]
|
||||||
public function testEnsureTableSucceeds(): void
|
public function testEnsureTableSucceeds(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->itExists('ensured'), 'The table should not exist already');
|
$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');
|
$this->assertTrue($this->itExists('idx_ensured_key'), 'The key index should now exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureFieldIndex() succeeds')]
|
||||||
public function testEnsureFieldIndexSucceeds(): void
|
public function testEnsureFieldIndexSucceeds(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->itExists('idx_ensured_test'), 'The index should not exist already');
|
$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');
|
$this->assertTrue($this->itExists('idx_ensured_test'), 'The index should now exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureDocumentIndex() succeeds for Full')]
|
||||||
public function testEnsureDocumentIndexSucceedsForFull(): void
|
public function testEnsureDocumentIndexSucceedsForFull(): void
|
||||||
{
|
{
|
||||||
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';
|
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';
|
||||||
|
@ -73,6 +76,7 @@ class DefinitionTest extends TestCase
|
||||||
$this->assertTrue($this->itExists($docIdx), 'The document index should now exist');
|
$this->assertTrue($this->itExists($docIdx), 'The document index should now exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureDocumentIndex() succeeds for Optimized')]
|
||||||
public function testEnsureDocumentIndexSucceedsForOptimized(): void
|
public function testEnsureDocumentIndexSucceedsForOptimized(): void
|
||||||
{
|
{
|
||||||
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';
|
$docIdx = 'idx_' . ThrowawayDb::TABLE . '_document';
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DeleteTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is deleted')]
|
#[TestDox('byId() succeeds when a document is deleted')]
|
||||||
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByContainsSucceedsWhenDocumentsAreDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByContainsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByJsonPathSucceedsWhenDocumentsAreDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByJsonPathSucceedsWhenDocumentsAreNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||||
|
|
|
@ -35,6 +35,7 @@ class DocumentListTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('create() succeeds')]
|
||||||
public function testCreateSucceeds(): void
|
public function testCreateSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -43,6 +44,7 @@ class DocumentListTest extends TestCase
|
||||||
$list = null;
|
$list = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('items() succeeds')]
|
||||||
public function testItemsSucceeds(): void
|
public function testItemsSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$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');
|
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('items() fails when already consumed')]
|
||||||
public function testItemsFailsWhenAlreadyConsumed(): void
|
public function testItemsFailsWhenAlreadyConsumed(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -69,6 +72,7 @@ class DocumentListTest extends TestCase
|
||||||
iterator_to_array($list->items());
|
iterator_to_array($list->items());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('hasItems() succeeds with empty results')]
|
||||||
public function testHasItemsSucceedsWithEmptyResults(): void
|
public function testHasItemsSucceedsWithEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(
|
$list = DocumentList::create(
|
||||||
|
@ -78,6 +82,7 @@ class DocumentListTest extends TestCase
|
||||||
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
|
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('hasItems() succeeds with non-empty results')]
|
||||||
public function testHasItemsSucceedsWithNonEmptyResults(): void
|
public function testHasItemsSucceedsWithNonEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$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');
|
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('map() succeeds')]
|
||||||
public function testMapSucceeds(): void
|
public function testMapSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -102,6 +108,7 @@ class DocumentListTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('iter() succeeds')]
|
||||||
public function testIterSucceeds(): void
|
public function testIterSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -114,6 +121,7 @@ class DocumentListTest extends TestCase
|
||||||
'Iteration did not have the expected result');
|
'Iteration did not have the expected result');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('mapToArray() succeeds')]
|
||||||
public function testMapToArraySucceeds(): void
|
public function testMapToArraySucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
|
|
@ -35,7 +35,7 @@ class DocumentTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds for array no auto ID')]
|
#[TestDox('insert() succeeds for array no auto ID')]
|
||||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
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');
|
$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
|
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
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');
|
$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
|
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
Configuration::$autoId = AutoId::RandomString;
|
||||||
|
@ -269,12 +269,14 @@ class DocumentTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('insert() fails for duplicate key')]
|
||||||
public function testInsertFailsForDuplicateKey(): void
|
public function testInsertFailsForDuplicateKey(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('save() succeeds when a document is inserted')]
|
||||||
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
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');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('save() succeeds when a document is updated')]
|
||||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
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');
|
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('update() succeeds when replacing a document')]
|
||||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
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');
|
$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
|
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||||
|
|
|
@ -33,51 +33,55 @@ class ExistsTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document exists')]
|
#[TestDox('byId() succeeds when a document exists')]
|
||||||
public function testByIdSucceedsWhenADocumentExists(): void
|
public function testByIdSucceedsWhenADocumentExists(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
|
$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
|
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
||||||
'There should not have been an existing document');
|
'There should not have been an existing document');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when documents exist')]
|
||||||
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
||||||
'There should have been existing documents');
|
'There should have been existing documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no matching documents exist')]
|
||||||
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
||||||
'There should not have been any existing documents');
|
'There should not have been any existing documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when documents exist')]
|
||||||
public function testByContainsSucceedsWhenDocumentsExist(): void
|
public function testByContainsSucceedsWhenDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
|
$this->assertTrue(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'purple']),
|
||||||
'There should have been existing documents');
|
'There should have been existing documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when no matching documents exist')]
|
||||||
public function testByContainsSucceedsWhenNoMatchingDocumentsExist(): void
|
public function testByContainsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'violet']),
|
$this->assertFalse(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'violet']),
|
||||||
'There should not have been existing documents');
|
'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
|
public function testByJsonPathSucceedsWhenDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)'),
|
$this->assertTrue(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)'),
|
||||||
'There should have been existing documents');
|
'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
|
public function testByJsonPathSucceedsWhenNoMatchingDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10.1)'),
|
$this->assertFalse(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10.1)'),
|
||||||
|
|
|
@ -34,6 +34,7 @@ class FindTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('all() succeeds when there is data')]
|
||||||
public function testAllSucceedsWhenThereIsData(): void
|
public function testAllSucceedsWhenThereIsData(): void
|
||||||
{
|
{
|
||||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
|
$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');
|
$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
|
public function testAllSucceedsWhenThereIsNoData(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
|
||||||
{
|
{
|
||||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absent')]);
|
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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when documents are found')]
|
||||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
|
$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');
|
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when documents are found')]
|
||||||
public function testByContainsSucceedsWhenDocumentsAreFound(): void
|
public function testByContainsSucceedsWhenDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
|
$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');
|
$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
|
public function testByContainsSucceedsWhenNoDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
$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');
|
$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
|
public function testByJsonPathSucceedsWhenDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
|
$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');
|
$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
|
public function testByJsonPathSucceedsWhenNoDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
$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');
|
$this->assertFalse($docs->hasItems(), 'The document list should be empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByFields() succeeds when a document is found')]
|
||||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
$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');
|
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
$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');
|
$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
|
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByContains() succeeds when a document is found')]
|
||||||
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
|
public function testFirstByContainsSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'FIRST!'], TestDocument::class);
|
$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');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByContains() succeeds when multiple documents are found')]
|
||||||
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
|
public function testFirstByContainsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'purple'], TestDocument::class);
|
$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');
|
$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
|
public function testFirstByContainsSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
$doc = Find::firstByContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
||||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
$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
|
public function testFirstByJsonPathSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)', TestDocument::class);
|
$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');
|
$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
|
public function testFirstByJsonPathSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', TestDocument::class);
|
$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');
|
$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
|
public function testFirstByJsonPathSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
$doc = Find::firstByJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
||||||
|
|
|
@ -34,7 +34,7 @@ class PatchTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is updated')]
|
#[TestDox('byId() succeeds when a document is updated')]
|
||||||
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
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');
|
$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
|
public function testByIdSucceedsWhenNoDocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
$id = 'forty-seven';
|
$id = 'forty-seven';
|
||||||
|
@ -52,6 +52,7 @@ class PatchTest extends TestCase
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a document is updated')]
|
||||||
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
|
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');
|
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no document is updated')]
|
||||||
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
$fields = [Field::equal('value', 'burgundy')];
|
$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');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when documents are updated')]
|
||||||
public function testByContainsSucceedsWhenDocumentsAreUpdated(): void
|
public function testByContainsSucceedsWhenDocumentsAreUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byContains(ThrowawayDb::TABLE, ['value' => 'another'], ['num_value' => 12]);
|
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');
|
$this->assertEquals(12, $doc->num_value, 'The document was not patched');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when no documents are updated')]
|
||||||
public function testByContainsSucceedsWhenNoDocumentsAreUpdated(): void
|
public function testByContainsSucceedsWhenNoDocumentsAreUpdated(): void
|
||||||
{
|
{
|
||||||
$criteria = ['value' => 'updated'];
|
$criteria = ['value' => 'updated'];
|
||||||
|
@ -86,7 +90,7 @@ class PatchTest extends TestCase
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$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
|
public function testByJsonPathSucceedsWhenDocumentsAreUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', ['value' => 'blue']);
|
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
|
public function testByJsonPathSucceedsWhenDocumentsAreNotUpdated(): void
|
||||||
{
|
{
|
||||||
$path = '$.num_value ? (@ > 100)';
|
$path = '$.num_value ? (@ > 100)';
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when fields are removed')]
|
#[TestDox('byId() succeeds when fields are removed')]
|
||||||
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
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');
|
$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
|
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$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
|
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a field is removed')]
|
||||||
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
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');
|
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a field is not removed')]
|
||||||
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no document is matched')]
|
||||||
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when a field is removed')]
|
||||||
public function testByContainsSucceedsWhenAFieldIsRemoved(): void
|
public function testByContainsSucceedsWhenAFieldIsRemoved(): void
|
||||||
{
|
{
|
||||||
$criteria = ['sub' => ['foo' => 'green']];
|
$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
|
public function testByContainsSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byContains(ThrowawayDb::TABLE, ['sub' => ['foo' => 'green']], ['invalid_field']);
|
RemoveFields::byContains(ThrowawayDb::TABLE, ['sub' => ['foo' => 'green']], ['invalid_field']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() succeeds when no document is matched')]
|
||||||
public function testByContainsSucceedsWhenNoDocumentIsMatched(): void
|
public function testByContainsSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byContains(ThrowawayDb::TABLE, ['value' => 'substantial'], ['num_value']);
|
RemoveFields::byContains(ThrowawayDb::TABLE, ['value' => 'substantial'], ['num_value']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$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
|
public function testByJsonPathSucceedsWhenAFieldIsRemoved(): void
|
||||||
{
|
{
|
||||||
$path = '$.value ? (@ == "purple")';
|
$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
|
public function testByJsonPathSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "purple")', ['submarine']);
|
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "purple")', ['submarine']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$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
|
public function testByJsonPathSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "mauve")', ['value']);
|
RemoveFields::byJsonPath(ThrowawayDb::TABLE, '$.value ? (@ == "mauve")', ['value']);
|
||||||
|
|
|
@ -33,31 +33,35 @@ class CountTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('all() succeeds')]
|
||||||
public function testAllSucceeds(): void
|
public function testAllSucceeds(): void
|
||||||
{
|
{
|
||||||
$count = Count::all(ThrowawayDb::TABLE);
|
$count = Count::all(ThrowawayDb::TABLE);
|
||||||
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds for a numeric range')]
|
||||||
public function testByFieldsSucceedsForANumericRange(): void
|
public function testByFieldsSucceedsForANumericRange(): void
|
||||||
{
|
{
|
||||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('num_value', 10, 20)]);
|
||||||
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
$this->assertEquals(3, $count, 'There should have been 3 matching documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds for a non-numeric range')]
|
||||||
public function testByFieldsSucceedsForANonNumericRange(): void
|
public function testByFieldsSucceedsForANonNumericRange(): void
|
||||||
{
|
{
|
||||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
||||||
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Count::byContains('', []);
|
Count::byContains('', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -34,6 +34,7 @@ class CustomTest extends TestCase
|
||||||
ThrowawayDb::destroy($this->dbName);
|
ThrowawayDb::destroy($this->dbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('runQuery() succeeds with a valid query')]
|
||||||
public function testRunQuerySucceedsWithAValidQuery(): void
|
public function testRunQuerySucceedsWithAValidQuery(): void
|
||||||
{
|
{
|
||||||
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
|
$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
|
public function testRunQueryFailsWithAnInvalidQuery(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
@ -55,6 +57,7 @@ class CustomTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('list() succeeds when data is found')]
|
||||||
public function testListSucceedsWhenDataIsFound(): void
|
public function testListSucceedsWhenDataIsFound(): void
|
||||||
{
|
{
|
||||||
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
|
$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');
|
$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
|
public function testListSucceedsWhenNoDataIsFound(): void
|
||||||
{
|
{
|
||||||
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' > :value",
|
$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');
|
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('array() succeeds when data is found')]
|
||||||
public function testArraySucceedsWhenDataIsFound(): void
|
public function testArraySucceedsWhenDataIsFound(): void
|
||||||
{
|
{
|
||||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
|
$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');
|
$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
|
public function testArraySucceedsWhenNoDataIsFound(): void
|
||||||
{
|
{
|
||||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
|
$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');
|
$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
|
public function testSingleSucceedsWhenARowIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
$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');
|
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('single() succeeds when a row is not found')]
|
||||||
public function testSingleSucceedsWhenARowIsNotFound(): void
|
public function testSingleSucceedsWhenARowIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
$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');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('nonQuery() succeeds when operating on data')]
|
||||||
public function testNonQuerySucceedsWhenOperatingOnData(): void
|
public function testNonQuerySucceedsWhenOperatingOnData(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
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');
|
$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
|
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE data->>'num_value' > :value", [':value' => 100]);
|
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');
|
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('scalar() succeeds')]
|
||||||
public function testScalarSucceeds(): void
|
public function testScalarSucceeds(): void
|
||||||
{
|
{
|
||||||
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
|
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
|
||||||
|
|
|
@ -47,6 +47,7 @@ class DefinitionTest extends TestCase
|
||||||
[':name' => $name], new ExistsMapper());
|
[':name' => $name], new ExistsMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureTable() succeeds')]
|
||||||
public function testEnsureTableSucceeds(): void
|
public function testEnsureTableSucceeds(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->itExists('ensured'), 'The table should not exist already');
|
$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');
|
$this->assertTrue($this->itExists('idx_ensured_key'), 'The key index should now exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureFieldIndex() succeeds')]
|
||||||
public function testEnsureFieldIndexSucceeds(): void
|
public function testEnsureFieldIndexSucceeds(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->itExists('idx_ensured_test'), 'The index should not exist already');
|
$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');
|
$this->assertTrue($this->itExists('idx_ensured_test'), 'The index should now exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('ensureDocumentIndex() fails')]
|
||||||
public function testEnsureDocumentIndexFails(): void
|
public function testEnsureDocumentIndexFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DeleteTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is deleted')]
|
#[TestDox('byId() succeeds when a document is deleted')]
|
||||||
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
$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');
|
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Delete::byContains('', []);
|
Delete::byContains('', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -35,6 +35,7 @@ class DocumentListTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('create() succeeds')]
|
||||||
public function testCreateSucceeds(): void
|
public function testCreateSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -43,6 +44,7 @@ class DocumentListTest extends TestCase
|
||||||
$list = null;
|
$list = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('items() succeeds')]
|
||||||
public function testItemsSucceeds(): void
|
public function testItemsSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$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');
|
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('items() fails when already consumed')]
|
||||||
public function testItemsFailsWhenAlreadyConsumed(): void
|
public function testItemsFailsWhenAlreadyConsumed(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -69,6 +72,7 @@ class DocumentListTest extends TestCase
|
||||||
iterator_to_array($list->items());
|
iterator_to_array($list->items());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('hasItems() succeeds with empty results')]
|
||||||
public function testHasItemsSucceedsWithEmptyResults(): void
|
public function testHasItemsSucceedsWithEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' < 0", [],
|
$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');
|
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('hasItems() succeeds with non-empty results')]
|
||||||
public function testHasItemsSucceedsWithNonEmptyResults(): void
|
public function testHasItemsSucceedsWithNonEmptyResults(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$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');
|
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('map() succeeds')]
|
||||||
public function testMapSucceeds(): void
|
public function testMapSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -100,6 +107,7 @@ class DocumentListTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('iter() succeeds')]
|
||||||
public function testIterSucceeds(): void
|
public function testIterSucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
@ -112,6 +120,7 @@ class DocumentListTest extends TestCase
|
||||||
'Iteration did not have the expected result');
|
'Iteration did not have the expected result');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('mapToArray() succeeds')]
|
||||||
public function testMapToArraySucceeds(): void
|
public function testMapToArraySucceeds(): void
|
||||||
{
|
{
|
||||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||||
|
|
|
@ -35,7 +35,7 @@ class DocumentTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('Insert succeeds for array no auto ID')]
|
#[TestDox('insert() succeeds for array no auto ID')]
|
||||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
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');
|
$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
|
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
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');
|
$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
|
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::Number;
|
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
|
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::UUID;
|
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
|
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
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
|
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
|
||||||
{
|
{
|
||||||
Configuration::$autoId = AutoId::RandomString;
|
Configuration::$autoId = AutoId::RandomString;
|
||||||
|
@ -269,12 +269,14 @@ class DocumentTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('insert() fails for duplicate key')]
|
||||||
public function testInsertFailsForDuplicateKey(): void
|
public function testInsertFailsForDuplicateKey(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('save() succeeds when a document is inserted')]
|
||||||
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
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');
|
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('save() succeeds when a document is updated')]
|
||||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
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');
|
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('update() succeeds when replacing a document')]
|
||||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
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');
|
$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
|
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
|
||||||
{
|
{
|
||||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||||
|
|
|
@ -33,38 +33,41 @@ class ExistsTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document exists')]
|
#[TestDox('byId() succeeds when a document exists')]
|
||||||
public function testByIdSucceedsWhenADocumentExists(): void
|
public function testByIdSucceedsWhenADocumentExists(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
|
$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
|
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
||||||
'There should not have been an existing document');
|
'There should not have been an existing document');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when documents exist')]
|
||||||
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
||||||
'There should have been existing documents');
|
'There should have been existing documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no matching documents exist')]
|
||||||
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
||||||
'There should not have been any existing documents');
|
'There should not have been any existing documents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Exists::byContains('', []);
|
Exists::byContains('', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -34,6 +34,7 @@ class FindTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('all() succeeds when there is data')]
|
||||||
public function testAllSucceedsWhenThereIsData(): void
|
public function testAllSucceedsWhenThereIsData(): void
|
||||||
{
|
{
|
||||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
|
$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');
|
$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
|
public function testAllSucceedsWhenThereIsNoData(): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
$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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
|
||||||
{
|
{
|
||||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
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');
|
$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
|
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when documents are found')]
|
||||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 15)], TestDocument::class);
|
$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');
|
$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
|
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
|
$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');
|
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Find::byContains('', [], TestDocument::class);
|
Find::byContains('', [], TestDocument::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Find::byJsonPath('', '', TestDocument::class);
|
Find::byJsonPath('', '', TestDocument::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByFields() succeeds when a document is found')]
|
||||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
$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');
|
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
$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');
|
$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
|
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||||
{
|
{
|
||||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'absent')], TestDocument::class);
|
||||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('firstByContains() fails')]
|
||||||
public function testFirstByContainsFails(): void
|
public function testFirstByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Find::firstByContains('', [], TestDocument::class);
|
Find::firstByContains('', [], TestDocument::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('First by JSON Path fails')]
|
#[TestDox('firstByJsonPath() fails')]
|
||||||
public function testFirstByJsonPathFails(): void
|
public function testFirstByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -34,7 +34,7 @@ class PatchTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when a document is updated')]
|
#[TestDox('byId() succeeds when a document is updated')]
|
||||||
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
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');
|
$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
|
public function testByIdSucceedsWhenNoDocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byId(ThrowawayDb::TABLE, 'forty-seven', ['foo' => 'green']);
|
Patch::byId(ThrowawayDb::TABLE, 'forty-seven', ['foo' => 'green']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a document is updated')]
|
||||||
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
|
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');
|
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no document is updated')]
|
||||||
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
||||||
{
|
{
|
||||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'burgundy')], ['foo' => 'green']);
|
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'burgundy')], ['foo' => 'green']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
Patch::byContains('', [], []);
|
Patch::byContains('', [], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RemoveFieldsTest extends TestCase
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By ID succeeds when fields are removed')]
|
#[TestDox('byId() succeeds when fields are removed')]
|
||||||
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
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');
|
$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
|
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$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
|
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a field is removed')]
|
||||||
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
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');
|
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when a field is not removed')]
|
||||||
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['nada']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byFields() succeeds when no document is matched')]
|
||||||
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
||||||
{
|
{
|
||||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
||||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TestDox('byContains() fails')]
|
||||||
public function testByContainsFails(): void
|
public function testByContainsFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
RemoveFields::byContains('', [], []);
|
RemoveFields::byContains('', [], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[TestDox('By JSON Path fails')]
|
#[TestDox('byJsonPath() fails')]
|
||||||
public function testByJsonPathFails(): void
|
public function testByJsonPathFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(DocumentException::class);
|
$this->expectException(DocumentException::class);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user