Example #1
0
 public function testComposeCompexLogicalQuery()
 {
     $q1 = new Query("TestObject");
     $q1->greaterThanOrEqualTo("number", 42);
     $q2 = new Query("TestObject");
     $q2->lessThan("number", 24);
     $q3 = new Query("TestObject");
     $q3->contains("title", "clojure");
     $q = Query::orQuery($q1, $q2);
     $out = $q->encode();
     $where = array('$or' => array(array("number" => array('$gte' => 42)), array("number" => array('$lt' => 24))));
     $this->assertEquals(json_encode($where), $out["where"]);
     $q = Query::andQuery($q, $q3);
     $out = $q->encode();
     $where = array('$and' => array(array('$or' => array(array("number" => array('$gte' => 42)), array("number" => array('$lt' => 24)))), array("title" => array('$regex' => "clojure"))));
     $this->assertEquals(json_encode($where), $out["where"]);
 }
Example #2
0
 public function testSaveWhenWhere()
 {
     $obj = new Object("TestObject");
     $obj->set("score", 6);
     $obj->save();
     $this->assertNotEmpty($obj->getObjectId());
     $obj->set("level", "good");
     $query = new Query("TestObject");
     $query->greaterThanOrEqualTo("score", 8);
     $option = new SaveOption();
     $option->where = $query;
     $this->setExpectedException("LeanCloud\\CloudException");
     $obj->save($option);
     $query->greaterThanOrEqualTo("score", 6);
     $option->where = $query;
     $obj->increment("score");
     $obj->save($option);
     $this->assertEquals(7, $obj->get("score"));
 }