Skip to content

Commit 963d720

Browse files
committed
PHPC-1908: Test srvMaxHosts URI option
1 parent c67ed67 commit 963d720

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): srvMaxHosts option validation
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
echo throws(function() {
9+
create_test_manager('mongodb://localhost:27017/?srvMaxHosts=1');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
echo throws(function() {
13+
create_test_manager('mongodb://localhost:27017', ['srvMaxHosts' => 1]);
14+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
15+
16+
echo throws(function() {
17+
create_test_manager('mongodb+srv://a.example.com/?srvMaxHosts=1&replicaSet=foo');
18+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
19+
20+
echo throws(function() {
21+
create_test_manager('mongodb+srv://a.example.com', ['srvMaxHosts' => 1, 'replicaSet' => 'foo']);
22+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
23+
24+
echo throws(function() {
25+
create_test_manager('mongodb+srv://a.example.com/?srvMaxHosts=1&loadBalanced=true');
26+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
27+
28+
echo throws(function() {
29+
create_test_manager('mongodb+srv://a.example.com', ['srvMaxHosts' => 1, 'loadBalanced' => true]);
30+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
31+
32+
?>
33+
===DONE===
34+
<?php exit(0); ?>
35+
--EXPECT--
36+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
37+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?srvMaxHosts=1'. srvmaxhosts must not be specified with a non-SRV URI.
38+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
39+
Failed to parse URI options: srvmaxhosts must not be specified with a non-SRV URI
40+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
41+
Failed to parse MongoDB URI: 'mongodb+srv://a.example.com/?srvMaxHosts=1&replicaSet=foo'. srvmaxhosts must not be specified with replicaset.
42+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
43+
Failed to parse URI options: srvmaxhosts must not be specified with replicaset
44+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
45+
Failed to parse MongoDB URI: 'mongodb+srv://a.example.com/?srvMaxHosts=1&loadBalanced=true'. srvmaxhosts must not be specified with loadbalanced=true.
46+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
47+
Failed to parse URI options: srvmaxhosts must not be specified with loadbalanced=true
48+
===DONE===

0 commit comments

Comments
 (0)