Files
mongo-php-driver/tests/server/server-construct-001.phpt
T
Jeremy Mikola 6fee1909b6 Fix port via parse_url() when default URI is used
The default URI is "mongodb://127.0.0.1/" and does not include a port. Since parse_url() will not yield a "port" index in that case we should fill in the default (i.e. 27017).

This is related to dd5e9e9b73.
2018-09-19 14:16:29 -04:00

33 lines
882 B
PHP

--TEST--
MongoDB\Driver\Server::__construct()
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_live(); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
/* For replica sets we need to do some extra work to get the primary */
$uri = is_replica_set(URI) ? get_primary_server(URI)->getInfo()['me'] : URI;
$parsed = parse_url($uri);
$manager = new MongoDB\Driver\Manager(URI);
$bulk = new \MongoDB\Driver\BulkWrite();
$bulk->insert(array('foo' => 'bar'));
$server = $manager->executeBulkWrite(NS, $bulk)->getServer();
$expectedHost = $parsed['host'];
$expectedPort = (integer) (isset($parsed['port']) ? $parsed['port'] : 27017);
var_dump($server->getHost() == $expectedHost);
var_dump($server->getPort() == $expectedPort);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
bool(true)
bool(true)
===DONE===