Skip to content

Commit

Permalink
Add null return type to SpotifyWebAPI::getMyCurrentTrack() and Spotif…
Browse files Browse the repository at this point in the history
…yWebAPI::getMyCurrentPlaybackInfo()

Closes #269
  • Loading branch information
jwilsson committed Dec 14, 2023
1 parent c115c3c commit 776d063
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/SpotifyWebAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,10 @@ public function getMultipleAudioFeatures(string|array $trackIds): array|object
* - string market Optional. ISO 3166-1 alpha-2 country code, provide this if you wish to apply Track Relinking.
* - string|array additional_types Optional. Types of media to return info about.
*
* @return array|object The user's currently playing track. Type is controlled by the `return_assoc` option.
* @return array|object|null The user's currently playing track or null if nothing's currently playing.
* Type is controlled by the `return_assoc` option.
*/
public function getMyCurrentTrack(array|object $options = []): array|object
public function getMyCurrentTrack(array|object $options = []): array|object|null
{
$uri = '/v1/me/player/currently-playing';
$options = (array) $options;
Expand Down Expand Up @@ -1172,9 +1173,10 @@ public function getMyDevices(): array|object
* - string market Optional. ISO 3166-1 alpha-2 country code, provide this if you wish to apply Track Relinking.
* - string|array additional_types Optional. Types of media to return info about.
*
* @return array|object The user's playback information. Type is controlled by the `return_assoc` option.
* @return array|object|null The user's playback information or null if nothing's currently playing.
* Type is controlled by the `return_assoc` option.
*/
public function getMyCurrentPlaybackInfo(array|object $options = []): array|object
public function getMyCurrentPlaybackInfo(array|object $options = []): array|object|null
{
$uri = '/v1/me/player';
$options = (array) $options;
Expand Down
32 changes: 32 additions & 0 deletions tests/SpotifyWebAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,22 @@ public function testGetMyCurrentTrack()
$this->assertObjectHasProperty('item', $response);
}

public function testGetMyCurrentTrackEmptyResponse()
{
$return = ['body' => null];
$api = $this->setupApi(
'GET',
'/v1/me/player/currently-playing',
[],
[],
$return
);

$response = $api->getMyCurrentTrack([]);

$this->assertNull($response);
}

public function testGetMyDevices()
{
$return = ['body' => get_fixture('user-devices')];
Expand Down Expand Up @@ -1308,6 +1324,22 @@ public function testGetMyCurrentPlaybackInfo()
$this->assertObjectHasProperty('item', $response);
}

public function testGetMyCurrentPlaybackInfoEmptyResponse()
{
$return = ['body' => null];
$api = $this->setupApi(
'GET',
'/v1/me/player',
[],
[],
$return
);

$response = $api->getMyCurrentPlaybackInfo([]);

$this->assertNull($response);
}

public function testGetMyPlaylists()
{
$options = ['limit' => 10];
Expand Down

0 comments on commit 776d063

Please sign in to comment.