Skip to content

Commit da45c74

Browse files
committed
Merge branch 'v1.5'
2 parents 760402a + 5c4b608 commit da45c74

File tree

7 files changed

+228
-69
lines changed

7 files changed

+228
-69
lines changed

tests/cursor/cursor-getmore-005.phpt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
--TEST--
22
MongoDB\Driver\Cursor query result iteration with getmore failure
3-
--XFAIL--
4-
START() tests must be reimplemented (PHPC-1179)
53
--SKIPIF--
64
<?php require __DIR__ . "/" ."../utils/basic-skipif.inc"; ?>
7-
<?php START("THROWAWAY", ["version" => "30-release"]); CLEANUP(THROWAWAY); ?>
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(); ?>
815
--FILE--
916
<?php
1017
require_once __DIR__ . "/../utils/basic.inc";
1118

12-
$manager = new MongoDB\Driver\Manager(THROWAWAY);
19+
$uri = createTemporaryMongoInstance();
20+
$manager = new MongoDB\Driver\Manager($uri);
1321

1422
$bulkWrite = new MongoDB\Driver\BulkWrite;
1523

@@ -30,14 +38,13 @@ throws(function() use ($cursor) {
3038
printf("%d => {_id: %d}\n", $i, $document->_id);
3139
}
3240
}, "MongoDB\Driver\Exception\ConnectionException");
33-
3441
?>
3542
===DONE===
36-
<?php DELETE("THROWAWAY"); ?>
43+
<?php destroyTemporaryMongoInstance(); ?>
3744
<?php exit(0); ?>
3845
--CLEAN--
3946
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
40-
<?php DELETE("THROWAWAY"); ?>
47+
<?php destroyTemporaryMongoInstance(); ?>
4148
--EXPECT--
4249
Inserted: 5
4350
0 => {_id: 0}

tests/cursor/cursor-getmore-006.phpt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
--TEST--
22
MongoDB\Driver\Cursor command result iteration with getmore failure
3-
--XFAIL--
4-
START() tests must be reimplemented (PHPC-1179)
53
--SKIPIF--
64
<?php require __DIR__ . "/" ."../utils/basic-skipif.inc"; ?>
7-
<?php START("THROWAWAY", ["version" => "30-release"]); CLEANUP(THROWAWAY); ?>
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(); ?>
815
--FILE--
916
<?php
1017
require_once __DIR__ . "/../utils/basic.inc";
1118

12-
$manager = new MongoDB\Driver\Manager(THROWAWAY);
19+
$uri = createTemporaryMongoInstance();
20+
$manager = new MongoDB\Driver\Manager($uri);
1321

1422
$bulkWrite = new MongoDB\Driver\BulkWrite;
1523

@@ -40,11 +48,11 @@ throws(function() use ($cursor) {
4048

4149
?>
4250
===DONE===
43-
<?php DELETE("THROWAWAY"); ?>
51+
<?php destroyTemporaryMongoInstance(); ?>
4452
<?php exit(0); ?>
4553
--CLEAN--
4654
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
47-
<?php DELETE("THROWAWAY"); ?>
55+
<?php destroyTemporaryMongoInstance(); ?>
4856
--EXPECT--
4957
Inserted: 5
5058
0 => {_id: 0}

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===

tests/utils/basic.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once __DIR__ . "/" . "tools.php";
44

55
define('URI', getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/');
6+
define('MONGO_ORCHESTRATION_URI', getenv('MONGO_ORCHESTRATION_URI') ?: 'http://localhost:8889/v1');
67
define('DATABASE_NAME', getenv('MONGODB_DATABASE') ?: 'phongo');
78
define('COLLECTION_NAME', makeCollectionNameFromFilename($_SERVER['SCRIPT_FILENAME']));
89
define('NS', DATABASE_NAME . '.' . COLLECTION_NAME);

tests/utils/skipif.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,15 @@ function skip_if_not_clean($databaseName = DATABASE_NAME, $collectionName = COLL
306306
exit("skip Could not drop '$databaseName.$collectionName': " . $e->getMessage());
307307
}
308308
}
309+
310+
function skip_if_no_getmore_failpoint()
311+
{
312+
$serverVersion = get_server_version(URI);
313+
314+
if (
315+
version_compare($serverVersion, '3.2', '>=') &&
316+
version_compare($serverVersion, '4.0', '<')
317+
) {
318+
exit("skip Server version '$serverVersion' does not support a getMore failpoint'");
319+
}
320+
}

0 commit comments

Comments
 (0)