Commit 9317e3c9 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-90: Client::__toString() should return connection URI

The legacy driver would return a comma-delimited list of host:port combinations; however, that would require __toString() to invoke topology discovery on new Manager instances. Returning the URI is less invasive.
parent 797ef704
......@@ -14,6 +14,7 @@ use MongoDB\Operation\ListDatabases;
class Client
{
private $manager;
private $uri;
/**
* Constructs a new Client instance.
......@@ -30,6 +31,17 @@ class Client
public function __construct($uri, array $options = [], array $driverOptions = [])
{
$this->manager = new Manager($uri, $options, $driverOptions);
$this->uri = (string) $uri;
}
/**
* Return the connection string (i.e. URI).
*
* @param string
*/
public function __toString()
{
return $this->uri;
}
/**
......
<?php
namespace MongoDB\Tests;
use MongoDB\Client;
/**
* Unit tests for the Client class.
*/
class ClientTest extends TestCase
{
public function testToString()
{
$client = new Client($this->getUri());
$this->assertSame($this->getUri(), (string) $client);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment