Skip to content

Commit 53e6207

Browse files
committed
Allow null id in delete
1 parent 743fa30 commit 53e6207

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/Client.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,13 @@ public function put($resource, $id, array $data)
272272
*/
273273
public function startDelete($resource, $id, array $data = null)
274274
{
275-
Util::throwIfNotType(['string' => [$resource, $id]], true);
276-
$url = "{$this->_baseUrl}/" . urlencode($resource) . '/' . urlencode($id);
275+
Util::throwIfNotType(['string' => [$resource]], true);
276+
$url = "{$this->_baseUrl}/" . urlencode($resource);
277+
if ($id !== null) {
278+
Util::throwIfNotType(['string' => [$id]], true);
279+
$url .= '/' . urlencode($id);
280+
}
281+
277282
$json = $data !== null ? json_encode($data) : null;
278283
return $this->_start($url, 'DELETE', $json, ['Content-Type' => 'application/json']);
279284
}

tests/ClientTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,25 @@ public function delete()
286286
$this->assertSame(['Content-Type' => ['application/json']], $response->getResponseHeaders());
287287
}
288288

289+
/**
290+
* Verify behavior of startDelete when no id is given.
291+
*
292+
* @test
293+
* @covers ::startDelete
294+
*
295+
* @return void
296+
*/
297+
public function deleteWithoutId()
298+
{
299+
$adapter = new DeleteAdapter();
300+
$authentication = Authentication::createClientCredentials('not under test', 'not under test');
301+
$client = new Client($adapter, $authentication, 'baseUrl/v1');
302+
$client->startDelete('resource', null, ['foo' => 'bar']);
303+
$this->assertSame('baseUrl/v1/resource', $adapter->request->getUrl());
304+
$this->assertSame('DELETE', $adapter->request->getMethod());
305+
$this->assertSame(json_encode(['foo' => 'bar']), $adapter->request->getBody());
306+
}
307+
289308
/**
290309
* Verfiy delete creates the request body properly
291310
*

0 commit comments

Comments
 (0)