Skip to content

Commit be188e3

Browse files
committed
Merge pull request #50
2 parents 797ef70 + 3a26fe2 commit be188e3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Client.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class Client
1515
{
1616
private $manager;
17+
private $uri;
1718

1819
/**
1920
* Constructs a new Client instance.
@@ -27,9 +28,20 @@ class Client
2728
* @param array $options Additional connection string options
2829
* @param array $driverOptions Driver-specific options
2930
*/
30-
public function __construct($uri, array $options = [], array $driverOptions = [])
31+
public function __construct($uri = 'mongodb://localhost:27017', array $options = [], array $driverOptions = [])
3132
{
3233
$this->manager = new Manager($uri, $options, $driverOptions);
34+
$this->uri = (string) $uri;
35+
}
36+
37+
/**
38+
* Return the connection string (i.e. URI).
39+
*
40+
* @param string
41+
*/
42+
public function __toString()
43+
{
44+
return $this->uri;
3345
}
3446

3547
/**

tests/ClientTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace MongoDB\Tests;
4+
5+
use MongoDB\Client;
6+
7+
/**
8+
* Unit tests for the Client class.
9+
*/
10+
class ClientTest extends TestCase
11+
{
12+
public function testConstructorDefaultUri()
13+
{
14+
$client = new Client();
15+
16+
$this->assertEquals('mongodb://localhost:27017', (string) $client);
17+
}
18+
19+
public function testToString()
20+
{
21+
$client = new Client($this->getUri());
22+
23+
$this->assertSame($this->getUri(), (string) $client);
24+
}
25+
}

0 commit comments

Comments
 (0)