File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1414class 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 /**
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments