Permalink
Browse files

Add array parameter support in Query\Builder::select()

  • Loading branch information...
1 parent 5c7c61a commit c8fc2e55e2336b3695040f4f9ba2afb6ed49d58c Pierre Durand committed Mar 29, 2013
Showing with 27 additions and 2 deletions.
  1. +6 −2 lib/Doctrine/MongoDB/Query/Builder.php
  2. +21 −0 tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
@@ -317,12 +317,16 @@ public function distinct($field)
/**
* The fields to select.
*
- * @param string $fieldName
+ * @param string|array $fieldName
* @return Builder
*/
public function select($fieldName = null)
{
- $select = func_get_args();
+ if (is_array($fieldName)) {
+ $select = $fieldName;
+ } else {
+ $select = func_get_args();
+ }
foreach ($select as $fieldName) {
$this->query['select'][$fieldName] = 1;
}
@@ -526,6 +526,27 @@ public function testSelect()
$this->assertEquals($expected, $qb->debug('select'));
}
+ public function testSelectWithArray()
+ {
+ $qb = $this->getTestQueryBuilder()
+ ->select(array('foo', 'bar'));
+
+ $expected = array(
+ 'foo' => 1,
+ 'bar' => 1
+ );
+ $this->assertEquals($expected, $qb->debug('select'));
+ }
+
+ public function testSelectWithNothing()
+ {
+ $qb = $this->getTestQueryBuilder()
+ ->select();
+
+ $expected = array();
+ $this->assertEquals($expected, $qb->debug('select'));
+ }
+
public function testExclude()
{
$qb = $this->getTestQueryBuilder()

0 comments on commit c8fc2e5

Please sign in to comment.