Просмотр исходного кода

Add test to show keys can have "0" as a string

Greg Dickson 7 лет назад
Родитель
Сommit
8a35d41c73
1 измененных файлов с 14 добавлено и 0 удалено
  1. 14 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

+ 14 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

@@ -130,6 +130,20 @@ class MongoCollectionTest extends TestCase
         $this->assertSame(1, $this->getCollection()->count(['foo']));
     }
 
+    public function testInsertWithAlphaNumbericKey()
+    {
+        /**
+         * Force the array to store the key as a string "0".
+         * Initialising like ['0' => 'foo'] casts the string to an int.
+         */
+        $document = new \stdClass();
+        $document->{'0'} = 'foo';
+        $document = (array) $document;
+
+        $this->getCollection()->insert($document);
+        $this->assertSame(1, $this->getCollection()->count(['0' => 'foo']));
+    }
+
     public function testInsertDuplicate()
     {
         $collection = $this->getCollection();