Exemplo n.º 1
0
 /**
  * Search for a track and build the response objects
  *
  * @param string $string
  *
  * @return Track
  */
 public function findTrack(string $string)
 {
     $result = $this->spotifyWebApi->search($string, 'track');
     if (count($result->tracks->items) === 0) {
         throw NoTracksFoundException::emptyResult();
     }
     $firstItem = $result->tracks->items[0];
     $images = $this->valueObjectBuilder->buildImages($firstItem->album->images);
     $album = $this->valueObjectBuilder->buildAlbumSimplified($firstItem->album, $images);
     $artists = $this->valueObjectBuilder->buildArtistsSimplified($firstItem->artists);
     $track = $this->valueObjectBuilder->buildTrack($firstItem, $album, $artists);
     return $track;
 }
 public function testGetSongsFromSpotifyIgnoresEmpty()
 {
     $song = new Song();
     $song->setTitle('Foo song')->setArtist('Bar');
     $song2 = new Song();
     $song2->setTitle('Baz song')->setArtist('Qux');
     $spotifyTrack = new Track();
     $spotifyTrack->setId('aoeu')->setSpotifyUri('spotify:track:something');
     // First track found
     $this->trackFinder->expects($this->at(0))->method('findTrack')->willReturn($spotifyTrack);
     // 2nd track not found with restrictive search
     $this->trackFinder->expects($this->at(1))->method('findTrack')->willThrowException(NoTracksFoundException::emptyResult());
     // 2nd track not found with loose search either
     $this->trackFinder->expects($this->at(2))->method('findTrack')->willThrowException(NoTracksFoundException::emptyResult());
     $result = $this->trackConverter->getSongsFromSpotify([$song, $song2], false);
     $this->assertCount(1, $result, 'Only 1 track should be returned');
 }