File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -66,4 +66,21 @@ public function getVersion() : string
66
66
}
67
67
}
68
68
}
69
+
70
+ /**
71
+ * Get a list of databases
72
+ *
73
+ * @return array The database names
74
+ */
75
+ public function getAllDbs () {
76
+ $ response = $ this ->client ->request ("GET " , "/_all_dbs " );
77
+ if ($ response ->getStatusCode () == 200 ) {
78
+ // try to decode JSON
79
+ if ($ json_data = json_decode ($ response ->getBody (), true )) {
80
+ return $ json_data ;
81
+ } else {
82
+ throw new Exception ('JSON response not received or not understood ' );
83
+ }
84
+ }
85
+ }
69
86
}
Original file line number Diff line number Diff line change @@ -46,4 +46,18 @@ public function testGetVersion() {
46
46
$ this ->assertEquals ("1.6.0 " , $ server ->getVersion ());
47
47
48
48
}
49
+
50
+ public function testGetAllDbs () {
51
+ $ dbs = ["test " , "items " ];
52
+ $ response1 = new Response (200 , [], json_encode ($ dbs ));
53
+
54
+ $ mock = new MockHandler ([ $ response1 ]);
55
+ $ handler = HandlerStack::create ($ mock );
56
+ $ client = new Client (['handler ' => $ handler ]);
57
+
58
+ // userland code starts
59
+ $ server = new \PHPCouchDB \Server (["client " => $ client ]);
60
+ $ this ->assertEquals ($ dbs , $ server ->getAllDbs ());
61
+
62
+ }
49
63
}
You can’t perform that action at this time.
0 commit comments