Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function testInstance()
 {
     $root = new Category();
     $rootName = 'Video';
     $root->setName($rootName);
     $rootId = 102;
     $root->setId($rootId);
     $subCategoryMovies = new Category();
     $subCategoryMovies->setId(202);
     $subCategoryMovies->setName('Movies');
     $subCategoryMovies->setParentCategory($root);
     $subCategoryCartoons = new Category();
     $subCategoryCartoons->setId(203);
     $subCategoryCartoons->setName('Cartoons');
     $subCategoryCartoons->setParentCategory($root);
     $root->setSubCategories([$subCategoryMovies, $subCategoryCartoons]);
     $categoryInterface = '\\Martial\\T411\\Api\\Category\\CategoryInterface';
     $this->assertInstanceOf($categoryInterface, $root);
     $this->assertSame($rootId, $root->getId());
     $this->assertSame($rootName, $root->getName());
     $this->assertContainsOnly($categoryInterface, $root->getSubCategories());
     $this->assertSame($root, $subCategoryCartoons->getParentCategory());
 }