Change doc list hasItems and items to properties
- Update associated tests
This commit is contained in:
@@ -39,8 +39,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');
|
||||
}
|
||||
|
||||
@@ -49,6 +50,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');
|
||||
}
|
||||
@@ -58,6 +60,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');
|
||||
}
|
||||
@@ -68,6 +71,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');
|
||||
}
|
||||
@@ -78,7 +82,7 @@ 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')]
|
||||
@@ -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() succeeds when documents are found')]
|
||||
@@ -174,8 +182,9 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'purple'], 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(2, $count, 'There should have been 2 documents in the list');
|
||||
}
|
||||
|
||||
@@ -185,6 +194,7 @@ class FindTest extends TestCase
|
||||
$docs = Find::byContains(ThrowawayDb::TABLE, ['sub' => ['foo' => 'green']], TestDocument::class,
|
||||
[Field::named('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'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
@@ -194,7 +204,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::byContains(ThrowawayDb::TABLE, ['value' => 'indigo'], TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$this->assertFalse($docs->hasItems(), 'The document list should be empty');
|
||||
$this->assertFalse($docs->hasItems, 'The document list should be empty');
|
||||
}
|
||||
|
||||
#[TestDox('byJsonPath() succeeds when documents are found')]
|
||||
@@ -202,8 +212,9 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', 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(2, $count, 'There should have been 2 documents in the list');
|
||||
}
|
||||
|
||||
@@ -213,6 +224,7 @@ class FindTest extends TestCase
|
||||
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 10)', 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'], $ids, 'The documents were not ordered correctly');
|
||||
}
|
||||
@@ -222,7 +234,7 @@ class FindTest extends TestCase
|
||||
{
|
||||
$docs = Find::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ > 100)', TestDocument::class);
|
||||
$this->assertNotNull($docs, 'There should have been a document list returned');
|
||||
$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')]
|
||||
|
||||
Reference in New Issue
Block a user