Skip to content

Commit f10d602

Browse files
committed
Merge branch 'v1.8'
2 parents 89b29ed + ace3850 commit f10d602

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): directConnection option
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_replica_set(); ?>
6+
<?php skip_if_not_enough_data_nodes(2); ?>
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$manager = new \MongoDB\Driver\Manager(URI, ['directConnection' => false]);
13+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primaryPreferred'));
14+
15+
printf("Topology has multiple nodes when directConnection=false: %s\n", count($manager->getServers()) > 1 ? 'true' : 'false');
16+
17+
$uri = sprintf('mongodb://%s:%d', $server->getHost(), $server->getPort());
18+
$manager2 = new \MongoDB\Driver\Manager($uri, ['directConnection' => true]);
19+
$server2 = $manager2->selectServer(new \MongoDB\Driver\ReadPreference('primaryPreferred'));
20+
21+
printf("Topology has single node when directConnection=true: %s\n", count($manager2->getServers()) == 1 ? 'true' : 'false');
22+
printf("Single node in topology matches seed in URI: %s\n", ($server2 == $server) ? 'true' : 'false');
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
Topology has multiple nodes when directConnection=false: true
29+
Topology has single node when directConnection=true: true
30+
Single node in topology matches seed in URI: true
31+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): directConnection=true conflicts with multiple seeds
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
$manager = new \MongoDB\Driver\Manager('mongodb://a.example.com,b.example.com/?directConnection=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
17+
Failed to parse MongoDB URI: 'mongodb://a.example.com,b.example.com/?directConnection=true'. Multiple seeds not allowed with directConnection option.
18+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): directConnection=true conflicts with SRV
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
$manager = new \MongoDB\Driver\Manager('mongodb+srv://a.example.com/?directConnection=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
17+
Failed to parse MongoDB URI: 'mongodb+srv://a.example.com/?directConnection=true'. SRV URI not allowed with directConnection option.
18+
===DONE===

0 commit comments

Comments
 (0)