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 14
14
class Client
15
15
{
16
16
private $ manager ;
17
+ private $ uri ;
17
18
18
19
/**
19
20
* Constructs a new Client instance.
@@ -27,9 +28,20 @@ class Client
27
28
* @param array $options Additional connection string options
28
29
* @param array $driverOptions Driver-specific options
29
30
*/
30
- public function __construct ($ uri , array $ options = [], array $ driverOptions = [])
31
+ public function __construct ($ uri = ' mongodb://localhost:27017 ' , array $ options = [], array $ driverOptions = [])
31
32
{
32
33
$ 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 ;
33
45
}
34
46
35
47
/**
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