@@ -163,4 +163,51 @@ public function testAllDocsWithoutIncludeDocs() {
163
163
$ this ->assertArrayHasKey ('id ' , $ docs [0 ]);
164
164
$ this ->assertArrayHasKey ('rev ' , $ docs [0 ]);
165
165
}
166
+
167
+ public function testView () {
168
+ $ view = '{"rows":[
169
+ {"key":"2012","value":34028},
170
+ {"key":"2013","value":33023},
171
+ {"key":"2014","value":21324}
172
+ ]} ' ;
173
+ $ view_response = new Response (200 , [], $ view );
174
+
175
+ $ mock = new MockHandler ([ $ this ->use_response , $ view_response ]);
176
+
177
+ $ handler = HandlerStack::create ($ mock );
178
+ $ client = new Client (['handler ' => $ handler ]);
179
+
180
+ // userland code starts
181
+ $ server = new \PHPCouchDB \Server (["client " => $ client ]);
182
+ $ database = $ server ->useDB (["name " => "egdb " ]);
183
+ $ docs = $ database ->getView (["ddoc " => "myview " , "view " => "year " , "group " => true ]);
184
+
185
+ $ this ->assertInternalType ('array ' , $ docs );
186
+ $ this ->assertEquals (3 , count ($ docs ));
187
+ $ this ->assertInternalType ('array ' , $ docs [0 ]);
188
+ }
189
+
190
+ public function testViewWithIncludeDocs () {
191
+ $ view = '{"total_rows":88375,"offset":0,"rows":[
192
+ {"id":"27881d866ac53784daebdd4fd3036986","key":"2012","value":1,"doc":{"_id":"27881d866ac53784daebdd4fd3036986","_rev":"1-d3d95288556bb4875daa17ab81b21813","Retailer country":"Italy","Order method type":"Sales visit","Retailer type":"Warehouse Store","Product line":"Camping Equipment","Product type":"Lanterns","Product":"EverGlow Single","Year":"2012","Quarter":"Q1 2012","Revenue":"15130.95","Quantity":"447","Gross margin":"0.46706056"}},
193
+ {"id":"27881d866ac53784daebdd4fd3037731","key":"2012","value":1,"doc":{"_id":"27881d866ac53784daebdd4fd3037731","_rev":"1-4ccc2e75f0328ac53b852684f303906f","Retailer country":"Italy","Order method type":"Sales visit","Retailer type":"Warehouse Store","Product line":"Personal Accessories","Product type":"Knives","Product":"Single Edge","Year":"2012","Quarter":"Q1 2012","Revenue":"37411.15","Quantity":"3115","Gross margin":"0.28726062"}},
194
+ {"id":"27881d866ac53784daebdd4fd30378ed","key":"2012","value":1,"doc":{"_id":"27881d866ac53784daebdd4fd30378ed","_rev":"1-d10f91c4f214cc96bd7bf5d38943693f","Retailer country":"Italy","Order method type":"Sales visit","Retailer type":"Warehouse Store","Product line":"Personal Accessories","Product type":"Knives","Product":"Double Edge","Year":"2012","Quarter":"Q1 2012","Revenue":"9151.38","Quantity":"567","Gross margin":"0.29182156"}}
195
+ ]} ' ;
196
+ $ view_response = new Response (200 , [], $ view );
197
+
198
+ $ mock = new MockHandler ([ $ this ->use_response , $ view_response ]);
199
+
200
+ $ handler = HandlerStack::create ($ mock );
201
+ $ client = new Client (['handler ' => $ handler ]);
202
+
203
+ // userland code starts
204
+ $ server = new \PHPCouchDB \Server (["client " => $ client ]);
205
+ $ database = $ server ->useDB (["name " => "egdb " ]);
206
+ $ docs = $ database ->getView (["ddoc " => "myview " , "view " => "year " , "reduce " => false , "limit " => 3 , "include_docs " => true ]);
207
+
208
+ $ this ->assertInternalType ('array ' , $ docs );
209
+ $ this ->assertEquals (3 , count ($ docs ));
210
+ $ this ->assertInstanceOf ('PHPCouchDB\Document ' , $ docs [0 ]);
211
+ $ this ->assertObjectHasAttribute ('Product type ' , $ docs [0 ]);
212
+ }
166
213
}
0 commit comments