Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hungneox committed Jun 17, 2018
1 parent 47b2177 commit 77a7b75
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions tests/Search/SearchTest.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -140,45 +141,48 @@ public function testToArray()
],
],
],
'size' => 100,
'from' => 0,
'size' => 100,
], $this->search->buildBody());

$this->search = $this->service->createSearch();
$this->search->setSort($this->sort);

$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();
$this->search->addAggregation($this->aggregation);

$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());
}

Expand All @@ -191,6 +195,7 @@ public function testToArrayWithSource()

$this->assertEquals([
'query' => ['match_all' => new \stdClass()],
'from' => 0,
'size' => 100,
'_source' => [
'id',
Expand Down Expand Up @@ -221,7 +226,7 @@ public function testAddAggregations()

$this->assertEquals([
'query' => ['match_all' => new \stdClass()],
'aggs' => [
'aggs' => [
'name1' => [
'terms' => [
'field' => 'field1'
Expand All @@ -233,7 +238,8 @@ public function testAddAggregations()
]
]
],
'size' => 100,
'from' => 0,
'size' => 100,
], $this->search->buildBody());
}
}

0 comments on commit 77a7b75

Please sign in to comment.