|
|
@@ -429,6 +429,35 @@ class MongoCollectionTest extends TestCase
|
|
|
$this->assertInstanceOf('MongoCursor', $collection->find());
|
|
|
}
|
|
|
|
|
|
+ public function testFindWithProjection()
|
|
|
+ {
|
|
|
+ $document = ['foo' => 'foo', 'bar' => 'bar'];
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+ unset($document['_id']);
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+
|
|
|
+ $cursor = $this->getCollection()->find(['foo' => 'foo'], ['bar' => true]);
|
|
|
+ foreach ($cursor as $document) {
|
|
|
+ $this->assertCount(2, $document);
|
|
|
+ $this->assertArraySubset(['bar' => 'bar'], $document);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testFindWithLegacyProjection()
|
|
|
+ {
|
|
|
+ $document = ['foo' => 'foo', 'bar' => 'bar'];
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+ unset($document['_id']);
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+
|
|
|
+ $cursor = $this->getCollection()->find(['foo' => 'foo'], ['bar']);
|
|
|
+ foreach ($cursor as $document) {
|
|
|
+ $this->assertCount(2, $document);
|
|
|
+ $this->assertArraySubset(['bar' => 'bar'], $document);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public function testCount()
|
|
|
{
|
|
|
$this->prepareData();
|
|
|
@@ -510,6 +539,26 @@ class MongoCollectionTest extends TestCase
|
|
|
$this->assertSame(['foo' => 'foo'], $document);
|
|
|
}
|
|
|
|
|
|
+ public function testFindOneWithProjection()
|
|
|
+ {
|
|
|
+ $document = ['foo' => 'foo', 'bar' => 'bar'];
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+
|
|
|
+ $document = $this->getCollection()->findOne(['foo' => 'foo'], ['bar' => true]);
|
|
|
+ $this->assertCount(2, $document);
|
|
|
+ $this->assertArraySubset(['bar' => 'bar'], $document);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testFindOneWithLegacyProjection()
|
|
|
+ {
|
|
|
+ $document = ['foo' => 'foo', 'bar' => 'bar'];
|
|
|
+ $this->getCollection()->insert($document);
|
|
|
+
|
|
|
+ $document = $this->getCollection()->findOne(['foo' => 'foo'], ['bar']);
|
|
|
+ $this->assertCount(2, $document);
|
|
|
+ $this->assertArraySubset(['bar' => 'bar'], $document);
|
|
|
+ }
|
|
|
+
|
|
|
public function testFindOneNotFound()
|
|
|
{
|
|
|
$document = $this->getCollection()->findOne(['foo' => 'foo'], ['_id' => false]);
|