Skip to content

Commit 26faced

Browse files
authored
add update method for contact client, add missing tests for contact cleint
1 parent 422146c commit 26faced

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ $response = $client->getAll();
5959
// other methods
6060
$response = $client->get($entityId);
6161
$response = $client->create($data);
62+
$response = $client->update($entityId, $data);
63+
6264
```
6365

6466
### Country Endpoint

src/Contact/Client.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ public function generateUrl(int $page): string
2222
'&direction=' . $this->sortDirection .
2323
'&property=' .$this->sortProperty;
2424
}
25+
26+
/**
27+
* @param string $id
28+
* @param array $data
29+
* @return ResponseInterface
30+
* @throws CacheException
31+
* @throws LexOfficeApiException
32+
*/
33+
public function update(string $id, array $data)
34+
{
35+
$api = $this->api->newRequest('PUT', $this->resource . '/' . $id);
36+
37+
$api->request = $api->request->withBody($this->createStream($data));
38+
39+
return $api->getResponse();
40+
}
2541
}

tests/Contact/ClientTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,44 @@ public function testGenerateUrl()
2222
);
2323
}
2424

25+
public function testCreate()
26+
{
27+
$stub = $this->createClientMockObject(
28+
Client::class,
29+
new Response(200, [], 'body'),
30+
['create']
31+
);
32+
33+
$response = $stub->create([
34+
'version' => 0
35+
]);
36+
37+
$this->assertEquals('body', $response->getBody()->__toString());
38+
}
39+
40+
public function testGet()
41+
{
42+
$stub = $this->createClientMockObject(
43+
Client::class,
44+
new Response(200, [], 'body'),
45+
['get']
46+
);
47+
48+
$response = $stub->get('resource-id');
49+
50+
$this->assertEquals('body', $response->getBody()->__toString());
51+
}
52+
53+
public function testUpdate()
54+
{
55+
$stub = $this->createClientMockObject(
56+
Client::class,
57+
new Response(200, [], 'body'),
58+
['update']
59+
);
60+
61+
$response = $stub->update('resource-id', []);
62+
63+
$this->assertEquals('body', $response->getBody()->__toString());
64+
}
2565
}

0 commit comments

Comments
 (0)