Skip to content

Commit 226b3a2

Browse files
committed
PHPC-1876: Session with snapshot=true requires MongoDB 5.0+
1 parent 962a9d2 commit 226b3a2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/session/session-005.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
MongoDB\Driver\Session spec test: snapshot option requires MongoDB 5.0+
3+
--DESCRIPTION--
4+
PHPC-1876: Raise client error for snapshot sessions on <5.0 servers
5+
--SKIPIF--
6+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
7+
<?php skip_if_not_libmongoc_crypto(); ?>
8+
<?php skip_if_not_live(); ?>
9+
<?php skip_if_server_version('<', '3.6'); ?>
10+
<?php skip_if_server_version('>=', '5.0'); ?>
11+
--FILE--
12+
<?php
13+
require_once __DIR__ . "/../utils/basic.inc";
14+
15+
$manager = create_test_manager();
16+
$session = $manager->startSession(['snapshot' => true]);
17+
18+
/* Note: executeBulkWrite() always throws a BulkWriteException. Any previous
19+
* exception's message will be included in the BulkWriteException message. */
20+
echo "\nTesting executeBulkWrite()\n";
21+
echo throws(function() use ($manager, $session) {
22+
$bulk = new MongoDB\Driver\BulkWrite();
23+
$bulk->insert(['x' => 1]);
24+
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
25+
}, MongoDB\Driver\Exception\BulkWriteException::class), "\n";
26+
27+
echo "\nTesting executeCommand()\n";
28+
echo throws(function() use ($manager, $session) {
29+
$command = new MongoDB\Driver\Command(['ping' => 1]);
30+
$manager->executeCommand(DATABASE_NAME, $command, ['session' => $session]);
31+
}, MongoDB\Driver\Exception\RuntimeException::class), "\n";
32+
33+
echo "\nTesting executeQuery()\n";
34+
echo throws(function() use ($manager, $session) {
35+
$query = new MongoDB\Driver\Query([]);
36+
$manager->executeQuery(NS, $query, ['session' => $session]);
37+
}, MongoDB\Driver\Exception\RuntimeException::class), "\n";
38+
39+
?>
40+
===DONE===
41+
<?php exit(0); ?>
42+
--EXPECT--
43+
Testing executeBulkWrite()
44+
OK: Got MongoDB\Driver\Exception\BulkWriteException
45+
Bulk write failed due to previous MongoDB\Driver\Exception\RuntimeException: Snapshot reads require MongoDB 5.0 or later
46+
47+
Testing executeCommand()
48+
OK: Got MongoDB\Driver\Exception\RuntimeException
49+
Snapshot reads require MongoDB 5.0 or later
50+
51+
Testing executeQuery()
52+
OK: Got MongoDB\Driver\Exception\RuntimeException
53+
Snapshot reads require MongoDB 5.0 or later
54+
===DONE===

0 commit comments

Comments
 (0)