Skip to content

Commit c8023c7

Browse files
committed
make CollectionHandler::all work in Batch plus test
1 parent 9ffea68 commit c8023c7

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lib/ArangoDBClient/BatchPart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public function getProcessedResponse()
293293
}
294294
break;
295295
case 'cursor':
296+
case 'all':
296297
$options = $this->getCursorOptions();
297298
$options['_isNew'] = false;
298299

lib/ArangoDBClient/CollectionHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,10 @@ public function all($collectionId, array $options = [])
11541154
);
11551155

11561156
$response = $this->getConnection()->put(Urls::URL_ALL, $this->json_encode_wrapper($body));
1157+
1158+
if ($batchPart = $response->getBatchPart()) {
1159+
return $batchPart;
1160+
}
11571161

11581162
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
11591163

tests/BatchTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,44 @@ public function testRemoveByKeysInBatch()
482482
static::assertTrue($existing == 0, 'Batch removeByKeys not removed all documents!');
483483
}
484484

485+
public function testCollectionHandlerAllInBatch()
486+
{
487+
$connection = $this->connection;
488+
$collection = $this->collection;
489+
$document1 = Document::createFromArray([ "foo" => "bar" ]);
490+
$document2 = Document::createFromArray([ "foo" => "baz" ]);
491+
$documentHandler = new DocumentHandler($connection);
492+
493+
$documentId1 = $documentHandler->save($collection->getName(), $document1);
494+
$documentId2 = $documentHandler->save($collection->getName(), $document2);
495+
496+
$documentIds = [];
497+
$cursor = $this->collectionHandler->all($collection->getName());
498+
foreach($cursor->getAll() as $doc) {
499+
$documentIds[$doc->getId()] = $doc;
500+
}
501+
502+
$batch = new Batch($this->connection);
503+
$batch->startCapture();
504+
505+
$part = $this->collectionHandler->all($collection->getName());
506+
507+
static::assertInstanceOf(BatchPart::class, $part);
508+
509+
$batch->process();
510+
511+
$cursor = $batch->getPart(0)->getProcessedResponse();
512+
$results = $cursor->getAll();
513+
514+
static::assertInstanceOf(Cursor::class, $cursor);
515+
static::assertTrue(count($documentIds) == count($results));
516+
517+
foreach($results as $result) {
518+
static::assertTrue(isset($documentIds[$result->getId()]));
519+
static::assertEquals($documentIds[$result->getId()], $result);
520+
}
521+
}
522+
485523
public function tearDown()
486524
{
487525
try {

0 commit comments

Comments
 (0)