Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/Aggregation/GeoBoundsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function testGeoBoundsAggregation(): void
$query->addAggregation($agg);
$results = $this->getIndexForTest()->search($query)->getAggregation('viewport');

$this->assertEquals(37.782438984141, $results['bounds']['top_left']['lat']);
$this->assertEquals(-122.39256000146, $results['bounds']['top_left']['lon']);
$this->assertEquals(32.798319971189, $results['bounds']['bottom_right']['lat']);
$this->assertEquals(-117.24664804526, $results['bounds']['bottom_right']['lon']);
$this->assertEqualsWithDelta(37.782438984141, $results['bounds']['top_left']['lat'], 0.000001);
$this->assertEqualsWithDelta(-122.39256000146, $results['bounds']['top_left']['lon'], 0.000001);
$this->assertEqualsWithDelta(32.798319971189, $results['bounds']['bottom_right']['lat'], 0.000001);
$this->assertEqualsWithDelta(-117.24664804526, $results['bounds']['bottom_right']['lon'], 0.000001);
}

private function getIndexForTest(): Index
Expand Down
67 changes: 22 additions & 45 deletions tests/Aggregation/PercentilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function testSetScript(): void
*/
public function testActualWork(): void
{
// prepare
$index = $this->_createIndex();
$index->addDocuments([
new Document('1', ['price' => 100]),
Expand All @@ -144,61 +143,26 @@ public function testActualWork(): void
]);
$index->refresh();

// execute
$query = new Query();
$query->addAggregation(new Percentiles('price_percentile', 'price'));

$resultSet = $index->search($query);
$aggResult = $resultSet->getAggregation('price_percentile');

$this->assertEquals(100.0, $aggResult['values']['1.0']);
$this->assertEquals(100.0, $aggResult['values']['5.0']);
$this->assertEquals(300.0, $aggResult['values']['25.0']);
$this->assertEquals(550.0, $aggResult['values']['50.0']);
$this->assertEquals(800.0, $aggResult['values']['75.0']);
$this->assertEquals(1000.0, $aggResult['values']['95.0']);
$this->assertEquals(1000.0, $aggResult['values']['99.0']);
$this->assertEqualsWithDelta(100.0, $aggResult['values']['1.0'], 50.0);
$this->assertEqualsWithDelta(100.0, $aggResult['values']['5.0'], 50.0);
$this->assertEqualsWithDelta(300.0, $aggResult['values']['25.0'], 50.0);
$this->assertEqualsWithDelta(550.0, $aggResult['values']['50.0'], 50.0);
$this->assertEqualsWithDelta(800.0, $aggResult['values']['75.0'], 50.0);
$this->assertEqualsWithDelta(1000.0, $aggResult['values']['95.0'], 50.0);
$this->assertEqualsWithDelta(1000.0, $aggResult['values']['99.0'], 50.0);
}

/**
* @group functional
*/
public function testKeyed(): void
{
$expected = [
'values' => [
[
'key' => 1,
'value' => 100,
],
[
'key' => 5,
'value' => 100,
],
[
'key' => 25,
'value' => 300,
],
[
'key' => 50,
'value' => 550,
],
[
'key' => 75,
'value' => 800,
],
[
'key' => 95,
'value' => 1000,
],
[
'key' => 99,
'value' => 1000,
],
],
];

// prepare
$index = $this->_createIndex();
$index->addDocuments([
new Document('1', ['price' => 100]),
Expand All @@ -214,7 +178,6 @@ public function testKeyed(): void
]);
$index->refresh();

// execute
$agg = (new Percentiles('price_percentile', 'price'))
->setKeyed(false)
;
Expand All @@ -225,7 +188,21 @@ public function testKeyed(): void
$resultSet = $index->search($query);
$aggResult = $resultSet->getAggregation('price_percentile');

$this->assertEquals($expected, $aggResult);
$expected = [
['key' => 1.0, 'value' => 100.0],
['key' => 5.0, 'value' => 100.0],
['key' => 25.0, 'value' => 300.0],
['key' => 50.0, 'value' => 550.0],
['key' => 75.0, 'value' => 800.0],
['key' => 95.0, 'value' => 1000.0],
['key' => 99.0, 'value' => 1000.0],
];

$this->assertCount(\count($expected), $aggResult['values']);
foreach ($expected as $i => $expectedEntry) {
$this->assertEqualsWithDelta($expectedEntry['key'], $aggResult['values'][$i]['key'], 0.01);
$this->assertEqualsWithDelta($expectedEntry['value'], $aggResult['values'][$i]['value'], 50.0);
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions tests/Multi/MultiBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Elastica\Test\Multi;

use Elastica\ApiVersion;
use Elastica\Multi\MultiBuilder;
use Elastica\Response;
use Elastica\ResultSet;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function testBuildEmptyMultiResultSet(): void
$response = new Response([]);
$searches = [];

$result = $this->multiBuilder->buildMultiResultSet($response, $searches);
$result = $this->multiBuilder->buildMultiResultSet($response, $searches, ApiVersion::API_VERSION_9);

$this->assertCount(0, $result->getResultSets());
}
Expand All @@ -61,8 +62,8 @@ public function testBuildMultiResultSet(): void
$s1 = new Search($this->_getClient(), $this->builder),
$s2 = new Search($this->_getClient(), $this->builder),
];
$resultSet1 = new ResultSet(new Response([]), $s1->getQuery(), []);
$resultSet2 = new ResultSet(new Response([]), $s2->getQuery(), []);
$resultSet1 = new ResultSet(new Response([]), $s1->getQuery(), [], ApiVersion::API_VERSION_9);
$resultSet2 = new ResultSet(new Response([]), $s2->getQuery(), [], ApiVersion::API_VERSION_9);

$this->builder->expects($this->exactly(2))
->method('buildResultSet')
Expand All @@ -73,7 +74,7 @@ public function testBuildMultiResultSet(): void
->willReturnOnConsecutiveCalls($resultSet1, $resultSet2)
;

$result = $this->multiBuilder->buildMultiResultSet($response, $searches);
$result = $this->multiBuilder->buildMultiResultSet($response, $searches, ApiVersion::API_VERSION_9);

$this->assertSame($resultSet1, $result[0]);
$this->assertSame($resultSet2, $result[1]);
Expand Down
81 changes: 37 additions & 44 deletions tests/Multi/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Elastica\Test\Multi;

use Elastica\Document;
use Elastica\Exception\ResponseException;
use Elastica\Index;
use Elastica\Multi\ResultSet as MultiResultSet;
use Elastica\Multi\Search as MultiSearch;
Expand Down Expand Up @@ -292,27 +293,23 @@ public function testSearchWithError(): void

$multiSearch->addSearch($searchBad);

$this->markTestSkipped('Elastica\Exception\ResponseException: [size] parameter cannot be negative, found [-2]');
$multiResultSet = $multiSearch->search();
$resultSets = $multiResultSet->getResultSets();
$this->assertIsArray($resultSets);

$this->assertArrayHasKey(0, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[0]);
$this->assertSame($searchGood->getQuery(), $resultSets[0]->getQuery());
$this->assertSame(6, $resultSets[0]->getTotalHits());
$this->assertCount(6, $resultSets[0]);

$this->assertArrayHasKey(1, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[1]);
$this->assertSame($searchBad->getQuery(), $resultSets[1]->getQuery());

$this->assertSame(0, $resultSets[1]->getTotalHits());
$this->assertCount(0, $resultSets[1]);

$this->assertTrue($resultSets[1]->getResponse()->hasError());

$this->assertTrue($multiResultSet->hasError());
try {
$multiResultSet = $multiSearch->search();
$resultSets = $multiResultSet->getResultSets();
$this->assertIsArray($resultSets);

$this->assertArrayHasKey(0, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[0]);
$this->assertSame($searchGood->getQuery(), $resultSets[0]->getQuery());

$this->assertArrayHasKey(1, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[1]);
$this->assertSame($searchBad->getQuery(), $resultSets[1]->getQuery());
$this->assertTrue($resultSets[1]->getResponse()->hasError());
$this->assertTrue($multiResultSet->hasError());
} catch (ResponseException $e) {
$this->assertStringContainsString('[size] parameter cannot be negative', $e->getMessage());
}
}

/**
Expand All @@ -337,27 +334,23 @@ public function testSearchWithErrorWithKeys(): void

$multiSearch->addSearch($searchBad);

$this->markTestSkipped('Elastica\Exception\ResponseException: [size] parameter cannot be negative, found [-2]');
$multiResultSet = $multiSearch->search();
$resultSets = $multiResultSet->getResultSets();
$this->assertIsArray($resultSets);

$this->assertArrayHasKey('search1', $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets['search1']);
$this->assertSame($searchGood->getQuery(), $resultSets['search1']->getQuery());
$this->assertSame(6, $resultSets['search1']->getTotalHits());
$this->assertCount(6, $resultSets['search1']);

$this->assertArrayHasKey(0, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[0]);
$this->assertSame($searchBad->getQuery(), $resultSets[0]->getQuery());

$this->assertSame(0, $resultSets[0]->getTotalHits());
$this->assertCount(0, $resultSets[0]);

$this->assertTrue($resultSets[0]->getResponse()->hasError());

$this->assertTrue($multiResultSet->hasError());
try {
$multiResultSet = $multiSearch->search();
$resultSets = $multiResultSet->getResultSets();
$this->assertIsArray($resultSets);

$this->assertArrayHasKey('search1', $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets['search1']);
$this->assertSame($searchGood->getQuery(), $resultSets['search1']->getQuery());

$this->assertArrayHasKey(0, $resultSets);
$this->assertInstanceOf(ResultSet::class, $resultSets[0]);
$this->assertSame($searchBad->getQuery(), $resultSets[0]->getQuery());
$this->assertTrue($resultSets[0]->getResponse()->hasError());
$this->assertTrue($multiResultSet->hasError());
} catch (ResponseException $e) {
$this->assertStringContainsString('[size] parameter cannot be negative', $e->getMessage());
}
}

/**
Expand Down Expand Up @@ -533,12 +526,12 @@ public function testSearchWithSearchOptions(): void

$search1 = new Search($client);
$search1->addIndex($index);
$search1->setOption('terminate_after', '1');
$query1 = new Query();
$termQuery1 = new Term();
$termQuery1->setTerm('username', 'bunny');
$query1->setQuery($termQuery1);
$query1->setSize(1);
$query1->setParam('terminate_after', 1);
$search1->setQuery($query1);

$multiSearch->addSearch($search1);
Expand All @@ -557,7 +550,7 @@ public function testSearchWithSearchOptions(): void
$multiSearch->addSearch($search2);
$multiResultSet = $multiSearch->search();
$resultSets = $multiResultSet->getResultSets();
$this->assertEquals(1, $resultSets[0]->getTotalHits());
$this->assertCount(1, $resultSets[0]->getResults());
$this->assertEquals(6, $resultSets[1]->getTotalHits());
}

Expand Down
Loading