public function testMergeHaving()
 {
     $this->queryBuilder->having('score', 5, SelectQueryBuilder::LESS_THAN);
     $qb = new SelectQueryBuilder();
     $qb->openHaving(SelectQueryBuilder::LOGICAL_OR)->having('price', 9, SelectQueryBuilder::NOT_EQUALS, null)->closeHaving();
     $this->queryBuilder->mergeHaving($qb);
     $expected = array(array('column' => 'score', 'value' => 5, 'operator' => '<', 'connector' => 'AND'), array('bracket' => '(', 'connector' => 'OR'), array('column' => 'price', 'value' => 9, 'operator' => '!=', 'connector' => 'AND'), array('bracket' => ')', 'connector' => NULL));
     $this->assertEquals($expected, $this->queryBuilder->getHavingParts());
 }
Ejemplo n.º 2
0
 /**
  * Merges the given QueryBuilder's HAVINGs into this QueryBuilder.
  *
  * @param \SQL\SelectQueryBuilder $QueryBuilder to merge
  *
  * @return \SQL\SelectQueryBuilder the current QueryBuilder
  */
 public function mergeHaving(SelectQueryBuilder $QueryBuilder)
 {
     foreach ($QueryBuilder->getHavingParts() as $currentHaving) {
         // Handle open/close brackets differently than other criteria.
         if (array_key_exists('bracket', $currentHaving)) {
             if (strcmp($currentHaving['bracket'], self::BRACKET_OPEN) == 0) {
                 $this->openHaving($currentHaving['connector']);
             } else {
                 $this->closeHaving();
             }
         } else {
             $this->having($currentHaving['column'], $currentHaving['value'], $currentHaving['operator'], $currentHaving['connector']);
         }
     }
     return $this;
 }