/** * 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() { $id = 123; $name = 'Avatar'; $category = new Category(); $numberOfSeeders = 123456; $numberOfLeechers = 1234554; $numberOfComments = 234; $isVerified = true; $additionDate = new \DateTime('-2 months'); $size = 585959; $timesCompleted = 75757; $owner = new User(); $privacy = 'normal'; $torrent = new Torrent(); $torrent->setId($id); $torrent->setName($name); $torrent->setCategory($category); $torrent->setNumberOfSeeders($numberOfSeeders); $torrent->setNumberOfLeechers($numberOfLeechers); $torrent->setNumberOfComments($numberOfComments); $torrent->setIsVerified($isVerified); $torrent->setAdditionDate($additionDate); $torrent->setSize($size); $torrent->setTimesCompleted($timesCompleted); $torrent->setOwner($owner); $torrent->setPrivacy($privacy); $this->assertSame($id, $torrent->getId()); $this->assertSame($name, $torrent->getName()); $this->assertSame($category, $torrent->getCategory()); $this->assertSame($numberOfSeeders, $torrent->getNumberOfSeeders()); $this->assertSame($numberOfLeechers, $torrent->getNumberOfLeechers()); $this->assertSame($numberOfComments, $torrent->getNumberOfComments()); $this->assertSame($isVerified, $torrent->isVerified()); $this->assertSame($additionDate, $torrent->getAdditionDate()); $this->assertSame($size, $torrent->getSize()); $this->assertSame($timesCompleted, $torrent->getTimesCompleted()); $this->assertSame($owner, $torrent->getOwner()); $this->assertSame($privacy, $torrent->getPrivacy()); }