v2 RC1 Changes (#7)
- Changes `items` and `hasItems` on `DocumentList` to be properties - Updates dependent option/result library, which contains similar changes Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
@@ -40,8 +40,9 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
foreach ($docs->items as $ignored) $count++;
|
||||
$this->assertEquals(5, $count, 'There should have been 5 documents in the list');
|
||||
}
|
||||
|
||||
@@ -50,6 +51,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class, [Field::named('id')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$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');
|
||||
}
|
||||
@@ -59,6 +61,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::all(ThrowawayDb::TABLE, TestDocument::class, [Field::named('id DESC')]);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$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');
|
||||
}
|
||||
@@ -69,6 +72,7 @@ class FindTest extends TestCase
|
||||
$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');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$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');
|
||||
}
|
||||
@@ -79,15 +83,15 @@ class FindTest extends TestCase
|
||||
Custom::nonQuery('DELETE FROM ' . ThrowawayDb::TABLE, []);
|
||||
$docs = Find::all(ThrowawayDb::TABLE, 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');
|
||||
$this->assertFalse($docs->hasItems, 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is found')]
|
||||
public function testByIdSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 'two', TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('byId() succeeds when a document is found with numeric ID')]
|
||||
@@ -95,15 +99,15 @@ class FindTest extends TestCase
|
||||
{
|
||||
Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']);
|
||||
$doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertEquals('18', $doc->get()->id, 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('18', $doc->value->id, 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[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');
|
||||
$this->assertTrue($doc->isNone, 'There should not have been a document returned');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds when documents are found')]
|
||||
@@ -112,8 +116,9 @@ class FindTest extends TestCase
|
||||
$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');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
foreach ($docs->items as $ignored) $count++;
|
||||
$this->assertEquals(1, $count, 'There should have been 1 document in the list');
|
||||
}
|
||||
|
||||
@@ -123,6 +128,7 @@ class FindTest extends TestCase
|
||||
$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');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$ids = iterator_to_array($docs->map(fn ($it) => $it->id), false);
|
||||
$this->assertEquals(['five', 'four'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
@@ -132,8 +138,9 @@ class FindTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
foreach ($docs->items as $ignored) $count++;
|
||||
$this->assertEquals(1, $count, 'There should have been 1 document in the list');
|
||||
}
|
||||
|
||||
@@ -142,7 +149,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
$this->assertFalse($docs->hasItems, 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byFields() succeeds for inArray when matching documents exist')]
|
||||
@@ -153,8 +160,9 @@ class FindTest extends TestCase
|
||||
$docs = Find::byFields(ThrowawayDb::TABLE, [Field::inArray('values', ThrowawayDb::TABLE, ['c'])],
|
||||
ArrayDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertTrue($docs->hasItems, 'There should have been documents in the list');
|
||||
$count = 0;
|
||||
foreach ($docs->items() as $ignored) $count++;
|
||||
foreach ($docs->items as $ignored) $count++;
|
||||
$this->assertEquals(2, $count, 'There should have been 2 documents in the list');
|
||||
}
|
||||
|
||||
@@ -166,7 +174,7 @@ class FindTest extends TestCase
|
||||
$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');
|
||||
$this->assertFalse($docs->hasItems, 'There should have been no documents in the list');
|
||||
}
|
||||
|
||||
#[TestDox('byContains() fails')]
|
||||
@@ -187,16 +195,16 @@ class FindTest extends TestCase
|
||||
public function testFirstByFieldsSucceedsWhenADocumentIsFound(): void
|
||||
{
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('two', $doc->value->id, 'The incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple documents are found')]
|
||||
public function testFirstByFieldsSucceedsWhenMultipleDocumentsAreFound(): void
|
||||
{
|
||||
$doc = Find::firstByFields(ThrowawayDb::TABLE, [Field::equal('sub.foo', 'green')], TestDocument::class);
|
||||
$this->assertTrue($doc->isSome(), 'There should have been a document returned');
|
||||
$this->assertContains($doc->get()->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertContains($doc->value->id, ['two', 'four'], 'An incorrect document was returned');
|
||||
}
|
||||
|
||||
#[TestDox('firstByFields() succeeds when multiple ordered documents are found')]
|
||||
@@ -204,15 +212,15 @@ class FindTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
$this->assertTrue($doc->isSome, 'There should have been a document returned');
|
||||
$this->assertEquals('four', $doc->value->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::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')]
|
||||
|
||||
Reference in New Issue
Block a user