Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
Fix wrong expectation of the Transmission response in case of duplica…
Browse files Browse the repository at this point in the history
…te torrents
  • Loading branch information
cyb3rd4d committed Mar 11, 2016
1 parent c9cf199 commit 9fdc30b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/RpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ private function buildRequestBody($method, array $arguments = [])
* @param string $requestBody
* @return array
* @throws CSRFException
* @throws DuplicateTorrentException
* @throws TransmissionException
*/
private function sendRequest($sessionId, $requestBody)
Expand Down Expand Up @@ -599,6 +600,16 @@ private function sendRequest($sessionId, $requestBody)
throw $e;
}

if (isset($responseBody['arguments']['torrent-duplicate'])) {
$torrentDuplicateData = $responseBody['arguments']['torrent-duplicate'];
$e = new DuplicateTorrentException();
$e->setTorrentId($torrentDuplicateData['id']);
$e->setTorrentName($torrentDuplicateData['name']);
$e->setTorrentHashString($torrentDuplicateData['hashString']);

throw $e;
}

return $responseBody;
}
}
2 changes: 1 addition & 1 deletion tests/RpcClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public function testTorrentAddShouldThrowAnExceptionWithDuplicateTorrent()
->andReturn($this->guzzleResponse);

$this->setResponseBody(sprintf(
'{"arguments":{"torrent-duplicate":{"id":%d,"name":"%s","hashString":"%s"}},"result":"duplicate torrent"}',
'{"arguments":{"torrent-duplicate":{"id":%d,"name":"%s","hashString":"%s"}},"result":"success"}',
$torrentId,
$torrentName,
$hashString
Expand Down

0 comments on commit 9fdc30b

Please sign in to comment.