Exemple #1
0
 public function run()
 {
     $this->requireDataset('Heroes');
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('superhero')->eq('Iron Man'))->count(), 1.0);
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(function ($x) {
         return $x('superhero')->ne('Iron Man');
     })->count(), 2.0);
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'))->count(), 0.0);
     $caught = false;
     try {
         $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\error())->count(), 0.0);
     } catch (r\RqlServerError $e) {
         $caught = true;
     }
     if (!$caught) {
         echo "Filter with default rrror() did not throw.";
     }
     $caught = false;
     try {
         $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\error('msg'))->count(), 0.0);
     } catch (r\RqlServerError $e) {
         $caught = true;
     }
     if (!$caught) {
         echo "Filter with default rrror() did not throw.";
     }
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), true)->count(), 3.0);
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->filter(r\row('foo')->eq('naaa'), r\expr('true'))->count(), 3.0);
 }
Exemple #2
0
 public function run()
 {
     $this->requireDataset('Control');
     $this->requireDataset('Heroes');
     $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) {
         return $x->mul($y->add($z));
     }), 5.0);
     $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true');
     $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false');
     $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) {
         return r\db('Control')->table('t1')->insert(array('x' => $x));
     })->attr('inserted'), 3.0);
     $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3));
     $errorCaught = false;
     try {
         r\error('ERRRRRR')->run($this->conn);
     } catch (r\RqlUserError $e) {
         $errorCaught = true;
     }
     if (!$errorCaught) {
         echo "rrror() did not throw an error.\n";
     }
     // Js is also tested separately in JsTest
     $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2');
     $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0);
     $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5');
     $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER');
     $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING');
     $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL');
     $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY');
     $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT');
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->info(), array('type' => "TABLE", 'primary_key' => 'superhero', 'name' => 'marvel', 'indexes' => array(), 'db' => array('type' => 'DB', 'name' => 'Heroes')));
     $this->datasets['Control']->reset();
 }
Exemple #3
0
 public function run()
 {
     $this->requireDataset('Control');
     $this->requireDataset('Heroes');
     $this->checkQueryResult(r\rDo(array(1, 2, 3), function ($x, $y, $z) {
         return $x->mul($y->add($z));
     }), 5.0);
     $this->checkQueryResult(r\branch(r\expr(true), r\expr('true'), r\expr('false')), 'true');
     $this->checkQueryResult(r\branch(r\expr(false), r\expr('true'), r\expr('false')), 'false');
     $this->checkQueryResult(r\expr(array(1, 2, 3))->rForeach(function ($x) {
         return r\db('Control')->table('t1')->insert(array('x' => $x));
     })->getField('inserted'), 3.0);
     $this->checkQueryResult(r\db('Control')->table('t1')->map(r\row('x')), array(1, 2, 3));
     $errorCaught = false;
     try {
         r\error('ERRRRRR')->run($this->conn);
     } catch (r\RqlServerError $e) {
         $errorCaught = true;
     }
     if (!$errorCaught) {
         echo "rrror() did not throw an error.\n";
     }
     // Js is also tested separately in JsTest
     $this->checkQueryResult(r\js("'str1' + 'str2'"), 'str1str2');
     $this->checkQueryResult(r\expr('5.0')->coerceTo('number'), 5.0);
     $this->checkQueryResult(r\expr(5.0)->coerceTo('string'), '5');
     $this->checkQueryResult(r\expr(5.0)->typeOf(), 'NUMBER');
     $this->checkQueryResult(r\expr('foo')->typeOf(), 'STRING');
     $this->checkQueryResult(r\expr(null)->typeOf(), 'NULL');
     $this->checkQueryResult(r\expr(array(1, 2, 3))->typeOf(), 'ARRAY');
     $this->checkQueryResult(r\expr(array('x' => 1))->typeOf(), 'OBJECT');
     $this->checkQueryResult(r\db('Heroes')->table('marvel')->info()->pluck(array('type', 'name')), array('type' => "TABLE", 'name' => 'marvel'));
     $this->checkQueryResult(r\expr(array('a' => 4))->getField('a')->rDefault(5), 4.0);
     $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(5), 5.0);
     $this->checkQueryResult(r\expr(array('a' => 4))->getField('b')->rDefault(function ($e) {
         return r\expr(5);
     }), 5.0);
     $this->checkQueryResult(r\range()->limit(3), array(0, 1, 2));
     $this->checkQueryResult(r\range(3), array(0, 1, 2));
     $this->checkQueryResult(r\range(1, 3), array(1, 2));
     $this->checkQueryResult(r\expr("123")->toJsonString(), "\"123\"");
     $this->datasets['Control']->reset();
 }
Exemple #4
0
 public function testError()
 {
     $this->setExpectedException('\\r\\Exceptions\\RqlServerError', 'Runtime error: ERRRRRR');
     \r\error('ERRRRRR')->run($this->conn);
 }
Exemple #5
0
 public function testFilterErrorMsg()
 {
     $this->setExpectedException('\\r\\Exceptions\\RqlServerError', 'msg');
     $res = $this->db()->table('marvel')->filter(\r\row('foo')->eq('naaa'), \r\error('msg'))->count()->run($this->conn);
 }