public function testSessionGetShouldThrowAnExceptionWithAnInvalidSessionId()
 {
     $requestBody = '{"method":"session-get"}';
     $invalidSessionId = uniqid();
     $this->sendRequest($requestBody, $invalidSessionId)->andThrow($this->generateCSRFException());
     try {
         $this->rpcClient->sessionGet($invalidSessionId);
     } catch (CSRFException $e) {
         $this->assertSame($this->sessionId, $e->getSessionId());
     }
 }
示例#2
0
    return $torrentList;
}
/**
 * @param array $torrentList
 */
function checkNotEmptyList(array $torrentList)
{
    if (empty($torrentList)) {
        echo 'No torrents found.' . PHP_EOL;
        exit(0);
    }
}
$sessionId = '';
// Fetching a new session ID
try {
    $api->sessionGet($sessionId);
} catch (CSRFException $e) {
    $sessionId = $e->getSessionId();
}
// Adding a new torrent to the download queue
$torrentData = $api->torrentAdd($sessionId, [Add::FILENAME => $newTorrentFile]);
printf('New torrent "%s" with ID %d added:', $torrentData[Get::NAME], $torrentData[Get::ID]);
echo PHP_EOL;
$torrentList = getTorrentData($api, $sessionId, []);
checkNotEmptyList($torrentList);
echo 'Torrent list:' . PHP_EOL;
printTorrentData($torrentList);
// Stopping the first torrent
$api->torrentStop($sessionId, new TorrentIdList([$torrentList[0][Get::ID]]));
sleep(1);
// The transmission API is not real time