File tree Expand file tree Collapse file tree
Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Eel Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -192,7 +192,10 @@ public function getAccessibleCount()
192192 public function getAggregations ()
193193 {
194194 $ this ->initialize ();
195- return $ this ->result ['aggregations ' ];
195+ if (array_key_exists ("aggregations " , $ this ->result )) {
196+ return $ this ->result ['aggregations ' ];
197+ }
198+ return array ();
196199 }
197200
198201 /**
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Flowpack \ElasticSearch \ContentRepositoryAdaptor \Tests \Unit \Eel ;
3+
4+ /* *
5+ * This script belongs to the TYPO3 Flow package "Flowpack.ElasticSearch.ContentRepositoryAdaptor". *
6+ * *
7+ * It is free software; you can redistribute it and/or modify it under *
8+ * the terms of the GNU Lesser General Public License, either version 3 *
9+ * of the License, or (at your option) any later version. *
10+ * *
11+ * The TYPO3 project - inspiring people to share! *
12+ * */
13+
14+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryBuilder ;
15+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryResult ;
16+
17+ /**
18+ * Testcase for ElasticSearchQueryBuilder
19+ */
20+ class ElasticSearchQueryBuilderResultTest extends \TYPO3 \Flow \Tests \UnitTestCase
21+ {
22+
23+ /**
24+ * @test
25+ */
26+ public function ifNoAggregationsAreSetInTheQueyBuilderResultAnEmptyArrayWillBeReturnedIfYouFetchTheAggregations ()
27+ {
28+ $ resultArrayWithoutAggregations = array (
29+ "nodes " => array ("some " , "nodes " )
30+ );
31+
32+ $ queryBuilder = $ this ->getMock (ElasticSearchQueryBuilder::class, array ("fetch " ));
33+ $ queryBuilder ->method ("fetch " )->will ($ this ->returnValue ($ resultArrayWithoutAggregations ));
34+
35+ $ esQuery = new \Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQuery ($ queryBuilder );
36+
37+ $ queryResult = new ElasticSearchQueryResult ($ esQuery );
38+
39+ $ actual = $ queryResult ->getAggregations ();
40+
41+ $ this ->assertTrue (is_array ($ actual ));
42+ $ this ->assertEmpty ($ actual );
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments