Skip to content

Commit 06f4281

Browse files
committed
MAGE-844 Fix ConfigTest
1 parent 977fb6e commit 06f4281

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Helper/AlgoliaHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,18 @@ public function generateSearchSecuredApiKey(string $key, array $params = []): st
321321

322322
/**
323323
* @param $indexName
324-
* @return void
324+
* @return array<string, mixed>
325325
* @throws \Exception
326326
*/
327-
public function getSettings($indexName)
327+
public function getSettings(string $indexName): array
328328
{
329329
try {
330330
return $this->client->getSettings($indexName);
331-
}catch (\Exception $e) {
331+
} catch (\Exception $e) {
332332
if ($e->getCode() !== 404) {
333333
throw $e;
334334
}
335+
return [];
335336
}
336337
}
337338

Test/Integration/ConfigTest.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testFacets()
1515

1616
$this->algoliaHelper->waitLastTask();
1717

18-
$indexSettings = $this->algoliaHelper->getIndex($this->indexPrefix . 'default_products')->getSettings();
18+
$indexSettings = $this->algoliaHelper->getSettings($this->indexPrefix . 'default_products');
1919

2020
$this->assertEquals($this->assertValues->attributesForFaceting, count($indexSettings['attributesForFaceting']));
2121
}
@@ -28,18 +28,22 @@ public function testQueryRules()
2828

2929
$this->algoliaHelper->waitLastTask();
3030

31-
$index = $this->algoliaHelper->getIndex($this->indexPrefix . 'default_products');
31+
$client = $this->algoliaHelper->getClient();
3232

3333
$matchedRules = [];
3434

3535
$hitsPerPage = 100;
3636
$page = 0;
3737
do {
38-
$fetchedQueryRules = $index->searchRules('', [
39-
'context' => 'magento_filters',
40-
'page' => $page,
41-
'hitsPerPage' => $hitsPerPage,
42-
]);
38+
$fetchedQueryRules = $client->searchRules(
39+
$this->indexPrefix . 'default_products',
40+
[
41+
'query' => '',
42+
'context' => 'magento_filters',
43+
'page' => $page,
44+
'hitsPerPage' => $hitsPerPage,
45+
]
46+
);
4347

4448
foreach ($fetchedQueryRules['hits'] as $hit) {
4549
$matchedRules[] = $hit;
@@ -75,7 +79,7 @@ public function testAutomaticalSetOfCategoriesFacet()
7579

7680
$this->algoliaHelper->waitLastTask();
7781

78-
$indexSettings = $this->algoliaHelper->getIndex($this->indexPrefix . 'default_products')->getSettings();
82+
$indexSettings = $this->algoliaHelper->getSettings($this->indexPrefix . 'default_products');
7983

8084
$this->assertEquals($this->assertValues->automaticalSetOfCategoryAttributesForFaceting, count($indexSettings['attributesForFaceting']));
8185

@@ -97,7 +101,7 @@ public function testAutomaticalSetOfCategoriesFacet()
97101

98102
$this->algoliaHelper->waitLastTask();
99103

100-
$indexSettings = $this->algoliaHelper->getIndex($this->indexPrefix . 'default_products')->getSettings();
104+
$indexSettings = $this->algoliaHelper->getSettings($this->indexPrefix . 'default_products');
101105

102106
$this->assertEquals($this->assertValues->automaticalSetOfCategoryAttributesForFaceting + 1, count($indexSettings['attributesForFaceting']));
103107

@@ -224,7 +228,7 @@ public function testExtraSettings()
224228
foreach ($sections as $section) {
225229
$indexName = $this->indexPrefix . 'default_' . $section;
226230

227-
$currentSettings = $this->algoliaHelper->getIndex($indexName)->getSettings();
231+
$currentSettings = $this->algoliaHelper->getSettings($indexName);
228232

229233
$this->assertArrayHasKey('exactOnSingleWordQuery', $currentSettings);
230234
$this->assertEquals('attribute', $currentSettings['exactOnSingleWordQuery']);
@@ -240,7 +244,7 @@ public function testExtraSettings()
240244
foreach ($sections as $section) {
241245
$indexName = $this->indexPrefix . 'default_' . $section;
242246

243-
$currentSettings = $this->algoliaHelper->getIndex($indexName)->getSettings();
247+
$currentSettings = $this->algoliaHelper->getSettings($indexName);
244248

245249
$this->assertArrayHasKey('exactOnSingleWordQuery', $currentSettings);
246250
$this->assertEquals('word', $currentSettings['exactOnSingleWordQuery']);

0 commit comments

Comments
 (0)