public function create() { $obj = new LeanObject("_TestObject"); $obj->set("name", "alice"); $obj->set("height", 60.0); $obj->set("weight", 4.5); $obj->set("birthdate", new \DateTime()); $obj->save(); }
/** * Remove object(s) from the field * * @param object|array $objects LeanObject(s) to remove */ public function remove($objects) { if (!is_array($objects)) { $objects = array($objects); } $op = new RelationOperation($this->key, null, $objects); $this->parent->set($this->key, $op); if (!$this->targetClassName) { $this->targetClassName = $op->getTargetClassName(); } }
public function testFind() { $obj = new LeanObject("TestObject"); $id = microtime(); $obj->set("testid", $id); $obj->save(); $query = new LeanQuery("TestObject"); $query->equalTo("testid", $id); $objects = $query->find(); $this->assertEquals(1, count($objects)); $this->assertEquals($id, $objects[0]->get("testid")); $obj->destroy(); }
public function testSaveWithNewGrandChildren() { $a = new LeanObject("TestObject"); $b = new LeanObject("TestObject"); $c = new LeanObject("TestObject"); $a->set("foo", "aar"); $b->set("foo", "bar"); $c->set("foo", "car"); $a->set("likes", array($b, "foo")); $b->set("likes", array($c, 42)); $this->setExpectedException("ErrorException", "Object without ID cannot be serialized."); $a->save(); }
public function testSetGeoPoint() { $obj = new LeanObject("TestObject"); $obj->set("location", new GeoPoint(39.9, 116.4)); $obj->save(); $obj2 = new LeanObject("TestObject", $obj->getObjectId()); $obj2->fetch(); $loc = $obj2->get("location"); $this->assertTrue($loc instanceof GeoPoint); $this->assertEquals(39.9, $loc->getLatitude()); $this->assertEquals(116.4, $loc->getLongitude()); }
public function testSaveObjectWithFile() { $obj = new LeanObject("TestObject"); $obj->set("name", "alice"); $file = LeanFile::createWithData("test.txt", "你好,中国!"); $obj->addIn("files", $file); $obj->save(); $this->assertNotEmpty($obj->getObjectId()); $this->assertNotEmpty($file->getObjectId()); $this->assertNotEmpty($file->getUrl()); $file->destroy(); $obj->destroy(); }
public function testEncodeCircularObjectAsPointer() { $a = new LeanObject("TestObject", "id001"); $b = new LeanObject("TestObject", "id002"); $c = new LeanObject("TestObject", "id003"); $a->set("name", "A"); $b->set("name", "B"); $c->set("name", "C"); $a->addIn("likes", $b); $b->addIn("likes", $c); $c->addIn("likes", $a); $jsonA = LeanClient::encode($a, "toFullJSON"); $jsonB = $jsonA["likes"][0]; $jsonC = $jsonB["likes"][0]; $this->assertEquals("Object", $jsonA["__type"]); $this->assertEquals("Object", $jsonB["__type"]); $this->assertEquals("Object", $jsonC["__type"]); $this->assertEquals("Pointer", $jsonC["likes"][0]["__type"]); }
public function testDoCloudQueryWithPvalues() { $obj = new LeanObject("TestObject"); $obj->set("name", "alice"); $obj->save(); $resp = LeanQuery::doCloudQuery("SELECT * FROM TestObject " . "WHERE name = ? LIMIT ?", array("alice", 1)); $this->assertGreaterThan(0, count($resp["results"])); $obj->destroy(); }