|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Command comment applies to getMore |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 5 | +<?php skip_if_not_live(); ?> |
| 6 | +<?php skip_if_server_version('<', '4.4'); ?> |
| 7 | +<?php skip_if_not_clean(); ?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 11 | + |
| 12 | +class Test implements MongoDB\Driver\Monitoring\CommandSubscriber |
| 13 | +{ |
| 14 | + public function executeCommand() |
| 15 | + { |
| 16 | + MongoDB\Driver\Monitoring\addSubscriber($this); |
| 17 | + |
| 18 | + $manager = create_test_manager(); |
| 19 | + |
| 20 | + $bulkWrite = new MongoDB\Driver\BulkWrite; |
| 21 | + |
| 22 | + for ($i = 0; $i < 5; $i++) { |
| 23 | + $bulkWrite->insert(['_id' => $i]); |
| 24 | + } |
| 25 | + |
| 26 | + $writeResult = $manager->executeBulkWrite(NS, $bulkWrite); |
| 27 | + printf("Inserted: %d\n", $writeResult->getInsertedCount()); |
| 28 | + |
| 29 | + $command = new MongoDB\Driver\Command([ |
| 30 | + 'aggregate' => COLLECTION_NAME, |
| 31 | + 'pipeline' => [['$match' => new stdClass]], |
| 32 | + 'comment' => ['foo' => 1], |
| 33 | + 'cursor' => ['batchSize' => 2] |
| 34 | + ]); |
| 35 | + $cursor = $manager->executeCommand(DATABASE_NAME, $command); |
| 36 | + |
| 37 | + $cursor->toArray(); |
| 38 | + |
| 39 | + MongoDB\Driver\Monitoring\removeSubscriber($this); |
| 40 | + } |
| 41 | + |
| 42 | + public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event) |
| 43 | + { |
| 44 | + $command = $event->getCommand(); |
| 45 | + |
| 46 | + if ($event->getCommandName() === 'aggregate' || $event->getCommandName() === 'getMore') { |
| 47 | + printf("%s command includes comment: %s\n", $event->getCommandName(), json_encode($command->comment)); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) |
| 52 | + { |
| 53 | + } |
| 54 | + |
| 55 | + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) |
| 56 | + { |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +(new Test)->executeCommand(); |
| 61 | + |
| 62 | +?> |
| 63 | +===DONE=== |
| 64 | +<?php exit(0); ?> |
| 65 | +--EXPECT-- |
| 66 | +Inserted: 5 |
| 67 | +aggregate command includes comment: {"foo":1} |
| 68 | +getMore command includes comment: {"foo":1} |
| 69 | +getMore command includes comment: {"foo":1} |
| 70 | +===DONE=== |
0 commit comments