Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 2edee9e

Browse files
committed
Merge pull request #833
2 parents 87b768f + 40975ac commit 2edee9e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
MongoCursor::batchSize() of 1 and -1 closes cursor after returning one document
3+
--SKIPIF--
4+
<?php require "tests/utils/standalone.inc"; ?>
5+
--FILE--
6+
<?php
7+
require "tests/utils/server.inc";
8+
9+
function log_getmore($server, $cursorOptions) {
10+
printf("Issuing getmore with batchSize: %d\n", $cursorOptions['batch_size']);
11+
}
12+
13+
$ctx = stream_context_create(array(
14+
"mongodb" => array(
15+
"log_getmore" => "log_getmore",
16+
),
17+
));
18+
19+
$host = MongoShellServer::getStandaloneInfo();
20+
$m = new MongoClient($host, array(), array('context' => $ctx));
21+
22+
$c = $m->selectCollection(dbname(), collname(__FILE__));
23+
$c->drop();
24+
25+
$c->insert(array('_id' => 1));
26+
$c->insert(array('_id' => 2));
27+
$c->insert(array('_id' => 3));
28+
29+
echo "Testing with batchSize = 1\n";
30+
31+
$cursor = $c->find()->batchSize(1);
32+
33+
printf("Cursor hasNext: %s\n", $cursor->hasNext() ? 'true' : 'false');
34+
printf("Cursor is dead: %s\n", $cursor->dead() ? 'true' : 'false');
35+
$document = $cursor->getNext();
36+
printf("Found document with ID: %d\n", $document['_id']);
37+
38+
echo "\nTesting with batchSize = -1\n";
39+
40+
$cursor = $c->find()->batchSize(-1);
41+
42+
printf("Cursor hasNext: %s\n", $cursor->hasNext() ? 'true' : 'false');
43+
printf("Cursor is dead: %s\n", $cursor->dead() ? 'true' : 'false');
44+
$document = $cursor->getNext();
45+
printf("Found document with ID: %d\n", $document['_id']);
46+
47+
?>
48+
===DONE===
49+
--EXPECT--
50+
Testing with batchSize = 1
51+
Cursor hasNext: true
52+
Cursor is dead: true
53+
Found document with ID: 1
54+
55+
Testing with batchSize = -1
56+
Cursor hasNext: true
57+
Cursor is dead: true
58+
Found document with ID: 1
59+
===DONE===

0 commit comments

Comments
 (0)