diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php | 139 |
1 files changed, 64 insertions, 75 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php index 12dbb598..96a49a77 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php @@ -1,121 +1,110 @@ <?php - namespace Elastica\Test\Filter; use Elastica\Document; use Elastica\Filter\Nested; use Elastica\Filter\Terms; use Elastica\Search; -use Elastica\Type\Mapping; use Elastica\Test\Base as BaseTest; +use Elastica\Type\Mapping; class NestedFilterWithSetFilterTest extends BaseTest { - public function setUp() + protected function _getIndexForTest() { - $client = $this->_getClient(); - $index = $client->getIndex('elastica_test_filter_nested_abstract_filter'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('user'); - $mapping = new Mapping(); - $mapping->setProperties( - array( - 'firstname' => array('type' => 'string', 'store' => 'yes'), - // default is store => no expected - 'lastname' => array('type' => 'string'), - 'hobbies' => array( - 'type' => 'nested', - 'include_in_parent' => true, - 'properties' => array('hobby' => array('type' => 'string')) - ) - ) - ); - $type->setMapping($mapping); - // Adds a list of documents with _bulk upload to the index - $docs = array(); - $docs[] = new Document(1, - array( + $type->setMapping(new Mapping(null, array( + 'firstname' => array('type' => 'string', 'store' => 'yes'), + // default is store => no expected + 'lastname' => array('type' => 'string'), + 'hobbies' => array( + 'type' => 'nested', + 'include_in_parent' => true, + 'properties' => array('hobby' => array('type' => 'string')), + ), + ))); + + $type->addDocuments(array( + new Document(1, array( 'firstname' => 'Nicolas', 'lastname' => 'Ruflin', 'hobbies' => array( - array('hobby' => 'opensource') - ) - ) - ); - $docs[] = new Document(2, - array( + array('hobby' => 'opensource'), + ), + )), + new Document(2, array( 'firstname' => 'Nicolas', 'lastname' => 'Ippolito', 'hobbies' => array( array('hobby' => 'opensource'), array('hobby' => 'guitar'), - ) - ) - ); - $response = $type->addDocuments($docs); + ), + )), + )); - // Refresh index $index->refresh(); - } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('elastica_test_filter_nested_abstract_filter'); - $index->delete(); + return $index; } + /** + * @group unit + */ public function testToArray() { - $f = new Nested(); - $this->assertEquals(array('nested' => array()), $f->toArray()); - $q = new Terms(); - $q->setTerms('hobby', array('guitar')); - $f->setPath('hobbies'); - $f->setFilter($q); + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setFilter($query); $expectedArray = array( 'nested' => array( 'path' => 'hobbies', 'filter' => array('terms' => array( - 'hobby' => array('guitar') - )) - ) + 'hobby' => array('guitar'), + )), + ), ); - $this->assertEquals($expectedArray, $f->toArray()); + $this->assertEquals($expectedArray, $filter->toArray()); } + /** + * @group functional + */ public function testShouldReturnTheRightNumberOfResult() { - $f = new Nested(); - $this->assertEquals(array('nested' => array()), $f->toArray()); - $q = new Terms(); - $q->setTerms('hobby', array('guitar')); - $f->setPath('hobbies'); - $f->setFilter($q); + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('guitar')); + $filter->setPath('hobbies'); + $filter->setFilter($query); - $c = $this->_getClient(); - $s = new Search($c); - $i = $c->getIndex('elastica_test_filter_nested_abstract_filter'); - $s->addIndex($i); - $r = $s->search($f); + $client = $this->_getClient(); + $search = new Search($client); + $index = $this->_getIndexForTest(); + $search->addIndex($index); + $resultSet = $search->search($filter); - $this->assertEquals(1, $r->getTotalHits()); + $this->assertEquals(1, $resultSet->getTotalHits()); - $f = new Nested(); - $this->assertEquals(array('nested' => array()), $f->toArray()); - $q = new Terms(); - $q->setTerms('hobby', array('opensource')); - $f->setPath('hobbies'); - $f->setFilter($q); + $filter = new Nested(); + $this->assertEquals(array('nested' => array()), $filter->toArray()); + $query = new Terms(); + $query->setTerms('hobby', array('opensource')); + $filter->setPath('hobbies'); + $filter->setFilter($query); - $c = $this->_getClient(); - $s = new Search($c); - $i = $c->getIndex('elastica_test_filter_nested_abstract_filter'); - $s->addIndex($i); - $r = $s->search($f); - $this->assertEquals(2, $r->getTotalHits()); + $client = $this->_getClient(); + $search = new Search($client); + $index = $this->_getIndexForTest(); + $search->addIndex($index); + $resultSet = $search->search($filter); + $this->assertEquals(2, $resultSet->getTotalHits()); } } |