Permalink
Browse files

Merge pull request #78 from jstout24/use-keys-arg

Added ability to return documents without the id as the key in Cursor::toArray()
  • Loading branch information...
2 parents 4813728 + 36915a3 commit eb3a3c38167d2a74532c2db963c364aa640bc2fd @jwage jwage committed Dec 18, 2012
Showing with 20 additions and 3 deletions.
  1. +3 −3 lib/Doctrine/MongoDB/Cursor.php
  2. +17 −0 tests/Doctrine/MongoDB/Tests/CursorTest.php
@@ -362,11 +362,11 @@ public function valid()
return $this->mongoCursor->valid();
}
- public function toArray()
+ public function toArray($useKeys = true)
{
$cursor = $this;
- return $this->retry(function() use ($cursor) {
- return iterator_to_array($cursor);
+ return $this->retry(function() use ($cursor, $useKeys) {
+ return iterator_to_array($cursor, $useKeys);
}, true);
}
@@ -61,4 +61,21 @@ public function testGetSingleResultReturnsNull()
$cursor = $collection->createQueryBuilder()->getQuery()->execute();
$this->assertNull($cursor->getSingleResult());
}
+
+ public function testToArray()
+ {
+ $this->assertEquals(
+ array(
+ (string) $this->doc1['_id'] => $this->doc1,
+ (string) $this->doc2['_id'] => $this->doc2,
+ (string) $this->doc3['_id'] => $this->doc3
+ ),
+ $this->cursor->toArray()
+ );
+ }
+
+ public function testToArrayWithoutKeys()
+ {
+ $this->assertEquals(array($this->doc1, $this->doc2, $this->doc3), $this->cursor->toArray(false));
+ }
}

0 comments on commit eb3a3c3

Please sign in to comment.