From c115c3c157edf42a7b3ec61c859f3c84d78e5bc1 Mon Sep 17 00:00:00 2001 From: Jonathan Wilsson Date: Thu, 14 Dec 2023 17:43:20 +0100 Subject: [PATCH] Correct return value of SpotifyWebAPI::getSnapshotId() --- src/SpotifyWebAPI.php | 2 +- tests/SpotifyWebAPITest.php | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/SpotifyWebAPI.php b/src/SpotifyWebAPI.php index fa8f574..d86599c 100644 --- a/src/SpotifyWebAPI.php +++ b/src/SpotifyWebAPI.php @@ -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; } /** diff --git a/tests/SpotifyWebAPITest.php b/tests/SpotifyWebAPITest.php index 3c7e6bd..6476357 100644 --- a/tests/SpotifyWebAPITest.php +++ b/tests/SpotifyWebAPITest.php @@ -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']; @@ -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 = [ @@ -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];