/**
  * Tests modifySearch method, with one and with multiple search fields.
  */
 public function testModifySearch()
 {
     $mockFilterState = $this->getMockBuilder('ONGR\\FilterManagerBundle\\Filters\\FilterState')->getMock();
     $mockFilterState->expects($this->exactly(2))->method('isActive')->will($this->returnValue(true));
     $fuzzySearch = new FuzzySearch();
     $mockSearch = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\Search')->getMock();
     $mockSearch->expects($this->once())->method('addQuery')->with($this->isInstanceOf('ONGR\\ElasticsearchBundle\\DSL\\Query\\FuzzyQuery'), $this->equalTo('must'));
     $fuzzySearch->setField('name');
     $fuzzySearch->modifySearch($mockSearch, $mockFilterState);
     $mockSearch = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\Search')->getMock();
     $mockSearch->expects($this->exactly(1))->method('addQuery')->with($this->isInstanceOf('ONGR\\ElasticsearchBundle\\DSL\\Query\\BoolQuery'), $this->equalTo('must'));
     $fuzzySearch->setField('name,age,address');
     $fuzzySearch->modifySearch($mockSearch, $mockFilterState);
 }
 /**
  * Tests if search works.
  *
  * @param array            $expected
  * @param Request          $request
  * @param string|int|float $fuzziness
  * @param int              $prefixLength
  * @param int              $maxExpansions
  *
  * @dataProvider getTestingData
  */
 public function testFiltering($expected, $request, $fuzziness = null, $prefixLength = null, $maxExpansions = null)
 {
     $container = new FiltersContainer();
     $fuzzy = new FuzzySearch();
     $fuzzy->setRequestField('q');
     $fuzzy->setField('color');
     $fuzzy->setFuzziness($fuzziness);
     $fuzzy->setPrefixLength($prefixLength);
     $fuzzy->setMaxExpansions($maxExpansions);
     $container->set('fuzzy', $fuzzy);
     $fmb = new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
     $result = $fmb->execute($request);
     $actual = [];
     foreach ($result->getResult() as $doc) {
         $actual[] = $doc->getId();
     }
     sort($actual);
     $this->assertEquals($expected, $actual);
 }