Skip to content

Commit da511cb

Browse files
committed
Split tests into pre and post 3.6 versions due to changes in exception class
1 parent b45a519 commit da511cb

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

tests/cursor/cursor-getmore-005.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MongoDB\Driver\Cursor query result iteration with getmore failure
99
?>
1010
<?php skip_if_not_live(); ?>
1111
<?php skip_if_not_standalone(); ?>
12+
<?php skip_if_server_version(">=", "3.6"); ?>
1213
<?php skip_if_no_getmore_failpoint(); ?>
1314
<?php skip_if_auth(); ?>
1415
--FILE--

tests/cursor/cursor-getmore-006.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MongoDB\Driver\Cursor command result iteration with getmore failure
99
?>
1010
<?php skip_if_not_live(); ?>
1111
<?php skip_if_not_standalone(); ?>
12+
<?php skip_if_server_version(">=", "3.6"); ?>
1213
<?php skip_if_no_getmore_failpoint(); ?>
1314
<?php skip_if_auth(); ?>
1415
--FILE--

tests/cursor/cursor-getmore-007.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor query result iteration with getmore failure
3+
--SKIPIF--
4+
<?php require __DIR__ . "/" ."../utils/basic-skipif.inc"; ?>
5+
<?php
6+
/* This test spins up its own mongod instance, so only run this in the most default "standalone, no
7+
* auth" configurations. This way, we can test on multiple server versions, but not waste resources
8+
* on f.e. Travis. */
9+
?>
10+
<?php skip_if_not_live(); ?>
11+
<?php skip_if_not_standalone(); ?>
12+
<?php skip_if_server_version("<", "3.6"); ?>
13+
<?php skip_if_no_getmore_failpoint(); ?>
14+
<?php skip_if_auth(); ?>
15+
--FILE--
16+
<?php
17+
require_once __DIR__ . "/../utils/basic.inc";
18+
19+
$uri = createTemporaryMongoInstance();
20+
$manager = new MongoDB\Driver\Manager($uri);
21+
22+
$bulkWrite = new MongoDB\Driver\BulkWrite;
23+
24+
for ($i = 0; $i < 5; $i++) {
25+
$bulkWrite->insert(array('_id' => $i));
26+
}
27+
28+
$writeResult = $manager->executeBulkWrite(NS, $bulkWrite);
29+
printf("Inserted: %d\n", $writeResult->getInsertedCount());
30+
31+
$query = new MongoDB\Driver\Query([], ['batchSize' => 2]);
32+
$cursor = $manager->executeQuery(NS, $query);
33+
34+
failGetMore($manager);
35+
36+
throws(function() use ($cursor) {
37+
foreach ($cursor as $i => $document) {
38+
printf("%d => {_id: %d}\n", $i, $document->_id);
39+
}
40+
}, "MongoDB\Driver\Exception\ServerException");
41+
?>
42+
===DONE===
43+
<?php destroyTemporaryMongoInstance(); ?>
44+
<?php exit(0); ?>
45+
--CLEAN--
46+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
47+
<?php destroyTemporaryMongoInstance(); ?>
48+
--EXPECT--
49+
Inserted: 5
50+
0 => {_id: 0}
51+
1 => {_id: 1}
52+
OK: Got MongoDB\Driver\Exception\ServerException
53+
===DONE===

tests/cursor/cursor-getmore-008.phpt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor command result iteration with getmore failure
3+
--SKIPIF--
4+
<?php require __DIR__ . "/" ."../utils/basic-skipif.inc"; ?>
5+
<?php
6+
/* This test spins up its own mongod instance, so only run this in the most default "standalone, no
7+
* auth" configurations. This way, we can test on multiple server versions, but not waste resources
8+
* on f.e. Travis. */
9+
?>
10+
<?php skip_if_not_live(); ?>
11+
<?php skip_if_not_standalone(); ?>
12+
<?php skip_if_server_version("<", "3.6"); ?>
13+
<?php skip_if_no_getmore_failpoint(); ?>
14+
<?php skip_if_auth(); ?>
15+
--FILE--
16+
<?php
17+
require_once __DIR__ . "/../utils/basic.inc";
18+
19+
$uri = createTemporaryMongoInstance();
20+
$manager = new MongoDB\Driver\Manager($uri);
21+
22+
$bulkWrite = new MongoDB\Driver\BulkWrite;
23+
24+
for ($i = 0; $i < 5; $i++) {
25+
$bulkWrite->insert(array('_id' => $i));
26+
}
27+
28+
$writeResult = $manager->executeBulkWrite(NS, $bulkWrite);
29+
printf("Inserted: %d\n", $writeResult->getInsertedCount());
30+
31+
$command = new MongoDB\Driver\Command([
32+
'aggregate' => COLLECTION_NAME,
33+
'pipeline' => [
34+
['$match' => new stdClass],
35+
],
36+
'cursor' => ['batchSize' => 2],
37+
]);
38+
39+
$cursor = $manager->executeCommand(DATABASE_NAME, $command);
40+
41+
failGetMore($manager);
42+
43+
throws(function() use ($cursor) {
44+
foreach ($cursor as $i => $document) {
45+
printf("%d => {_id: %d}\n", $i, $document->_id);
46+
}
47+
}, "MongoDB\Driver\Exception\ServerException");
48+
49+
?>
50+
===DONE===
51+
<?php destroyTemporaryMongoInstance(); ?>
52+
<?php exit(0); ?>
53+
--CLEAN--
54+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55+
<?php destroyTemporaryMongoInstance(); ?>
56+
--EXPECT--
57+
Inserted: 5
58+
0 => {_id: 0}
59+
1 => {_id: 1}
60+
OK: Got MongoDB\Driver\Exception\ServerException
61+
===DONE===

0 commit comments

Comments
 (0)