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