예제 #1
0
 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();
 }
예제 #2
0
 public function update($id, $hh)
 {
     //var_dump(func_get_args());
     var_dump($id, $hh);
     $obj = new LeanObject("TestObject", '5655637160b2febec4a56259');
     // 原子增加一个数
     //$obj->increment("age", 1);
     //$obj->save();
     // 在数组字段中添加,添加唯一,删除
     // 注意: 由于API限制,不同数组操作之间必须保存,否则会报错
     //        $obj->addIn("colors", "black");
     //        $obj->save();
     $obj->addUniqueIn("colors", "krange2");
     $obj->save();
     //        $obj->removeIn("colors", "blue");
     //        $obj->save();
 }
예제 #3
0
 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();
 }
예제 #4
0
 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());
 }
예제 #5
0
 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();
 }
예제 #6
0
 /**
  * Link user with 3rd party provider
  *
  * @param string $provider  Provider name e.g. "weibo", "weixin"
  * @param array  $authToken Array of id, token, and expiration info
  * @return self
  */
 public function linkWith($provider, $authToken)
 {
     if (!is_string($provider) || empty($provider)) {
         throw new \InvalidArgumentException("Provider name can only " . "be string.");
     }
     $data = $this->get("authData");
     if (!$data) {
         $data = array();
     }
     $data[$provider] = $authToken;
     $this->set("authData", $data);
     parent::save();
     return $this;
 }
예제 #7
0
 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();
 }