File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -186,4 +186,18 @@ public function current()
186186
187187 return $ this ->_result [$ this ->_position ];
188188 }
189+
190+ /**
191+ * Returns the values from a single field this collection, identified by the given $key.
192+ *
193+ * @param string $key The name of the field for which the values will be returned.
194+ *
195+ * @return iterable
196+ */
197+ public function column ($ key )
198+ {
199+ foreach ($ this as $ item ) {
200+ yield Util \Arrays::get ($ item , $ key );
201+ }
202+ }
189203}
Original file line number Diff line number Diff line change @@ -242,6 +242,23 @@ public function oneItemCollection()
242242 $ this ->assertSame (['id ' => '0 ' , 'key ' => 0 ], $ item );
243243 }
244244 }
245+
246+ /**
247+ * Verifies basic behavior of column().
248+ *
249+ * @test
250+ * @covers ::column
251+ */
252+ public function column ()
253+ {
254+ $ authentication = Authentication::createClientCredentials ('not under test ' , 'not under test ' );
255+ $ client = new Client (new CollectionAdapter (), $ authentication , 'not under test ' );
256+ $ collection = new Collection ($ client , 'basic ' , ['limit ' => 3 ]);
257+ $ this ->assertSame (
258+ [0 , 1 , 2 , 3 , 4 ],
259+ iterator_to_array ($ collection ->column ('key ' ))
260+ );
261+ }
245262}
246263
247264final class CollectionAdapter implements Adapter
You can’t perform that action at this time.
0 commit comments