|
| 1 | +--TEST-- |
| 2 | +MongoDB\Driver\Server::executeCommand() options (MONGO_CMD_RAW) |
| 3 | +--SKIPIF-- |
| 4 | +<?php if (getenv("TRAVIS")) exit("skip This currently tails on Travis because it doesn't run 3.6 yet"); ?> |
| 5 | +<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> |
| 6 | +<?php NEEDS('STANDALONE'); CLEANUP(STANDALONE); ?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +require_once __DIR__ . "/../utils/basic.inc"; |
| 10 | +require_once __DIR__ . "/../utils/observer.php"; |
| 11 | + |
| 12 | +$manager = new MongoDB\Driver\Manager(STANDALONE); |
| 13 | +$server = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY)); |
| 14 | + |
| 15 | +(new CommandObserver)->observe( |
| 16 | + function() use ($server) { |
| 17 | + $command = new MongoDB\Driver\Command([ |
| 18 | + 'ping' => true, |
| 19 | + ]); |
| 20 | + |
| 21 | + try { |
| 22 | + $server->executeCommand( |
| 23 | + DATABASE_NAME, |
| 24 | + $command, |
| 25 | + [ |
| 26 | + 'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY), |
| 27 | + 'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL), |
| 28 | + 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY), |
| 29 | + ] |
| 30 | + ); |
| 31 | + } catch ( Exception $e ) { |
| 32 | + // Ignore exception that ping doesn't support writeConcern |
| 33 | + } |
| 34 | + }, |
| 35 | + function(stdClass $command) { |
| 36 | + echo "Read Preference: ", $command->{'$readPreference'}->mode, "\n"; |
| 37 | + echo "Read Concern: ", $command->readConcern->level, "\n"; |
| 38 | + echo "Write Concern: ", $command->writeConcern->w, "\n"; |
| 39 | + } |
| 40 | +); |
| 41 | + |
| 42 | +?> |
| 43 | +===DONE=== |
| 44 | +<?php exit(0); ?> |
| 45 | +--EXPECTF-- |
| 46 | +Read Preference: secondary |
| 47 | +Read Concern: local |
| 48 | +Write Concern: majority |
| 49 | +===DONE=== |
0 commit comments