/** * @param array $params * @param int $limit * @throws \Lertify\Lastfm\Exception\NotFoundException * @return \Lertify\Lastfm\Api\Data\PagedCollection */ private function fetchShouts(array $params, $limit) { /** @var $self \Lertify\Lastfm\Api\Track */ $self = $this; $resultCallback = function ($page, $limit) use($params, $self) { $params = array_merge($params, array('page' => $page, 'limit' => $limit)); $result = $self->get(Track::PREFIX . 'getShouts', $params); $resultShouts = $result['shouts']; if (!isset($resultShouts['shout'])) { throw new NotFoundException('There are no shouts for this atrist and track!'); } if (isset($resultShouts['shout'][0])) { $shouts = $resultShouts['shout']; } else { $shouts = array($resultShouts['shout']); } $totalResults = (int) $resultShouts['@attr']['total']; $totalPages = (int) $resultShouts['@attr']['totalPages']; $List = new ArrayCollection(); foreach ($shouts as $shoutRow) { $Shout = new Data\Track\Shout(); $Shout->setArtist(Util::toSting($resultShouts['@attr']['artist'])); $Shout->setTrack(Util::toSting($resultShouts['@attr']['track'])); $Shout->setBody(Util::toSting($shoutRow['body'])); $Shout->setAuthor(Util::toSting($shoutRow['author'])); $Shout->setDate(Util::toSting($shoutRow['date'])); $List->add($Shout); } return array('results' => $List, 'total_pages' => $totalPages, 'total_results' => $totalResults); }; $PagedCollection = new PagedCollection($resultCallback); $PagedCollection->setLimit($limit); return $PagedCollection; }
/** * @param \Lertify\Lastfm\Api\Data\PagedCollection $PagedCollection */ protected function assertShoutsCollection(PagedCollection $PagedCollection) { $this->assertInternalType('int', $PagedCollection->count(), 'Is not an integer value'); $this->assertInternalType('int', $PagedCollection->countPages(), 'Is not an integer value'); $this->assertFalse($PagedCollection->isEmpty(), 'Current result should not be empty'); $ShoutsCollection = $PagedCollection->getPage(1); $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\Album\\ShoutsCollection', $ShoutsCollection, 'ShoutsCollection is not an instance of Data\\Album\\ShoutsCollection'); $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\ArrayCollection', $ShoutsCollection, 'ShoutsCollection is not an instance of Data\\ArrayCollection'); /** @var \Lertify\Lastfm\Api\Data\Album\Shout $Shout */ foreach ($ShoutsCollection as $Shout) { $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\Album\\Shout', $Shout, 'Shout is not an instance of Data\\Album\\Shout'); $this->assertInstanceOf('DateTime', $Shout->getDate(), 'Shout date is not an instance of DateTime'); } }