/** * @dataProvider getQueryStringProvider */ public function testGetQueryString($selects, $from, $joins, $wheres, $groupBys, $havings, $orderBys, $limit, $expectedQuery, $expectedFormattedQuery, $expectedBoundParameters, $expectedQuotedBoundParameters, $expectedDebuggedQuery) { foreach ($selects as $select) { $this->queryBuilder->select($select[0], isset($select[1]) ? $select[1] : null); } if (!empty($from)) { $this->queryBuilder->from($from[0], isset($from[1]) ? $from[1] : null); } foreach ($joins as $join) { $this->queryBuilder->join($join[0], isset($join[1]) ? $join[1] : null, isset($join[2]) ? $join[2] : null, isset($join[3]) ? $join[3] : null); } foreach ($wheres as $where) { $nbWhere = count($where); if ($nbWhere == 4) { $this->queryBuilder->where($where[0], $where[1], $where[2], $where[3]); } elseif ($nbWhere >= 1 && $nbWhere <= 2) { if ($where[0] == '(') { if (isset($where[1])) { $this->queryBuilder->_open($where[1]); } else { $this->queryBuilder->_open(); } } elseif ($where[0] == ')') { $this->queryBuilder->_close(); } } } foreach ($groupBys as $groupBy) { $this->queryBuilder->groupBy($groupBy[0], $groupBy[1]); } foreach ($havings as $having) { $nbHaving = count($having); if ($nbHaving == 4) { $this->queryBuilder->having($having[0], $having[1], $having[2], $having[3]); } elseif ($nbHaving >= 1 && $nbHaving <= 2) { if ($having[0] == '(') { if (isset($having[1])) { $this->queryBuilder->openHaving($having[1]); } else { $this->queryBuilder->openHaving(); } } elseif ($having[0] == ')') { $this->queryBuilder->closeHaving(); } } } foreach ($orderBys as $orderBy) { $this->queryBuilder->orderBy($orderBy[0], $orderBy[1]); } if (!empty($limit)) { $this->queryBuilder->limit($limit[0]); if (isset($limit[1])) { $this->queryBuilder->offset($limit[1]); } } $this->assertEquals($expectedQuery, $this->queryBuilder->getQueryString()); $this->assertEquals($expectedQuery, (string) $this->queryBuilder); $this->assertEquals($expectedFormattedQuery, $this->queryBuilder->getQueryString(true)); $this->assertEquals($expectedBoundParameters, $this->queryBuilder->getBoundParameters()); $this->assertEquals($expectedQuotedBoundParameters, $this->queryBuilder->getBoundParameters(true)); $this->assertEquals($expectedDebuggedQuery, $this->queryBuilder->debug()); }