public function testSearchAlbumReturnsAListOfAlbums() { $track_list = new ArrayCollection(array(Album::create('id', 'Album 1'), Album::create('id2', 'Album 2'))); $repository = $this->getMock('Naxhh\\PlayCool\\Domain\\Contract\\AlbumRepository'); $repository->expects($this->any())->method('getListByName')->will($this->returnValue($track_list)); $command = new SearchAlbumCommand('Search term'); $use_case = new SearchAlbumUseCase($repository); $album_list = $use_case->handle($command); $this->assertCount(2, $album_list); $this->assertInstanceOf('Naxhh\\Playcool\\Domain\\Entity\\Album', $album_list->get(1)); }
/** * Retrieves the artist with the given identity. * * @param ArtistIdentity $identity The identity of the artist to retrieve. * @return Domain\Entity\Artist * @throws Domain\Exception\ArtistNotFoundException If no artist has the requested identity. */ public function get(ArtistIdentity $identity) { try { $artist_raw = $this->spotify_api->getArtist($identity->getId()); $artist_albums = $this->spotify_api->getArtistAlbums($identity->getId()); $artist = Artist::create($artist_raw->id, $artist_raw->name); foreach ($artist_albums->items as $album) { $artist->addAlbum(Album::create($album->id, $album->name)); } return $artist; } catch (NotFoundException $e) { throw new ArtistNotFoundException(); } }
/** * Retrieves a list of albums that match the given name. * * @param string $name The name to search for. * @return Domain\Entity\Album[] */ public function getListByName($name) { $result = $this->spotify_api->search($name); if (!isset($result->albums->items)) { return array(); } $result = $result->albums->items; $albums = array(); foreach ($result as $artist) { $albums[] = Album::create($artist->id, $artist->name); } unset($result); return $albums; }