Skip to content

Commit

Permalink
Write tests for NestedFilteredAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van Asselt committed Apr 25, 2024
1 parent 2c45a92 commit 661b8d0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/Unit/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use JeroenG\Explorer\Domain\Aggregations\NestedAggregation;
use function var_dump;

class FinderTest extends MockeryTestCase
{
Expand Down Expand Up @@ -409,7 +410,7 @@ public function test_it_adds_nested_aggregations(): void
'aggs' => [
'filter_aggs' => [
'terms' => [
'field' => 'nestedFilteredAggregation.someField',
'field' => 'nestedFilteredAggregation.someFieldNestedAggregation',
'size' => 10,
],
],
Expand Down Expand Up @@ -458,7 +459,7 @@ public function test_it_adds_nested_aggregations(): void
'doc_count_error_upper_bound' => 0,
'sum_other_doc_count' => 0,
'buckets' => [
['key' => 'someKey', 'doc_count' => 6,],
['key' => 'someFieldNestedAggregation', 'doc_count' => 6,],
],
],
],
Expand All @@ -477,7 +478,7 @@ public function test_it_adds_nested_aggregations(): void
$nestedAggregation = new NestedAggregation('nestedAggregation');
$nestedAggregation->add('someField', new TermsAggregation('nestedAggregation.someField'));

$query->addAggregation('nestedFilteredAggregation', new NestedFilteredAggregation('nestedFilteredAggregation', 'filter_aggs', 'someField', []));
$query->addAggregation('nestedFilteredAggregation', new NestedFilteredAggregation('nestedFilteredAggregation', 'filter_aggs', 'someFieldNestedAggregation', []));

$query->addAggregation('nestedAggregation', $nestedAggregation);
$builder = new SearchCommand(self::TEST_INDEX, $query);
Expand All @@ -498,6 +499,17 @@ public function test_it_adds_nested_aggregations(): void

self::assertEquals(6, $nestedAggregationValue['doc_count']);
self::assertEquals('someKey', $nestedAggregationValue['key']);

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

self::assertInstanceOf(AggregationResult::class, $nestedFilterAggregation);
self::assertEquals('someFieldFiltered', $nestedFilterAggregation->name());
self::assertCount(1, $nestedFilterAggregation->values());

$nestedFilterAggregationValue = $nestedFilterAggregation->values()[0];

self::assertEquals(6, $nestedFilterAggregationValue['doc_count']);
self::assertEquals('someFieldNestedAggregation', $nestedFilterAggregationValue['key']);
}

private function hit(int $id = 1, float $score = 1.0): array
Expand Down

0 comments on commit 661b8d0

Please sign in to comment.