public function testShouldDownloadTorrentFile() { $content = 'content_file'; $stream = $this->getMock('GuzzleHttp\\Stream\\StreamInterface'); $stream->expects($this->once())->method('getContents')->willReturn($content); $response = $this->getMock('GuzzleHttp\\Message\\ResponseInterface'); $response->expects($this->once())->method('getBody')->willReturn($stream); $this->client->expects($this->once())->method('post')->with($this->config->getBaseUrl() . '/torrents/download/18', array('headers' => array('Authorization' => 'token')))->willReturn($response); $torrent = $this->getMockBuilder('Rosello\\T411\\Model\\Torrent')->disableOriginalConstructor()->getMock(); $torrent->expects($this->once())->method('getId')->willReturn(18); $this->assertSame($content, $this->downloader->download($torrent)); }
<?php require __DIR__ . '/../vendor/autoload.php'; use Rosello\T411\Authentication\Authentication; use Rosello\T411\Config\AuthConfig; use Rosello\T411\Downloader\TorrentDownloader; use Rosello\T411\Repository\TorrentRepository; //Create auth config object $authConfig = new AuthConfig('username', 'password'); //Ask token $authentication = new Authentication(); $tokenConfig = $authentication->auth($authConfig); //Search torrents $limit = 10; $repository = new TorrentRepository($tokenConfig, $limit); $torrents = $repository->search('Ubuntu'); //Download first torrent $downloader = new TorrentDownloader($tokenConfig); $file = $downloader->download($torrents[0]);