Skip to content

Commit ee751dc

Browse files
committed
Test cursor iteration beyond last document for CDRIVER-1234
1 parent dc9ec55 commit ee751dc

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor iteration beyond last document (find command)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(STANDALONE);
10+
11+
$bulk = new MongoDB\Driver\BulkWrite();
12+
$bulk->insert(['_id' => 1]);
13+
$manager->executeBulkWrite(NS, $bulk);
14+
15+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([]));
16+
17+
$iterator = new IteratorIterator($cursor);
18+
$iterator->rewind();
19+
var_dump($iterator->current());
20+
$iterator->next();
21+
var_dump($iterator->current());
22+
23+
// libmongoc throws on superfluous iteration of find command cursor (CDRIVER-1234)
24+
echo throws(function() use ($iterator) {
25+
$iterator->next();
26+
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECTF--
32+
object(stdClass)#%d (%d) {
33+
["_id"]=>
34+
int(1)
35+
}
36+
NULL
37+
OK: Got MongoDB\Driver\Exception\RuntimeException
38+
Cannot advance a completed or failed cursor.
39+
===DONE===
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor iteration beyond last document (OP_QUERY)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE_30) ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(STANDALONE_30);
10+
11+
$bulk = new MongoDB\Driver\BulkWrite();
12+
$bulk->insert(['_id' => 1]);
13+
$manager->executeBulkWrite(NS, $bulk);
14+
15+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array(), array('batchSize' => 2)));
16+
17+
$iterator = new IteratorIterator($cursor);
18+
$iterator->rewind();
19+
var_dump($iterator->current());
20+
$iterator->next();
21+
var_dump($iterator->current());
22+
23+
// libmongoc throws on superfluous iteration of OP_QUERY cursor (CDRIVER-1234)
24+
echo throws(function() use ($iterator) {
25+
$iterator->next();
26+
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECTF--
32+
object(stdClass)#%d (%d) {
33+
["_id"]=>
34+
int(1)
35+
}
36+
NULL
37+
OK: Got MongoDB\Driver\Exception\RuntimeException
38+
Cannot advance a completed or failed cursor.
39+
===DONE===

0 commit comments

Comments
 (0)