Changes for beta10 (#5)
- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
@@ -33,31 +33,35 @@ class CountTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds')]
|
||||
public function testAllSucceeds(): void
|
||||
{
|
||||
$count = Count::all(ThrowawayDb::TABLE);
|
||||
$this->assertEquals(5, $count, 'There should have been 5 matching documents');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds for a numeric range')]
|
||||
public function testByFieldsSucceedsForANumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('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');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds for a non-numeric range')]
|
||||
public function testByFieldsSucceedsForANonNumericRange(): void
|
||||
{
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::BT('value', 'aardvark', 'apple')]);
|
||||
$count = Count::byFields(ThrowawayDb::TABLE, [Field::between('value', 'aardvark', 'apple')]);
|
||||
$this->assertEquals(1, $count, 'There should have been 1 matching document');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Count::byContains('', []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -34,7 +34,8 @@ class CustomTest extends TestCase
|
||||
ThrowawayDb::destroy($this->dbName);
|
||||
}
|
||||
|
||||
public function testRunQuerySucceedsWithAValidQuery()
|
||||
#[TestDox('runQuery() succeeds with a valid query')]
|
||||
public function testRunQuerySucceedsWithAValidQuery(): void
|
||||
{
|
||||
$stmt = &Custom::runQuery('SELECT data FROM ' . ThrowawayDb::TABLE . ' LIMIT 1', []);
|
||||
try {
|
||||
@@ -44,7 +45,8 @@ class CustomTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testRunQueryFailsWithAnInvalidQuery()
|
||||
#[TestDox('runQuery() fails with an invalid query')]
|
||||
public function testRunQueryFailsWithAnInvalidQuery(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
$stmt = &Custom::runQuery('GRAB stuff FROM over_there UNTIL done', []);
|
||||
@@ -55,7 +57,8 @@ class CustomTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testListSucceedsWhenDataIsFound()
|
||||
#[TestDox('list() succeeds when data is found')]
|
||||
public function testListSucceedsWhenDataIsFound(): void
|
||||
{
|
||||
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE), [], new DocumentMapper(TestDocument::class));
|
||||
$this->assertNotNull($list, 'The document list should not be null');
|
||||
@@ -64,7 +67,8 @@ class CustomTest extends TestCase
|
||||
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
|
||||
}
|
||||
|
||||
public function testListSucceedsWhenNoDataIsFound()
|
||||
#[TestDox('list() succeeds when no data is found')]
|
||||
public function testListSucceedsWhenNoDataIsFound(): void
|
||||
{
|
||||
$list = Custom::list(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' > :value",
|
||||
[':value' => 100], new DocumentMapper(TestDocument::class));
|
||||
@@ -72,7 +76,8 @@ class CustomTest extends TestCase
|
||||
$this->assertFalse($list->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
public function testArraySucceedsWhenDataIsFound()
|
||||
#[TestDox('array() succeeds when data is found')]
|
||||
public function testArraySucceedsWhenDataIsFound(): void
|
||||
{
|
||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'sub' IS NOT NULL", [],
|
||||
new DocumentMapper(TestDocument::class));
|
||||
@@ -80,7 +85,8 @@ class CustomTest extends TestCase
|
||||
$this->assertCount(2, $array, 'There should have been 2 documents in the array');
|
||||
}
|
||||
|
||||
public function testArraySucceedsWhenNoDataIsFound()
|
||||
#[TestDox('array() succeeds when no data is found')]
|
||||
public function testArraySucceedsWhenNoDataIsFound(): void
|
||||
{
|
||||
$array = Custom::array(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'value' = :value",
|
||||
[':value' => 'not there'], new DocumentMapper(TestDocument::class));
|
||||
@@ -88,6 +94,7 @@ class CustomTest extends TestCase
|
||||
$this->assertCount(0, $array, 'There should have been no documents in the array');
|
||||
}
|
||||
|
||||
#[TestDox('single() succeeds when a row is found')]
|
||||
public function testSingleSucceedsWhenARowIsFound(): void
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id", [':id' => 'one'],
|
||||
@@ -96,6 +103,7 @@ class CustomTest extends TestCase
|
||||
$this->assertEquals('one', $doc->get()->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('single() succeeds when a row is not found')]
|
||||
public function testSingleSucceedsWhenARowIsNotFound(): void
|
||||
{
|
||||
$doc = Custom::single('SELECT data FROM ' . ThrowawayDb::TABLE . " WHERE data->>'id' = :id",
|
||||
@@ -103,21 +111,24 @@ class CustomTest extends TestCase
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
public function testNonQuerySucceedsWhenOperatingOnData()
|
||||
#[TestDox('nonQuery() succeeds when operating on data')]
|
||||
public function testNonQuerySucceedsWhenOperatingOnData(): void
|
||||
{
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$remaining = Count::all(ThrowawayDb::TABLE);
|
||||
$this->assertEquals(0, $remaining, 'There should be no documents remaining in the table');
|
||||
}
|
||||
|
||||
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause()
|
||||
#[TestDox('nonQuery() succeeds when no data matches WHERE clause')]
|
||||
public function testNonQuerySucceedsWhenNoDataMatchesWhereClause(): void
|
||||
{
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE . " WHERE data->>'num_value' > :value", [':value' => 100]);
|
||||
$remaining = Count::all(ThrowawayDb::TABLE);
|
||||
$this->assertEquals(5, $remaining, 'There should be 5 documents remaining in the table');
|
||||
}
|
||||
|
||||
public function testScalarSucceeds()
|
||||
#[TestDox('scalar() succeeds')]
|
||||
public function testScalarSucceeds(): void
|
||||
{
|
||||
$value = Custom::scalar("SELECT 5 AS it", [], new CountMapper());
|
||||
$this->assertEquals(5, $value, 'The scalar value was not returned correctly');
|
||||
|
||||
@@ -47,6 +47,7 @@ class DefinitionTest extends TestCase
|
||||
[':name' => $name], new ExistsMapper());
|
||||
}
|
||||
|
||||
#[TestDox('ensureTable() succeeds')]
|
||||
public function testEnsureTableSucceeds(): void
|
||||
{
|
||||
$this->assertFalse($this->itExists('ensured'), 'The table should not exist already');
|
||||
@@ -56,6 +57,7 @@ class DefinitionTest extends TestCase
|
||||
$this->assertTrue($this->itExists('idx_ensured_key'), 'The key index should now exist');
|
||||
}
|
||||
|
||||
#[TestDox('ensureFieldIndex() succeeds')]
|
||||
public function testEnsureFieldIndexSucceeds(): void
|
||||
{
|
||||
$this->assertFalse($this->itExists('idx_ensured_test'), 'The index should not exist already');
|
||||
@@ -64,6 +66,7 @@ class DefinitionTest extends TestCase
|
||||
$this->assertTrue($this->itExists('idx_ensured_test'), 'The index should now exist');
|
||||
}
|
||||
|
||||
#[TestDox('ensureDocumentIndex() fails')]
|
||||
public function testEnsureDocumentIndexFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -33,7 +33,7 @@ class DeleteTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is deleted')]
|
||||
#[TestDox('byId() succeeds when a document is deleted')]
|
||||
public function testByIdSucceedsWhenADocumentIsDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
@@ -41,7 +41,7 @@ class DeleteTest extends TestCase
|
||||
$this->assertEquals(4, Count::all(ThrowawayDb::TABLE), 'There should have been 4 documents remaining');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is not deleted')]
|
||||
#[TestDox('byId() succeeds when a document is not deleted')]
|
||||
public function testByIdSucceedsWhenADocumentIsNotDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
@@ -49,27 +49,30 @@ class DeleteTest extends TestCase
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are deleted')]
|
||||
public function testByFieldsSucceedsWhenDocumentsAreDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::NE('value', 'purple')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notEqual('value', 'purple')]);
|
||||
$this->assertEquals(2, Count::all(ThrowawayDb::TABLE), 'There should have been 2 documents remaining');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are not deleted')]
|
||||
public function testByFieldsSucceedsWhenDocumentsAreNotDeleted(): void
|
||||
{
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents to start');
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'crimson')]);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'crimson')]);
|
||||
$this->assertEquals(5, Count::all(ThrowawayDb::TABLE), 'There should have been 5 documents remaining');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Delete::byContains('', []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -35,6 +35,7 @@ class DocumentListTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('create() succeeds')]
|
||||
public function testCreateSucceeds(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -43,6 +44,7 @@ class DocumentListTest extends TestCase
|
||||
$list = null;
|
||||
}
|
||||
|
||||
#[TestDox('items() succeeds')]
|
||||
public function testItemsSucceeds(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -57,6 +59,7 @@ class DocumentListTest extends TestCase
|
||||
$this->assertEquals(5, $count, 'There should have been 5 documents returned');
|
||||
}
|
||||
|
||||
#[TestDox('items() fails when already consumed')]
|
||||
public function testItemsFailsWhenAlreadyConsumed(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -69,6 +72,7 @@ class DocumentListTest extends TestCase
|
||||
iterator_to_array($list->items());
|
||||
}
|
||||
|
||||
#[TestDox('hasItems() succeeds with empty results')]
|
||||
public function testHasItemsSucceedsWithEmptyResults(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE) . " WHERE data->>'num_value' < 0", [],
|
||||
@@ -77,6 +81,7 @@ class DocumentListTest extends TestCase
|
||||
$this->assertFalse($list->hasItems(), 'There should be no items in the list');
|
||||
}
|
||||
|
||||
#[TestDox('hasItems() succeeds with non-empty results')]
|
||||
public function testHasItemsSucceedsWithNonEmptyResults(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -88,6 +93,8 @@ class DocumentListTest extends TestCase
|
||||
}
|
||||
$this->assertFalse($list->hasItems(), 'There should be no remaining items in the list');
|
||||
}
|
||||
|
||||
#[TestDox('map() succeeds')]
|
||||
public function testMapSucceeds(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -100,6 +107,7 @@ class DocumentListTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('iter() succeeds')]
|
||||
public function testIterSucceeds(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
@@ -112,6 +120,7 @@ class DocumentListTest extends TestCase
|
||||
'Iteration did not have the expected result');
|
||||
}
|
||||
|
||||
#[TestDox('mapToArray() succeeds')]
|
||||
public function testMapToArraySucceeds(): void
|
||||
{
|
||||
$list = DocumentList::create(Query::selectFromTable(ThrowawayDb::TABLE), [],
|
||||
|
||||
@@ -35,7 +35,7 @@ class DocumentTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array no auto ID')]
|
||||
#[TestDox('insert() succeeds for array no auto ID')]
|
||||
public function testInsertSucceedsForArrayNoAutoId(): void
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'turkey', 'sub' => ['foo' => 'gobble', 'bar' => 'gobble']]);
|
||||
@@ -50,7 +50,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto number ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto number ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoNumberIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -74,7 +74,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto number ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto number ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoNumberIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -90,14 +90,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto UUID ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto UUID ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoUuidIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'num_value' => 5]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 5)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 5)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -105,7 +105,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto UUID ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto UUID ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoUuidIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
@@ -113,7 +113,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => $uuid, 'value' => 'uuid', 'num_value' => 12]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 12)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 12)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -121,7 +121,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto string ID not provided')]
|
||||
#[TestDox('insert() succeeds for array with auto string ID not provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoStringIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
@@ -129,7 +129,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => '', 'value' => 'new', 'num_value' => 8]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 8)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 8)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(6, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 6 characters');
|
||||
@@ -139,14 +139,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for array with auto string ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for array with auto string ID with ID provided')]
|
||||
public function testInsertSucceedsForArrayWithAutoStringIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 'my-key', 'value' => 'old', 'num_value' => 3]);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -154,7 +154,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object no auto ID')]
|
||||
#[TestDox('insert() succeeds for object no auto ID')]
|
||||
public function testInsertSucceedsForObjectNoAutoId(): void
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('turkey', sub: new SubDocument('gobble', 'gobble')));
|
||||
@@ -169,7 +169,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('gobble', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto number ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto number ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoNumberIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
@@ -177,12 +177,12 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'taco'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'taco')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'taco')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(1, $doc->get()->id, 'The ID 1 should have been auto-generated');
|
||||
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(value: 'burrito'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'burrito')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'burrito')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(2, $doc->get()->id, 'The ID 2 should have been auto-generated');
|
||||
} finally {
|
||||
@@ -190,14 +190,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto number ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto number ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoNumberIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new NumDocument(64, 'large'));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'large')], NumDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'large')], NumDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(64, $doc->get()->id, 'The ID 64 should have been stored');
|
||||
} finally {
|
||||
@@ -205,14 +205,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto UUID ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto UUID ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoUuidIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(value: 'something', num_value: 9));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EX('value')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::exists('value')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNotEmpty($doc->get()->id, 'The ID should have been auto-generated');
|
||||
} finally {
|
||||
@@ -220,7 +220,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto UUID ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto UUID ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoUuidIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
@@ -228,7 +228,7 @@ class DocumentTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$uuid = AutoId::generateUUID();
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument($uuid, num_value: 14));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 14)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 14)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals($uuid, $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -236,7 +236,7 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto string ID not provided')]
|
||||
#[TestDox('insert() succeeds for object with auto string ID not provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoStringIdNotProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
@@ -244,7 +244,7 @@ class DocumentTest extends TestCase
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument(num_value: 55));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 55)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 55)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals(40, strlen($doc->get()->id),
|
||||
'The ID should have been auto-generated and had 40 characters');
|
||||
@@ -254,14 +254,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds for object with auto string ID with ID provided')]
|
||||
#[TestDox('insert() succeeds for object with auto string ID with ID provided')]
|
||||
public function testInsertSucceedsForObjectWithAutoStringIdWithIdProvided(): void
|
||||
{
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
try {
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('my-key', num_value: 3));
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 3)], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 3)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('my-key', $doc->get()->id, 'The ID should not have been changed');
|
||||
} finally {
|
||||
@@ -269,12 +269,14 @@ class DocumentTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('insert() fails for duplicate key')]
|
||||
public function testInsertFailsForDuplicateKey(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Document::insert(ThrowawayDb::TABLE, new TestDocument('one'));
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is inserted')]
|
||||
public function testSaveSucceedsWhenADocumentIsInserted(): void
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('test', sub: new SubDocument('a', 'b')));
|
||||
@@ -282,6 +284,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('save() succeeds when a document is updated')]
|
||||
public function testSaveSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Document::save(ThrowawayDb::TABLE, new TestDocument('two', num_value: 44));
|
||||
@@ -292,6 +295,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertNull($doc->sub, 'The sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('update() succeeds when replacing a document')]
|
||||
public function testUpdateSucceedsWhenReplacingADocument(): void
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'one', new TestDocument('one', 'howdy', 8, new SubDocument('y', 'z')));
|
||||
@@ -305,6 +309,7 @@ class DocumentTest extends TestCase
|
||||
$this->assertEquals('z', $doc->sub->bar, 'The sub-document bar property was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('update() succeeds when no document is replaced')]
|
||||
public function testUpdateSucceedsWhenNoDocumentIsReplaced(): void
|
||||
{
|
||||
Document::update(ThrowawayDb::TABLE, 'two-hundred', new TestDocument('200'));
|
||||
|
||||
@@ -33,38 +33,41 @@ class ExistsTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document exists')]
|
||||
#[TestDox('byId() succeeds when a document exists')]
|
||||
public function testByIdSucceedsWhenADocumentExists(): void
|
||||
{
|
||||
$this->assertTrue(Exists::byId(ThrowawayDb::TABLE, 'three'), 'There should have been an existing document');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document does not exist')]
|
||||
#[TestDox('byId() succeeds when a document does not exist')]
|
||||
public function testByIdSucceedsWhenADocumentDoesNotExist(): void
|
||||
{
|
||||
$this->assertFalse(Exists::byId(ThrowawayDb::TABLE, 'seven'),
|
||||
'There should not have been an existing document');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents exist')]
|
||||
public function testByFieldsSucceedsWhenDocumentsExist(): void
|
||||
{
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 10)]),
|
||||
$this->assertTrue(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]),
|
||||
'There should have been existing documents');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when no matching documents exist')]
|
||||
public function testByFieldsSucceedsWhenNoMatchingDocumentsExist(): void
|
||||
{
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::LT('nothing', 'none')]),
|
||||
$this->assertFalse(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]),
|
||||
'There should not have been any existing documents');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Exists::byContains('', []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -8,9 +8,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Test\Integration\SQLite;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, Document, DocumentException, Field, Find};
|
||||
use BitBadger\PDODocument\{Custom, Delete, Document, DocumentException, Field, FieldMatch, Find};
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Test\Integration\ArrayDocument;
|
||||
use Test\Integration\TestDocument;
|
||||
|
||||
/**
|
||||
@@ -34,6 +35,7 @@ class FindTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds when there is data')]
|
||||
public function testAllSucceedsWhenThereIsData(): void
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
|
||||
@@ -43,6 +45,35 @@ class FindTest extends TestCase
|
||||
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds when ordering data ascending')]
|
||||
public function testAllSucceedsWhenOrderingDataAscending(): void
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class, [Field::named('id')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$ids = iterator_to_array($docs->map(fn ($it) => $it->id), false);
|
||||
$this->assertEquals(['five', 'four', 'one', 'three', 'two'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds when ordering data descending')]
|
||||
public function testAllSucceedsWhenOrderingDataDescending(): void
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class, [Field::named('id DESC')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$ids = iterator_to_array($docs->map(fn ($it) => $it->id), false);
|
||||
$this->assertEquals(['two', 'three', 'one', 'four', 'five'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds when ordering data numerically')]
|
||||
public function testAllSucceedsWhenOrderingDataNumerically(): void
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class,
|
||||
[Field::named('sub.foo NULLS LAST'), Field::named('n:num_value')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$ids = iterator_to_array($docs->map(fn ($it) => $it->id), false);
|
||||
$this->assertEquals(['two', 'four', 'one', 'three', 'five'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
|
||||
#[TestDox('all() succeeds when there is no data')]
|
||||
public function testAllSucceedsWhenThereIsNoData(): void
|
||||
{
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
@@ -51,7 +82,7 @@ class FindTest extends TestCase
|
||||
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is found')]
|
||||
#[TestDox('byId() succeeds when a document is found')]
|
||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
@@ -59,7 +90,7 @@ class FindTest extends TestCase
|
||||
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is found with numeric ID')]
|
||||
#[TestDox('byId() succeeds when a document is found with numeric ID')]
|
||||
public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||
@@ -68,69 +99,130 @@ class FindTest extends TestCase
|
||||
$this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is not found')]
|
||||
#[TestDox('byId() succeeds when a document is not found')]
|
||||
public function testByIdSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'seventy-five', TestDocument::class);
|
||||
$this->assertTrue($doc->isNone(), 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found')]
|
||||
public function testByFieldsSucceedsWhenDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 15)], TestDocument::class);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::in('value', ['blue', 'purple']), Field::exists('sub')],
|
||||
TestDocument::class, FieldMatch::All);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
$this->assertEquals(1, $count, 'There should have been 1 document in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found and ordered')]
|
||||
public function testByFieldsSucceedsWhenDocumentsAreFoundAndOrdered(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], TestDocument::class,
|
||||
FieldMatch::All, [Field::named('id')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$ids = iterator_to_array($docs->map(fn ($it) => $it->id), false);
|
||||
$this->assertEquals(['five', 'four'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found using IN with numeric field')]
|
||||
public function testByFieldsSucceedsWhenDocumentsAreFoundUsingInWithNumericField(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::in('num_value', [2, 4, 6, 8])], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
$this->assertEquals(1, $count, 'There should have been 1 document in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when no documents are found')]
|
||||
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::greater('num_value', 100)], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds for inArray when matching documents exist')]
|
||||
public function testByFieldsSucceedsForInArrayWhenMatchingDocumentsExist(): void
|
||||
{
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absentField')]);
|
||||
foreach (ArrayDocument::testDocuments() as $doc) Document::insert(ThrowawayDb::TABLE, $doc);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::inArray('values', ThrowawayDb::TABLE, ['c'])],
|
||||
ArrayDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
|
||||
}
|
||||
|
||||
public function testByFieldsSucceedsWhenNoDocumentsAreFound(): void
|
||||
#[TestDox('byFields() succeeds for inArray when no matching documents exist')]
|
||||
public function testByFieldsSucceedsForInArrayWhenNoMatchingDocumentsExist(): void
|
||||
{
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::GT('num_value', 100)], TestDocument::class);
|
||||
Delete::byFields(ThrowawayDb::TABLE, [Field::notExists('absentField')]);
|
||||
foreach (ArrayDocument::testDocuments() as $doc) Document::insert(ThrowawayDb::TABLE, $doc);
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::inArray('values', ThrowawayDb::TABLE, ['j'])],
|
||||
ArrayDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertFalse($docs->hasItems(), 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Find::byContains('', [], TestDocument::class);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Find::byJsonPath('', '', TestDocument::class);
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when a document is found')]
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('value', 'another')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('value', 'another')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('sub.foo', 'green')], TestDocument::class);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple ordered documents are found')]
|
||||
public function testFirstByFieldsSucceedsWhenMultipleOrderedDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class,
|
||||
orderBy: [Field::named('n:num_value DESC')]);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->get()->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when a document is not found')]
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsNotFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('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');
|
||||
}
|
||||
|
||||
#[TestDox('firstByContains() fails')]
|
||||
public function testFirstByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Find::firstByContains('', [], TestDocument::class);
|
||||
}
|
||||
|
||||
#[TestDox('First by JSON Path fails')]
|
||||
#[TestDox('firstByJsonPath() fails')]
|
||||
public function testFirstByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -34,7 +34,7 @@ class PatchTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a document is updated')]
|
||||
#[TestDox('byId() succeeds when a document is updated')]
|
||||
public function testByIdSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byId(ThrowawayDb::TABLE, 'one', ['num_value' => 44]);
|
||||
@@ -43,33 +43,36 @@ class PatchTest extends TestCase
|
||||
$this->assertEquals(44, $doc->get()->num_value, 'The updated document is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when no document is updated')]
|
||||
#[TestDox('byId() succeeds when no document is updated')]
|
||||
public function testByIdSucceedsWhenNoDocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byId(ThrowawayDb::TABLE, 'forty-seven', ['foo' => 'green']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when a document is updated')]
|
||||
public function testByFieldsSucceedsWhenADocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 77)]);
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::equal('value', 'purple')], ['num_value' => 77]);
|
||||
$after = Count::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 77)]);
|
||||
$this->assertEquals(2, $after, 'There should have been 2 documents updated');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when no document is updated')]
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsUpdated(): void
|
||||
{
|
||||
Patch::byFields(ThrowawayDb::TABLE, [Field::EQ('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');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
Patch::byContains('', [], []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
@@ -34,7 +34,7 @@ class RemoveFieldsTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when fields are removed')]
|
||||
#[TestDox('byId() succeeds when fields are removed')]
|
||||
public function testByIdSucceedsWhenFieldsAreRemoved(): void
|
||||
{
|
||||
RemoveFields::byId(ThrowawayDb::TABLE, 'two', ['sub', 'value']);
|
||||
@@ -45,47 +45,51 @@ class RemoveFieldsTest extends TestCase
|
||||
$this->assertNull($doc->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when a field is not removed')]
|
||||
#[TestDox('byId() succeeds when a field is not removed')]
|
||||
public function testByIdSucceedsWhenAFieldIsNotRemoved(): void
|
||||
{
|
||||
RemoveFields::byId(ThrowawayDb::TABLE, 'one', ['a_field_that_does_not_exist']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
#[TestDox('By ID succeeds when no document is matched')]
|
||||
#[TestDox('byId() succeeds when no document is matched')]
|
||||
public function testByIdSucceedsWhenNoDocumentIsMatched(): void
|
||||
{
|
||||
RemoveFields::byId(ThrowawayDb::TABLE, 'fifty', ['sub']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when a field is removed')]
|
||||
public function testByFieldsSucceedsWhenAFieldIsRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::EQ('num_value', 17)], TestDocument::class);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], ['sub']);
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('num_value', 17)], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertNull($doc->get()->sub, 'Sub-document should have been null');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when a field is not removed')]
|
||||
public function testByFieldsSucceedsWhenAFieldIsNotRemoved(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::EQ('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');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when no document is matched')]
|
||||
public function testByFieldsSucceedsWhenNoDocumentIsMatched(): void
|
||||
{
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::NE('missing', 'nope')], ['value']);
|
||||
RemoveFields::byFields(ThrowawayDb::TABLE, [Field::notEqual('missing', 'nope')], ['value']);
|
||||
$this->assertTrue(true, 'The above not throwing an exception is the test');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
public function testByContainsFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
RemoveFields::byContains('', [], []);
|
||||
}
|
||||
|
||||
#[TestDox('By JSON Path fails')]
|
||||
#[TestDox('byJsonPath() fails')]
|
||||
public function testByJsonPathFails(): void
|
||||
{
|
||||
$this->expectException(DocumentException::class);
|
||||
|
||||
Reference in New Issue
Block a user