Exemplo n.º 1
0
 /**
  * Test an empty Group entity
  */
 public function testEmptyGroup()
 {
     $group = new Group();
     $this->assertNull($group->getId());
     $this->assertNull($group->getName());
     $this->assertNull($group->getDescription());
     $this->assertNull($group->getCreatedBy());
     $this->assertNull($group->getUpdatedBy());
     $this->assertNull($group->getSlug());
 }
 /**
  * Find Album group
  *
  * @param Group  $group Group
  * @param string $album Album
  *
  * @throws BadRequestHttpException
  *
  * @return []
  */
 public function findAlbumGroup($group, $album)
 {
     $response = $this->client->get($this->lastFmApiUrl, ['query' => ['method' => 'album.getinfo', 'artist' => $group->getName(), 'album' => $album, 'api_key' => $this->lastFmKey, 'format' => 'json']]);
     $data = json_decode((string) $response->getBody()->getContents(), true);
     if (array_key_exists('error', $data)) {
         throw new BadRequestHttpException('Не правильний запит');
     }
     $durationMinutes = 0;
     $album = $data['album'];
     if (!array_key_exists('wiki', $album)) {
         $album['wiki']['published'] = 'Не відомо';
     }
     foreach ($album['tracks']['track'] as $track) {
         $durationMinutes += $track['duration'];
     }
     $album['duration'] = ['hour' => round($durationMinutes / 60), 'minute' => $durationMinutes % 60];
     $album['groupSlug'] = $group->getSlug();
     return $album;
 }