|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Cursor debug output for command cursor includes explicit session |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/" ."../utils/basic-skipif.inc"; ?> |
| 5 | +<?php NEEDS_CRYPTO(); ?> |
| 6 | +<?php NEEDS('STANDALONE'); ?> |
| 7 | +<?php NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?> |
| 8 | +<?php CLEANUP(STANDALONE); ?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 12 | + |
| 13 | +$manager = new MongoDB\Driver\Manager(STANDALONE); |
| 14 | + |
| 15 | +$bulk = new MongoDB\Driver\BulkWrite; |
| 16 | +$bulk->insert(['_id' => 1]); |
| 17 | +$bulk->insert(['_id' => 2]); |
| 18 | +$bulk->insert(['_id' => 3]); |
| 19 | +$manager->executeBulkWrite(NS, $bulk); |
| 20 | + |
| 21 | +$command = new MongoDB\Driver\Command([ |
| 22 | + 'aggregate' => COLLECTION_NAME, |
| 23 | + 'pipeline' => [['$match' => new stdClass]], |
| 24 | + 'cursor' => ['batchSize' => 2], |
| 25 | +]); |
| 26 | +$session = $manager->startSession(); |
| 27 | + |
| 28 | +$cursor = $manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]); |
| 29 | + |
| 30 | +$iterator = new IteratorIterator($cursor); |
| 31 | +$iterator->rewind(); |
| 32 | +$iterator->next(); |
| 33 | + |
| 34 | +printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); |
| 35 | +var_dump($cursor); |
| 36 | + |
| 37 | +$iterator->next(); |
| 38 | + |
| 39 | +/* Per PHPC-1161, the Cursor will free a reference to the Session as soon as it |
| 40 | + * is exhausted. While this is primarily done to ensure implicit sessions for |
| 41 | + * command cursors are returned to the pool ASAP, it also applies to explicit |
| 42 | + * sessions. */ |
| 43 | +printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); |
| 44 | +var_dump($cursor); |
| 45 | + |
| 46 | +?> |
| 47 | +===DONE=== |
| 48 | +<?php exit(0); ?> |
| 49 | +--EXPECTF-- |
| 50 | +Cursor ID is zero: no |
| 51 | +object(MongoDB\Driver\Cursor)#%d (%d) { |
| 52 | + %a |
| 53 | + ["session"]=> |
| 54 | + object(MongoDB\Driver\Session)#%d (%d) { |
| 55 | + %a |
| 56 | + } |
| 57 | + %a |
| 58 | +} |
| 59 | + |
| 60 | +Cursor ID is zero: yes |
| 61 | +object(MongoDB\Driver\Cursor)#%d (%d) { |
| 62 | + %a |
| 63 | + ["session"]=> |
| 64 | + NULL |
| 65 | + %a |
| 66 | +} |
| 67 | +===DONE=== |
0 commit comments