public function testAddFilterArrayOfValues()
 {
     $testValues = array('testArrayOfNumbers' => array('type' => Doctrine\DBAL\Connection::PARAM_INT_ARRAY, 'parameterName' => 'numbers', 'values' => array(1, 2, 3)), 'testArrayOfStrings' => array('type' => Doctrine\DBAL\Connection::PARAM_STR_ARRAY, 'parameterName' => 'strings', 'values' => array('A', 'B', 'C')));
     $filter = array();
     foreach ($testValues as $testValue) {
         $filter[] = array('property' => $testValue['parameterName'], 'value' => $testValue['values']);
     }
     $this->querybuilder->addFilter($filter);
     /** @var $expression \Doctrine\ORM\Query\Expr\Andx */
     $expression = $this->querybuilder->getDQLPart('where');
     $parts = $expression->getParts();
     $this->assertCount(2, $parts);
     $this->assertTrue(strpos($parts[0]->getRightExpr(), '(:number') === 0);
     $this->assertTrue(strpos($parts[1]->getRightExpr(), '(:strings') === 0);
     $expectedResult = array();
     $counter = 0;
     foreach ($testValues as $testValue) {
         $expectedResult[] = new Doctrine\ORM\Query\Expr\Comparison($testValue['parameterName'], 'IN', $parts[$counter]->getRightExpr());
         $counter++;
     }
     $this->assertEquals($expectedResult, $parts);
     $params = $this->querybuilder->getParameters()->toArray();
     $expectedResult = array();
     $counter = 0;
     foreach ($testValues as $testValue) {
         $expectedResult[] = new \Doctrine\ORM\Query\Parameter(trim($parts[$counter]->getRightExpr(), '()'), $testValue['values'], $testValue['type']);
         $counter++;
     }
     $this->assertEquals($expectedResult, $params);
 }
Exemple #2
0
 /**
  * Adds filters to the query results.
  *
  * <code>
  *      $this->addFilter($builder, array(array(
  *          'property' => 'name'
  *          'value' => 'A%'
  *      )));
  * </code>
  *
  * @param QueryBuilder $builder
  * @param array $filter
  */
 public function addFilter(QueryBuilder $builder, array $filter)
 {
     return $builder->addFilter($filter);
 }