/** * Abstract test * * @param mixed $value1 first value to push * @param mixed $value2 second value to push * @param array $expectedList expected list, stored in db * @param int $fieldName name of field, where values pushed: one of self::FIELD_NAME_* * @param bool $isDocumentSaved is document already stored to db before push */ private function doPushTest($value1, $value2, $expectedList, $fieldName, $isDocumentSaved) { // create document $doc = $this->collection->createDocument($this->initialDocument); // test push to saved or new document if ($isDocumentSaved) { $doc->save(); } // prepare expected value switch ($fieldName) { case self::FIELD_NAME_SCALAR: $expectedList = array_merge(array($this->initialDocument[$fieldName]), $expectedList); break; case self::FIELD_NAME_LIST: $expectedList = array_merge($this->initialDocument[$fieldName], $expectedList); break; } // push single to empty $doc->push($fieldName, $value1)->push($fieldName, $value2); // test document in identity map after push before save $this->assertEquals($expectedList, $doc->get($fieldName)); $doc->save(); // test document in identity map after push after save $this->assertEquals($expectedList, $this->collection->getDocument($doc->getId())->get($fieldName)); // test document in db $this->assertEquals($expectedList, $this->collection->getDocumentDirectly($doc->getId())->get($fieldName)); }
public function testEnableDocumentPool() { // disable document pool $this->collection->disableDocumentPool(); $this->assertFalse($this->collection->isDocumentPoolEnabled()); // create documents $document = $this->collection->createDocument(array('k' => array('f' => 'F1', 'kk' => 'A')))->save(); // read document $this->collection->getDocument($document->getId()); // check if document in pool $this->assertTrue($this->collection->isDocumentPoolEmpty()); // enable document pool $this->collection->enableDocumentPool(); $this->assertTrue($this->collection->isDocumentPoolEnabled()); // read document to pool $this->collection->getDocument($document->getId()); // check if document in pool $this->assertFalse($this->collection->isDocumentPoolEmpty()); // clear document pool $this->collection->clearDocumentPool(); $this->assertTrue($this->collection->isDocumentPoolEmpty()); // disable document pool $this->collection->disableDocumentPool(); $this->assertFalse($this->collection->isDocumentPoolEnabled()); }
public function testPullFromThreeDimensionalUsingExpressionInValue() { $this->collection->delete(); // create document $doc = $this->collection->createDocument(array('some' => array(array('sub' => array(array('a' => 1), array('b' => 2))), array('sub' => array(array('a' => 3), array('b' => 4)))))); $doc->save(); // push array to array $doc->pull('some', $this->collection->expression()->where('sub.a', 1)); $doc->save(); $this->assertEquals(array(array('sub' => array(array('a' => 3), array('b' => 4)))), $this->collection->getDocument($doc->getId())->some); }
public function testSetGeometryCollection() { $documentId = $this->collection->createDocument()->setGeometryCollection('location', array(new \GeoJson\Geometry\Point(array(30.523400000000038, 50.4501)), new \GeoJson\Geometry\LineString(array(array(30.523400000000038, 50.4501), array(24.012228, 49.831485), array(36.230376, 49.993499))), new \GeoJson\Geometry\Polygon(array(array(array(24.012228, 49.831485), array(36.230376, 49.993499), array(34.174927, 45.035993), array(24.012228, 49.831485)), array(array(34.551416, 49.588264), array(32.049226, 49.431181), array(35.139561, 47.838796), array(34.551416, 49.588264))))))->save()->getId(); $this->assertEquals(array('type' => 'GeometryCollection', 'geometries' => array(array('type' => 'Point', 'coordinates' => array(30.523400000000038, 50.4501)), array('type' => 'LineString', 'coordinates' => array(array(30.523400000000038, 50.4501), array(24.012228, 49.831485), array(36.230376, 49.993499))), array('type' => 'Polygon', 'coordinates' => array(array(array(24.012228, 49.831485), array(36.230376, 49.993499), array(34.174927, 45.035993), array(24.012228, 49.831485)), array(array(34.551416, 49.588264), array(32.049226, 49.431181), array(35.139561, 47.838796), array(34.551416, 49.588264)))))), $this->collection->getDocument($documentId)->get('location')); }