/** * Test the usage of FuncExpression in conditions. * * It validates the following syntax: * * `$builder->where('DB::avg('articles/author/age'), '>', 25);` * `$builder->whereAttr('thisOne', '<', DB::max('this/otherOne'));` * * @covers ::where * @covers ::whereAttr */ public function testWhereFuncExpression() { $b = new WhereBuilder(); $b->root('Blog'); $b->where(DB::avg('articles/author/age'), '>', 25); $components = $b->getComponents(); $expr = new FuncExpr('articles/author/age', 'AVG'); $expr->setValue(['age']); $where = [['type' => 'Basic', 'table' => 'articles.author', 'cols' => [$expr], 'op' => '>', 'val' => 25, 'logic' => 'AND', 'not' => false]]; $this->assertEquals($where, $components['where']); // - - - $b = new WhereBuilder(); $b->root('Article'); $b->whereAttr('author/age', '<', DB::avg('readers/age')); $components = $b->getComponents(); $expr = new FuncExpr('readers/age', 'AVG'); $expr->setValue(['age']); $where = [['type' => 'Attribute', 'lTable' => 'author', 'lCols' => ['age'], 'op' => '<', 'rTable' => 'readers', 'rCols' => [$expr], 'logic' => 'AND']]; $this->assertEquals($where, $components['where']); }