Beispiel #1
0
 public function getResult($query)
 {
     if (!$query instanceof ParsedQuery) {
         $query = new ParsedQuery($query);
     }
     $result = isset($this->queries[$query->getHash()]) ? $this->queries[$query->getHash()] : null;
     if ($result instanceof Result) {
         return $result;
     } else {
         throw new Exception("Attempting an operation on an un-mocked query is not allowed");
     }
 }
 public function getResult($query)
 {
     if (!$query instanceof ParsedQuery) {
         $query = new ParsedQuery($query);
     }
     $parsedQuery = $query->getParsedQuery();
     if (isset($parsedQuery['INSERT']) || isset($parsedQuery['UPDATE'])) {
         return new Result();
     }
     if (!isset($this->queries[$query->getHash()])) {
         throw new \Exception('Mock is not specified for query: ' . $query->getRawQuery());
     }
     $result = $this->queries[$query->getHash()];
     if ($result instanceof Result) {
         return $result;
     } else {
         throw new Exception("Attempting an operation on an un-mocked query is not allowed");
     }
 }
 function test_to_string()
 {
     $tests = array('' => '', 'a=x' => '{a=x}', '{a=x}{b=y}' => '{a=x}AND{b=y}', '{a=x}{b=y}OR{c=z}' => '({a=x}AND{b=y}OR{c=z})', '{a=x}({b=y}OR{c=z})' => '{a=x}AND({b=y}OR{c=z})');
     foreach ($tests as $test => $expected) {
         $tree = $this->parser->parse($test);
         $this->assertEqual($expected, $tree->to_string());
     }
     // special case, null
     $tree = new ParsedQuery(NULL);
     $this->assertEqual('', $tree->to_string());
 }