Пример #1
0
 /**
  * Builds the list of the torrents from the API response.
  *
  * @param array $response
  * @return TorrentSearchResultInterface
  */
 public function extractTorrentsFromApiResponse(array $response)
 {
     $torrentSearchResult = new TorrentSearchResult();
     $torrentSearchResult->setQuery($response['query']);
     $torrentSearchResult->setTotal($response['total']);
     $torrentSearchResult->setOffset($response['offset']);
     $torrentSearchResult->setLimit($response['limit']);
     $torrents = [];
     foreach ($response['torrents'] as $rawTorrentData) {
         $torrent = new Torrent();
         $category = new Category();
         $owner = new User();
         $category->setId($rawTorrentData['category']);
         $category->setName($rawTorrentData['categoryname']);
         $owner->setId($rawTorrentData['owner']);
         $owner->setUploadedData($rawTorrentData['username']);
         $torrent->setId($rawTorrentData['id']);
         $torrent->setName($rawTorrentData['name']);
         $torrent->setCategory($category);
         $torrent->setNumberOfLeechers($rawTorrentData['leechers']);
         $torrent->setNumberOfSeeders($rawTorrentData['seeders']);
         $torrent->setNumberOfComments($rawTorrentData['comments']);
         $torrent->setIsVerified($rawTorrentData['isVerified']);
         $torrent->setAdditionDate(new \DateTime($rawTorrentData['added']));
         $torrent->setSize($rawTorrentData['size']);
         $torrent->setTimesCompleted($rawTorrentData['times_completed']);
         $torrents[] = $torrent;
     }
     $torrentSearchResult->setTorrents($torrents);
     return $torrentSearchResult;
 }
 public function testInstance()
 {
     $torrentSearchResult = new TorrentSearchResult();
     $query = 'avatar';
     $offset = 10;
     $limit = 100;
     $total = 25;
     $torrents = [];
     for ($i = 0; $i < 5; $i++) {
         $torrents[] = new Torrent();
     }
     $torrentSearchResult->setQuery($query);
     $torrentSearchResult->setOffset($offset);
     $torrentSearchResult->setLimit($limit);
     $torrentSearchResult->setTotal($total);
     $torrentSearchResult->setTorrents($torrents);
     $this->assertSame($query, $torrentSearchResult->getQuery());
     $this->assertSame($offset, $torrentSearchResult->getOffset());
     $this->assertSame($limit, $torrentSearchResult->getLimit());
     $this->assertSame($total, $torrentSearchResult->getTotal());
     $this->assertSame($torrents, $torrentSearchResult->getTorrents());
 }