예제 #1
0
 /**
  * @covers ::whereFunc
  */
 public function testWhereFunc()
 {
     $b = new WhereBuilder();
     $b->root('Author');
     $b->whereFunc(DB::avg('age'), '>', 30);
     $components = $b->build();
     $expr = new FuncExpr('age', 'AVG');
     $expr->setValue(['age']);
     $where = [['type' => 'Basic', 'table' => '_', 'cols' => [$expr], 'op' => '>', 'val' => 30, 'logic' => 'AND', 'not' => false]];
     $this->assertEquals($where, $components['where']);
 }
예제 #2
0
 protected function _processFunctionExpression(FuncExpr $expr)
 {
     list($table, $cols) = $this->_processExtendedAttribute($expr->getAttribute());
     if ($expr->getAttribute()) {
         $expr->setValue($cols);
     }
     return array($table, array($expr));
 }
예제 #3
0
 /**
  * @covers Compiler::column
  */
 public function testWhereBasicWithAFuncExpr()
 {
     $c = new BaseCompiler();
     $c->useTableAlias = true;
     $expr = new FuncExpr('articles/author/age', 'AVG');
     $expr->setValue(['age']);
     $components['where'][] = ['type' => 'Basic', 'table' => 'articles.author', 'cols' => [$expr], 'op' => '>', 'val' => 25, 'logic' => 'AND', 'not' => false];
     $expr = new FuncExpr('readers/age', 'AVG');
     $expr->setValue(['age']);
     $components['where'][] = ['type' => 'Attribute', 'lTable' => 'author', 'lCols' => ['age'], 'op' => '<', 'rTable' => 'readers', 'rCols' => [$expr], 'logic' => 'AND'];
     $expected = 'WHERE AVG(`articles.author`.`age`) > ? AND `author`.`age` < AVG(`readers`.`age`)';
     $this->assertEquals($expected, $c->compileWhere($components));
 }