public function testIsPerformingSearch() { $mockHandler = new MockHandler([new Response(200, [], $this->getMockRawResult())]); $adapter = new TorrentProjectAdapter(); $adapter->setHttpClient(new Client(['handler' => $mockHandler])); $result1 = new SearchResult(); $result1->setName('elementaryos-0.3.2-stable-i386.20151209.iso'); $result1->setCategory('all'); $result1->setSize(1126170624); $result1->setTorrentHash('001b104e49d517cf7a41593a73c3861b7c8e34f8'); $result1->setSeeders(15); $result1->setLeechers(2); $actual = $adapter->search('The Walking Dead S05E08')->wait(); $this->assertEquals($result1, $actual->getSearchResult()[0]); }
/** * Parses thepiratebay html response. * * @param string $htmlBody * * @return SearchResult[] */ private static function parseResponse($htmlBody) { $results = []; $raw_results = json_decode($htmlBody, true); foreach ($raw_results as $row) { if (is_array($row)) { $result = new SearchResult(); $result->setTorrentHash($row['torrent_hash']); $result->setName($row['title']); $result->setCategory($row['category']); $result->setLeechers($row['leechs']); $result->setSeeders($row['seeds']); $result->setSize($row['torrent_size']); $results[] = $result; } } return $results; }