Skip to content

Commit e7f42f3

Browse files
author
Attila Dröszler
committed
handle empty resultset from contact api
1 parent 334ff81 commit e7f42f3

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/Suite/Api/Contact/Contact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getList(int $customerId, $keyId, array $keyValues, array $fields
3636
try
3737
{
3838
$response = $this->apiClient->post($this->endPoints->getData($customerId), $postData);
39-
return $response['data']['result'];
39+
return $response['data']['result'] ?: [];
4040
}
4141
catch (Error $ex)
4242
{

test/unit/Suite/Api/Contact/ContactTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public function getData_Perfect_Perfect()
4444
$this->assertEquals($contacts, $responseData);
4545
}
4646

47+
/**
48+
* @test
49+
*/
50+
public function getData_ContactNotFound_EmptyArrayReturned()
51+
{
52+
$this->apiClient->expects($this->once())->method('post')
53+
->will($this->apiSuccess([]));
54+
55+
$responseData = $this->contact->getList($this->customerId, 'id', [1, 2], [3]);
56+
$this->assertEquals([], $responseData);
57+
}
58+
4759
/**
4860
* @test
4961
*/
@@ -60,16 +72,16 @@ public function get_ApiFailure_ExceptionThrown()
6072
$this->fail('No exception was thrown.');
6173
}
6274

63-
private function apiSuccess($data = [])
75+
private function apiSuccess(array $data = [])
6476
{
6577
return $this->returnValue([
6678
'success' => true,
6779
'replyCode' => self::API_SUCCESS_CODE,
6880
'replyText' => self::API_SUCCESS_TEXT,
6981
'data' => [
7082
'errors' => [],
71-
'result' => $data
72-
]
83+
'result' => $data ?: false,
84+
],
7385
]);
7486
}
7587

0 commit comments

Comments
 (0)