コード例 #1
0
 /**
  * Tests toArray method.
  *
  * @param string $type         Child type.
  * @param string $queryType    Type of query for mock query class.
  * @param array  $queryToArray Return value for mock query class toArray method.
  * @param array  $parameters   Optional parameters.
  * @param string $dslType      Filter or query.
  * @param array  $expected     Expected result.
  *
  * @dataProvider getArrayDataProvider
  */
 public function testToArray($type, $queryType, $queryToArray, $parameters, $dslType, $expected)
 {
     $mockQuery = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\BuilderInterface')->getMock();
     $mockQuery->expects($this->once())->method('getType')->will($this->returnValue($queryType));
     $mockQuery->expects($this->once())->method('toArray')->will($this->returnValue($queryToArray));
     $filter = new HasChildFilter($type, $mockQuery, $parameters);
     $filter->setDslType($dslType);
     $result = $filter->toArray();
     $this->assertEquals($expected, $result);
 }
コード例 #2
0
 /**
  * Data provider for testHasChildFilter().
  *
  * @return array
  */
 public function getTestHasChildFilterData()
 {
     $out = [];
     $testData = $this->getDataArray();
     $mapping = ['product' => ['properties' => ['title' => ['type' => 'string']]], 'comment' => ['_parent' => ['type' => 'product'], '_routing' => ['required' => true], 'properties' => ['sub_title' => ['type' => 'string']]]];
     unset($testData['default']['product'][0]['_id']);
     // Case #0: Test with data.
     $filter = new HasChildFilter('comment', new TermFilter('sub_title', 'bar'));
     $out[] = [$filter, [$testData['default']['product'][0]], $mapping];
     // Case #1: Test with no data.
     $filter = new HasChildFilter('comment', new TermQuery('sub_title', 'nobar'));
     $filter->setDslType('query');
     $out[] = [$filter, [], $mapping];
     return $out;
 }