Skip to content

Commit

Permalink
Kill mutant in Results.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van Asselt committed Apr 25, 2024
1 parent fa9b610 commit 8c7039e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
1 change: 0 additions & 1 deletion infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"src"
],
"excludes": [
"Application/Results.php",
"ExplorerServiceProvider.php",
"Infrastructure/Console",
"Infrastructure/Scout/ElasticEngine",
Expand Down
57 changes: 55 additions & 2 deletions tests/Unit/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ public function test_it_adds_nested_aggregations(): void
'doc_count' => 42,
'filter_aggs' => [
'doc_count' => 42,
'buckets' => [
['key' => 'someFieldNestedAggregation_check', 'doc_count' => 6,],
],
'someFieldFiltered' => [
'doc_count_error_upper_bound' => 0,
'sum_other_doc_count' => 0,
Expand Down Expand Up @@ -499,7 +502,7 @@ public function test_it_adds_nested_aggregations(): void
$subject = new Finder($client, $builder);
$results = $subject->find();

self::assertCount(3, $results->aggregations());
self::assertCount(4, $results->aggregations());

$nestedAggregation = $results->aggregations()[0];

Expand All @@ -512,7 +515,7 @@ public function test_it_adds_nested_aggregations(): void
self::assertEquals(6, $nestedAggregationValue['doc_count']);
self::assertEquals('someKey', $nestedAggregationValue['key']);

$nestedFilterAggregation = $results->aggregations()[1];
$nestedFilterAggregation = $results->aggregations()[2];

self::assertInstanceOf(AggregationResult::class, $nestedFilterAggregation);
self::assertEquals('someFieldFiltered', $nestedFilterAggregation->name());
Expand All @@ -524,6 +527,56 @@ public function test_it_adds_nested_aggregations(): void
self::assertEquals('someFieldNestedAggregation', $nestedFilterAggregationValue['key']);
}

public function test_with_single_aggregation(): void
{
$client = Mockery::mock(Client::class);
$client->expects('search')
->with([
'index' => self::TEST_INDEX,
'body' => [
'query' => [
'bool' => [
'must' => [],
'should' => [],
'filter' => [],
],
],
'aggs' => [
'anotherAggregation' => ['terms' => ['field' => 'anotherField', 'size' => 10]],
],
],
])
->andReturn([
'hits' => [
'total' => ['value' => 1],
'hits' => [$this->hit()],
],
'aggregations' => [
'nestedAggregation' => [
'doc_count' => 42,
'someField' => [
'doc_count_error_upper_bound' => 0,
'sum_other_doc_count' => 0,
'buckets' => [
['key' => 'someKey', 'doc_count' => 6,],
],
],
],
],
]);

$query = Query::with(new BoolQuery());
$query->addAggregation('anotherAggregation', new TermsAggregation('anotherField'));

$builder = new SearchCommand(self::TEST_INDEX, $query);
$builder->setIndex(self::TEST_INDEX);

$subject = new Finder($client, $builder);
$results = $subject->find();

self::assertCount(1, $results->aggregations());
}

public function test_it_with_no_aggregations(): void
{
$client = Mockery::mock(Client::class);
Expand Down

0 comments on commit 8c7039e

Please sign in to comment.