From 77a7b7565a621261565c41427b78415edb02e53a Mon Sep 17 00:00:00 2001 From: Hung Neo Date: Mon, 18 Jun 2018 01:03:41 +0300 Subject: [PATCH] Fix tests --- tests/Search/SearchTest.php | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tests/Search/SearchTest.php b/tests/Search/SearchTest.php index 0a2651f..b7d711a 100644 --- a/tests/Search/SearchTest.php +++ b/tests/Search/SearchTest.php @@ -48,10 +48,10 @@ protected function setUp() parent::setUp(); $this->search = $this->service->createSearch(); - $this->query = new BoolQuery(); + $this->query = new BoolQuery(); $this->query->addMust(new TermQuery('field1', 'value1')); - $this->sort = $this->service->createSort(); + $this->sort = $this->service->createSort(); $this->sort->addSort(new Sort\ScoreSort()); $this->aggregation = new GlobalAggregation(); @@ -102,7 +102,8 @@ public function testToArray() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'size' => 100, + 'from' => 0, + 'size' => 100, ], $this->search->buildBody()); $this->search = $this->service->createSearch(); @@ -111,8 +112,8 @@ public function testToArray() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'size' => 100, - 'from' => 100, + 'size' => 100, + 'from' => 100, ], $this->search->buildBody()); $this->search = $this->service->createSearch(); @@ -121,8 +122,8 @@ public function testToArray() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'from' => 10, - 'size' => 10, + 'from' => 10, + 'size' => 10, ], $this->search->buildBody()); $this->search = $this->service->createSearch(); @@ -140,7 +141,8 @@ public function testToArray() ], ], ], - 'size' => 100, + 'from' => 0, + 'size' => 100, ], $this->search->buildBody()); $this->search = $this->service->createSearch(); @@ -148,8 +150,9 @@ public function testToArray() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'sort' => ['_score'], - 'size' => 100, + 'sort' => ['_score'], + 'from' => 0, + 'size' => 100, ], $this->search->buildBody()); $this->search = $this->service->createSearch(); @@ -157,28 +160,29 @@ public function testToArray() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'aggs' => [ + 'aggs' => [ 'global_name' => [ 'global' => new \stdClass(), - 'aggs' => [ + 'aggs' => [ 'min_name' => ['min' => ['field' => 'field_name']], 'max_name' => ['max' => ['field' => 'field_name']], ], ], ], - 'size' => 100, + 'from' => 0, + 'size' => 100, ], $this->search->buildBody()); - + // Make sure "from" is present when it's a positive number $this->search->setFrom(10); $this->assertArraySubset([ 'from' => 10, ], $this->search->buildBody()); - + // Make sure "size" is not present when it's set to zero $this->search->setSize(0); - + $this->assertArrayNotHasKey('size', $this->search->buildBody()); } @@ -191,6 +195,7 @@ public function testToArrayWithSource() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], + 'from' => 0, 'size' => 100, '_source' => [ 'id', @@ -221,7 +226,7 @@ public function testAddAggregations() $this->assertEquals([ 'query' => ['match_all' => new \stdClass()], - 'aggs' => [ + 'aggs' => [ 'name1' => [ 'terms' => [ 'field' => 'field1' @@ -233,7 +238,8 @@ public function testAddAggregations() ] ] ], - 'size' => 100, + 'from' => 0, + 'size' => 100, ], $this->search->buildBody()); } }