@@ -259,6 +259,93 @@ public function column()
259259 iterator_to_array ($ collection ->column ('key ' ))
260260 );
261261 }
262+
263+ /**
264+ * Verifies basic behavior of select().
265+ *
266+ * @test
267+ * @covers ::select
268+ *
269+ * @return void
270+ */
271+ public function select ()
272+ {
273+ $ authentication = Authentication::createClientCredentials ('not under test ' , 'not under test ' );
274+ $ client = new Client (new CollectionAdapter (), $ authentication , 'not under test ' );
275+ $ collection = new Collection ($ client , 'basic ' , ['limit ' => 3 ]);
276+ $ this ->assertSame (
277+ [
278+ ['key ' => 0 ],
279+ ['key ' => 1 ],
280+ ['key ' => 2 ],
281+ ['key ' => 3 ],
282+ ['key ' => 4 ],
283+ ],
284+ iterator_to_array ($ collection ->select (['key ' ]))
285+ );
286+ }
287+
288+ /**
289+ * Verifies behavior of select() with multiple keys.
290+ *
291+ * @test
292+ * @covers ::select
293+ *
294+ * @return void
295+ */
296+ public function selectMultipleKeys ()
297+ {
298+ $ adapter = new CollectionAdapter ();
299+ $ adapter ->results = [
300+ ['id ' => 1 , 'name ' => 'Sam ' , 'score ' => 99 ],
301+ ['id ' => 2 , 'name ' => 'Bob ' , 'score ' => 83 ],
302+ ['id ' => 3 , 'name ' => 'Jon ' , 'score ' => 75 ],
303+ ['id ' => 4 , 'name ' => 'Ted ' , 'score ' => 64 ],
304+ ];
305+ $ authentication = Authentication::createClientCredentials ('not under test ' , 'not under test ' );
306+ $ client = new Client ($ adapter , $ authentication , 'not under test ' );
307+ $ collection = new Collection ($ client , 'basic ' , ['limit ' => 3 ]);
308+ $ this ->assertSame (
309+ [
310+ ['id ' => 1 , 'score ' => 99 ],
311+ ['id ' => 2 , 'score ' => 83 ],
312+ ['id ' => 3 , 'score ' => 75 ],
313+ ['id ' => 4 , 'score ' => 64 ],
314+ ],
315+ iterator_to_array ($ collection ->select (['id ' , 'score ' ]))
316+ );
317+ }
318+
319+ /**
320+ * Verifies behavior of select() when results have missing keys.
321+ *
322+ * @test
323+ * @covers ::select
324+ *
325+ * @return void
326+ */
327+ public function selectMissingKeys ()
328+ {
329+ $ adapter = new CollectionAdapter ();
330+ $ adapter ->results = [
331+ ['id ' => 1 , 'name ' => 'Sam ' , 'score ' => 99 ],
332+ ['id ' => 2 , 'name ' => 'Bob ' ],
333+ ['id ' => 3 , 'name ' => 'Jon ' , 'score ' => 75 ],
334+ ['id ' => 4 , 'score ' => 64 ],
335+ ];
336+ $ authentication = Authentication::createClientCredentials ('not under test ' , 'not under test ' );
337+ $ client = new Client ($ adapter , $ authentication , 'not under test ' );
338+ $ collection = new Collection ($ client , 'basic ' , ['limit ' => 3 ]);
339+ $ this ->assertSame (
340+ [
341+ ['name ' => 'Sam ' , 'score ' => 99 ],
342+ ['name ' => 'Bob ' , 'score ' => null ],
343+ ['name ' => 'Jon ' , 'score ' => 75 ],
344+ ['name ' => null , 'score ' => 64 ],
345+ ],
346+ iterator_to_array ($ collection ->select (['name ' , 'score ' ]))
347+ );
348+ }
262349}
263350
264351final class CollectionAdapter implements Adapter
0 commit comments