Skip to content

Commit 1335af1

Browse files
committed
fix(stemming): handle null response from dictionary retrieval
- add null check in `StemmingDictionaries::retrieve()` to return empty dict - add setup method to initialize dictionary before tests - fix typo in test method name from `Rules` to `Dictionaries`
1 parent a7919ab commit 1335af1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/StemmingDictionaries.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ static function ($item) {
4747

4848
public function retrieve()
4949
{
50-
return $this->apiCall->get(StemmingDictionaries::RESOURCE_PATH, []);
50+
$response = $this->apiCall->get(StemmingDictionaries::RESOURCE_PATH, []);
51+
52+
// If response is null, return empty dictionaries structure
53+
if ($response === null) {
54+
return ['dictionaries' => []];
55+
}
56+
return $response;
5157
}
5258

5359
private function endpoint_path($operation = null)

tests/Feature/StemmingDictionariesTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class StemmingDictionariesTest extends TestCase
1515

1616
private $dictionaryUpsertResponse = null;
1717

18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
22+
$this->client()->stemming->dictionaries()->upsert(
23+
$this->dictionaryId,
24+
$this->dictionary
25+
);
26+
}
27+
1828
public function testCanUpsertADictionary(): void
1929
{
2030
$this->dictionaryUpsertResponse = $this->client()->stemming->dictionaries()->upsert($this->dictionaryId, $this->dictionary);
@@ -28,7 +38,7 @@ public function testCanRetrieveADictionary(): void
2838
}
2939

3040

31-
public function testCanRetrieveAllRules(): void
41+
public function testCanRetrieveAllDicitionaries(): void
3242
{
3343
$returnData = $this->client()->stemming->dictionaries()->retrieve();
3444
$this->assertCount(1, $returnData['dictionaries']);

0 commit comments

Comments
 (0)