|
|
@@ -478,6 +478,40 @@ class MongoCollectionTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @dataProvider dataFindWithProjectionAndNumericKeys
|
|
|
+ */
|
|
|
+ public function testFindWithProjectionAndNumericKeys($data, $projection, $expected)
|
|
|
+ {
|
|
|
+ $this->getCollection()->insert($data);
|
|
|
+
|
|
|
+ $document = $this->getCollection()->findOne([], $projection);
|
|
|
+ unset($document['_id']);
|
|
|
+ $this->assertSame($expected, $document);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function dataFindWithProjectionAndNumericKeys()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'sequentialIntegersStartingWithOne' => [
|
|
|
+ ['0' => 'foo', '1' => 'bar', '2' => 'foobar'],
|
|
|
+ [1 => true, 2 => true],
|
|
|
+ ['1' => 'bar', '2' => 'foobar'],
|
|
|
+ ],
|
|
|
+ 'nonSequentialIntegers' => [
|
|
|
+ ['0' => 'foo', '1' => 'bar', '2' => 'foobar', '3' => 'barfoo'],
|
|
|
+ [1 => true, 3 => true],
|
|
|
+ ['1' => 'bar', '3' => 'barfoo'],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testFindWithProjectionAndSequentialNumericKeys()
|
|
|
+ {
|
|
|
+ $this->setExpectedException(\MongoException::class, 'field names must be strings', 8);
|
|
|
+ $this->getCollection()->findOne([], [true, false]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @dataProvider dataFindWithProjectionExcludeId
|
|
|
*/
|
|
|
public function testFindWithProjectionExcludeId($projection)
|