summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php88
1 files changed, 49 insertions, 39 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
index 215dac63..0e2ed2e6 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
@@ -1,86 +1,96 @@
<?php
-
namespace Elastica\Test\Aggregation;
-use Elastica\Aggregation\Terms;
use Elastica\Aggregation\Nested;
use Elastica\Aggregation\ReverseNested;
+use Elastica\Aggregation\Terms;
use Elastica\Document;
use Elastica\Query;
use Elastica\Type\Mapping;
class ReverseNestedTest extends BaseAggregationTest
{
- protected function setUp()
+ protected function _getIndexForTest()
{
- parent::setUp();
- $this->_index = $this->_createIndex("nested");
+ $index = $this->_createIndex();
$mapping = new Mapping();
$mapping->setProperties(array(
- "comments" => array(
- "type" => "nested",
- "properties" => array(
- "name" => array("type" => "string"),
- "body" => array("type" => "string")
- )
- )
+ 'comments' => array(
+ 'type' => 'nested',
+ 'properties' => array(
+ 'name' => array('type' => 'string'),
+ 'body' => array('type' => 'string'),
+ ),
+ ),
));
- $type = $this->_index->getType("test");
+ $type = $index->getType('test');
$type->setMapping($mapping);
- $docs = array(
- new Document("1", array(
- "comments" => array(
+
+ $type->addDocuments(array(
+ new Document(1, array(
+ 'comments' => array(
array(
- "name" => "bob",
- "body" => "this is bobs comment",
+ 'name' => 'bob',
+ 'body' => 'this is bobs comment',
),
array(
- "name" => "john",
- "body" => "this is johns comment",
+ 'name' => 'john',
+ 'body' => 'this is johns comment',
),
),
- "tags" => array("foo", "bar"),
+ 'tags' => array('foo', 'bar'),
)),
- new Document("2", array(
- "comments" => array(
+ new Document(2, array(
+ 'comments' => array(
array(
- "name" => "bob",
- "body" => "this is another comment from bob",
+ 'name' => 'bob',
+ 'body' => 'this is another comment from bob',
),
array(
- "name" => "susan",
- "body" => "this is susans comment",
+ 'name' => 'susan',
+ 'body' => 'this is susans comment',
),
),
- "tags" => array("foo", "baz"),
- ))
- );
- $type->addDocuments($docs);
- $this->_index->refresh();
+ 'tags' => array('foo', 'baz'),
+ )),
+ ));
+
+ $index->refresh();
+
+ return $index;
}
+ /**
+ * @group unit
+ */
public function testPathNotSetIfNull()
{
$agg = new ReverseNested('nested');
$this->assertFalse($agg->hasParam('path'));
}
+ /**
+ * @group unit
+ */
public function testPathSetIfNotNull()
{
$agg = new ReverseNested('nested', 'some_field');
$this->assertEquals('some_field', $agg->getParam('path'));
}
+ /**
+ * @group functional
+ */
public function testReverseNestedAggregation()
{
- $agg = new Nested("comments", "comments");
- $names = new Terms("name");
- $names->setField("comments.name");
+ $agg = new Nested('comments', 'comments');
+ $names = new Terms('name');
+ $names->setField('comments.name');
- $tags = new Terms("tags");
- $tags->setField("tags");
+ $tags = new Terms('tags');
+ $tags->setField('tags');
- $reverseNested = new ReverseNested("main");
+ $reverseNested = new ReverseNested('main');
$reverseNested->addAggregation($tags);
$names->addAggregation($reverseNested);
@@ -89,7 +99,7 @@ class ReverseNestedTest extends BaseAggregationTest
$query = new Query();
$query->addAggregation($agg);
- $results = $this->_index->search($query)->getAggregation("comments");
+ $results = $this->_getIndexForTest()->search($query)->getAggregation('comments');
$this->assertArrayHasKey('name', $results);
$nameResults = $results['name'];