Skip to content

Commit

Permalink
Correct return value of SpotifyWebAPI::getSnapshotId()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilsson committed Dec 14, 2023
1 parent f328500 commit c115c3c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SpotifyWebAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getSnapshotId(array|object $body): string|bool
{
$body = (array) $body;

return $body['snapshot_id'] ?? null;
return $body['snapshot_id'] ?? false;
}

/**
Expand Down
72 changes: 72 additions & 0 deletions tests/SpotifyWebAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ public function testAddPlaylistTracks()
);
}

public function testAddPlaylistTracksNoSnapshotId()
{
$expected = json_encode([
'uris' => [],
]);

$headers = ['Content-Type' => 'application/json'];
$return = ['body' => []];
$api = $this->setupApi(
'POST',
'/v1/playlists/0UZ0Ll4HJHR7yvURYbHJe9/tracks',
$expected,
$headers,
$return
);

$this->assertFalse(
$api->addPlaylistTracks(
'spotify:playlist:0UZ0Ll4HJHR7yvURYbHJe9',
[],
[]
)
);
}

public function testChangeMyDevice()
{
$options = ['device_ids' => 'abc123'];
Expand Down Expand Up @@ -617,6 +642,30 @@ public function testDeletePlaylistTracksPositions()
);
}

public function testDeletePlaylistTracksNoSnapshotId()
{
$expected = json_encode([
'positions' => [],
]);

$headers = ['Content-Type' => 'application/json'];
$return = ['body' => []];
$api = $this->setupApi(
'DELETE',
'/v1/playlists/0UZ0Ll4HJHR7yvURYbHJe9/tracks',
$expected,
$headers,
$return
);

$this->assertFalse(
$api->deletePlaylistTracks(
'spotify:playlist:0UZ0Ll4HJHR7yvURYbHJe9',
['positions' => []]
)
);
}

public function testFollowArtistsOrUsers()
{
$options = [
Expand Down Expand Up @@ -2014,6 +2063,29 @@ public function testReorderPlaylistTracks()
);
}

public function testReorderPlaylistTracksNoSnapshotId()
{
$expected = json_encode([
]);

$headers = ['Content-Type' => 'application/json'];
$return = ['body' => []];
$api = $this->setupApi(
'PUT',
'/v1/playlists/0UZ0Ll4HJHR7yvURYbHJe9/tracks',
$expected,
$headers,
$return
);

$this->assertFalse(
$api->reorderPlaylistTracks(
'spotify:playlist:0UZ0Ll4HJHR7yvURYbHJe9',
[]
)
);
}

public function testRepeat()
{
$return = ['status' => 204];
Expand Down

0 comments on commit c115c3c

Please sign in to comment.