/** * 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; $username = '******'; $gender = 'male'; $age = 42; $avatarUri = '/images/avatar.jpg'; $downloadedData = 12345; $uploadedData = 12345; $user = new User(); $user->setId($id); $user->setUsername($username); $user->setGender($gender); $user->setAge($age); $user->setAvatarUri($avatarUri); $user->setDownloadedData($downloadedData); $user->setUploadedData($uploadedData); $this->assertSame($id, $user->getId()); $this->assertSame($username, $user->getUsername()); $this->assertSame($gender, $user->getGender()); $this->assertSame($age, $user->getAge()); $this->assertSame($avatarUri, $user->getAvatarUri()); $this->assertSame($downloadedData, $user->getDownloadedData()); $this->assertSame($uploadedData, $user->getUploadedData()); }