public function testAssemble() { $selector = CountSelectExpression::create(); $this->assertEquals('COUNT(*)', QueryAssembler::stringify($selector)); $selector->setField(AllSelectExpression::create()); $this->assertEquals('COUNT(*)', QueryAssembler::stringify($selector)); $selector->setField('fieldname'); $this->assertEquals('COUNT(fieldname)', QueryAssembler::stringify($selector)); $selector->setAlias('cnt'); $this->assertEquals('COUNT(fieldname) AS cnt', QueryAssembler::stringify($selector)); $selector->setDistinct(); $this->assertEquals('COUNT(DISTINCT fieldname) AS cnt', QueryAssembler::stringify($selector)); }
public function testSubquery() { $subQuery = SubQuerySelectExpression::create(QueryBuilder::select('myField')->from('myTable')->limitWithOffset(5, 10), '_'); $stmt = QueryBuilder::select(CountSelectExpression::create())->from($subQuery); $this->assertEquals('SELECT COUNT(*) FROM (SELECT myField FROM myTable LIMIT 5,10) AS _', QueryAssembler::stringify($stmt)); }