From 88d2d4fbe80bef549a102fc5f305c0977b00b7c4 Mon Sep 17 00:00:00 2001 From: Phan An Date: Sun, 10 Dec 2017 01:23:37 +0100 Subject: [PATCH] Apply fixes from StyleCI (#695) --- tests/Integration/Models/FileTest.php | 72 +++--- tests/Integration/Models/InteractionTest.php | 139 ++++++------ tests/Integration/Models/SettingTest.php | 107 +++++---- .../Integration/Models/SongZipArchiveTest.php | 76 +++---- tests/Integration/Models/UserTest.php | 101 +++++---- tests/Integration/Services/LastfmTest.php | 208 +++++++++--------- tests/Integration/Services/MediaCacheTest.php | 85 +++---- tests/Integration/Services/iTunesTest.php | 49 +++-- tests/Unit/Models/ArtistTest.php | 2 - tests/Unit/Models/FileTest.php | 4 +- tests/Unit/Models/InteractionTest.php | 5 - tests/Unit/Models/SongZipArchiveTest.php | 1 - tests/Unit/Models/UserTest.php | 1 - 13 files changed, 423 insertions(+), 427 deletions(-) diff --git a/tests/Integration/Models/FileTest.php b/tests/Integration/Models/FileTest.php index b68ec36c..c2d9ee9f 100644 --- a/tests/Integration/Models/FileTest.php +++ b/tests/Integration/Models/FileTest.php @@ -7,43 +7,43 @@ use Tests\TestCase; class FileTest extends TestCase { - /** @test */ - public function file_info_is_retrieved_correctly() - { - $file = new File(__DIR__ . '/../../songs/full.mp3'); - $info = $file->getInfo(); + /** @test */ + public function file_info_is_retrieved_correctly() + { + $file = new File(__DIR__.'/../../songs/full.mp3'); + $info = $file->getInfo(); - $expectedData = [ - 'artist' => 'Koel', - 'album' => 'Koel Testing Vol. 1', - 'compilation' => false, - 'title' => 'Amet', - 'track' => 5, - 'disc' => 3, - 'lyrics' => "Foo\rbar", - 'cover' => [ - 'data' => file_get_contents(__DIR__ . '/../../blobs/cover.png'), - 'image_mime' => 'image/png', - 'image_width' => 512, - 'image_height' => 512, - 'imagetype' => 'PNG', - 'picturetype' => 'Other', - 'description' => '', - 'datalength' => 7627, - ], - 'path' => __DIR__ . '/../../songs/full.mp3', - 'mtime' => filemtime(__DIR__ . '/../../songs/full.mp3'), - 'albumartist' => '', - ]; + $expectedData = [ + 'artist' => 'Koel', + 'album' => 'Koel Testing Vol. 1', + 'compilation' => false, + 'title' => 'Amet', + 'track' => 5, + 'disc' => 3, + 'lyrics' => "Foo\rbar", + 'cover' => [ + 'data' => file_get_contents(__DIR__.'/../../blobs/cover.png'), + 'image_mime' => 'image/png', + 'image_width' => 512, + 'image_height' => 512, + 'imagetype' => 'PNG', + 'picturetype' => 'Other', + 'description' => '', + 'datalength' => 7627, + ], + 'path' => __DIR__.'/../../songs/full.mp3', + 'mtime' => filemtime(__DIR__.'/../../songs/full.mp3'), + 'albumartist' => '', + ]; - $this->assertArraySubset($expectedData, $info); - $this->assertEquals(10.083, $info['length'], '', 0.001); - } + $this->assertArraySubset($expectedData, $info); + $this->assertEquals(10.083, $info['length'], '', 0.001); + } - /** @test */ - public function song_without_a_title_tag_has_file_name_as_the_title() - { - $file = new File(__DIR__ . '/../../songs/blank.mp3'); - $this->assertSame('blank', $file->getInfo()['title']); - } + /** @test */ + public function song_without_a_title_tag_has_file_name_as_the_title() + { + $file = new File(__DIR__.'/../../songs/blank.mp3'); + $this->assertSame('blank', $file->getInfo()['title']); + } } diff --git a/tests/Integration/Models/InteractionTest.php b/tests/Integration/Models/InteractionTest.php index 21d916e7..f96dff10 100644 --- a/tests/Integration/Models/InteractionTest.php +++ b/tests/Integration/Models/InteractionTest.php @@ -11,86 +11,89 @@ use Tests\TestCase; class InteractionTest extends TestCase { - /** @test */ - public function it_increases_a_songs_play_count() - { - // Given an interaction - /** @var Interaction $interaction */ - $interaction = factory(Interaction::class)->create(); + /** @test */ + public function it_increases_a_songs_play_count() + { + // Given an interaction + /** @var Interaction $interaction */ + $interaction = factory(Interaction::class)->create(); - // When I call the method to increases the song's play count - Interaction::increasePlayCount($interaction->song, $interaction->user); + // When I call the method to increases the song's play count + Interaction::increasePlayCount($interaction->song, $interaction->user); - // Then I see the play count is increased - /** @var Interaction $interaction */ - $updatedInteraction = Interaction::find($interaction->id); - $this->assertEquals($interaction->play_count + 1, $updatedInteraction->play_count); - } + // Then I see the play count is increased + /** @var Interaction $interaction */ + $updatedInteraction = Interaction::find($interaction->id); + $this->assertEquals($interaction->play_count + 1, $updatedInteraction->play_count); + } - /** - * @test - * @throws \Exception - */ - public function it_toggles_like_status() - { - $this->expectsEvents(SongLikeToggled::class); + /** + * @test + * + * @throws \Exception + */ + public function it_toggles_like_status() + { + $this->expectsEvents(SongLikeToggled::class); - // Given an interaction - $interaction = factory(Interaction::class)->create(); + // Given an interaction + $interaction = factory(Interaction::class)->create(); - // When I call the method to toggle the song's like status by user - Interaction::toggleLike($interaction->song, $interaction->user); + // When I call the method to toggle the song's like status by user + Interaction::toggleLike($interaction->song, $interaction->user); - // Then I see the interaction's like status is toggled - /** @var Interaction $interaction */ - $updatedInteraction = Interaction::find($interaction->id); - $this->assertNotSame($interaction->liked, $updatedInteraction->liked); - } + // Then I see the interaction's like status is toggled + /** @var Interaction $interaction */ + $updatedInteraction = Interaction::find($interaction->id); + $this->assertNotSame($interaction->liked, $updatedInteraction->liked); + } - /** - * @test - * @throws \Exception - */ - public function user_can_like_multiple_songs_at_once() - { - $this->expectsEvents(SongLikeToggled::class); + /** + * @test + * + * @throws \Exception + */ + public function user_can_like_multiple_songs_at_once() + { + $this->expectsEvents(SongLikeToggled::class); - // Given multiple song and a user - /** @var Collection $songs */ - $songs = factory(Song::class, 2)->create(); - $user = factory(User::class)->create(); + // Given multiple song and a user + /** @var Collection $songs */ + $songs = factory(Song::class, 2)->create(); + $user = factory(User::class)->create(); - // When I call the method to like songs in batch - Interaction::batchLike($songs->pluck('id')->all(), $user); + // When I call the method to like songs in batch + Interaction::batchLike($songs->pluck('id')->all(), $user); - // Then I see the songs are all liked - $songs->each(function (Song $song) use ($user) { - $this->assertTrue(Interaction::whereSongIdAndUserId($song->id, $user->id)->first()->liked); - }); - } + // Then I see the songs are all liked + $songs->each(function (Song $song) use ($user) { + $this->assertTrue(Interaction::whereSongIdAndUserId($song->id, $user->id)->first()->liked); + }); + } - /** - * @test - * @throws \Exception - */ - public function user_can_unlike_multiple_songs_at_once() - { - $this->expectsEvents(SongLikeToggled::class); + /** + * @test + * + * @throws \Exception + */ + public function user_can_unlike_multiple_songs_at_once() + { + $this->expectsEvents(SongLikeToggled::class); - // Given multiple interaction records - $user = factory(User::class)->create(); - /** @var Collection $interactions */ - $interactions = factory(Interaction::class, 3)->create([ - 'user_id' => $user->id, - 'liked' => true, - ]); + // Given multiple interaction records + $user = factory(User::class)->create(); + /** @var Collection $interactions */ + $interactions = factory(Interaction::class, 3)->create([ + 'user_id' => $user->id, + 'liked' => true, + ]); - // When I call the method to like songs in batch - Interaction::batchUnlike($interactions->pluck('song.id')->all(), $user); + // When I call the method to like songs in batch + Interaction::batchUnlike($interactions->pluck('song.id')->all(), $user); - // Then I see the songs are all liked - $interactions->each(function (Interaction $interaction) { - $this->assertFalse(Interaction::find($interaction->id)->liked); - }); - } + // Then I see the songs are all liked + $interactions->each(function (Interaction $interaction) { + $this->assertFalse(Interaction::find($interaction->id)->liked); + }); + } } diff --git a/tests/Integration/Models/SettingTest.php b/tests/Integration/Models/SettingTest.php index e8166907..347b63cf 100644 --- a/tests/Integration/Models/SettingTest.php +++ b/tests/Integration/Models/SettingTest.php @@ -7,68 +7,67 @@ use Tests\TestCase; class SettingTest extends TestCase { + /** @test */ + public function it_sets_a_key_value_pair() + { + // Given a key-value pair + $key = 'foo'; + $value = 'bar'; - /** @test */ - public function it_sets_a_key_value_pair() - { - // Given a key-value pair - $key = 'foo'; - $value = 'bar'; + // When I call the method to save the key-value + Setting::set($key, $value); - // When I call the method to save the key-value - Setting::set($key, $value); + // Then I see the key and serialized value in the database + $this->assertDatabaseHas('settings', [ + 'key' => 'foo', + 'value' => serialize('bar'), + ]); + } - // Then I see the key and serialized value in the database - $this->assertDatabaseHas('settings', [ - 'key' => 'foo', - 'value' => serialize('bar'), - ]); - } + /** @test */ + public function it_supports_associative_arrays_when_saving_settings() + { + // Given an associative array of multiple settings + $settings = [ + 'foo' => 'bar', + 'baz' => 'qux', + ]; - /** @test */ - public function it_supports_associative_arrays_when_saving_settings() - { - // Given an associative array of multiple settings - $settings = [ - 'foo' => 'bar', - 'baz' => 'qux', - ]; + // When I call the method to save the settings + Setting::set($settings); - // When I call the method to save the settings - Setting::set($settings); + // Then I see all settings the database + $this->assertDatabaseHas('settings', [ + 'key' => 'foo', + 'value' => serialize('bar'), + ])->assertDatabaseHas('settings', [ + 'key' => 'baz', + 'value' => serialize('qux'), + ]); + } - // Then I see all settings the database - $this->assertDatabaseHas('settings', [ - 'key' => 'foo', - 'value' => serialize('bar'), - ])->assertDatabaseHas('settings', [ - 'key' => 'baz', - 'value' => serialize('qux'), - ]); - } + /** @test */ + public function existing_settings_should_be_updated() + { + Setting::set('foo', 'bar'); + Setting::set('foo', 'baz'); - /** @test */ - public function existing_settings_should_be_updated() - { - Setting::set('foo', 'bar'); - Setting::set('foo', 'baz'); + $this->assertEquals('baz', Setting::get('foo')); + } - $this->assertEquals('baz', Setting::get('foo')); - } + /** @test */ + public function it_gets_the_setting_value_in_an_unserialized_format() + { + // Given a setting in the database + factory(Setting::class)->create([ + 'key' => 'foo', + 'value' => 'bar', + ]); - /** @test */ - public function it_gets_the_setting_value_in_an_unserialized_format() - { - // Given a setting in the database - factory(Setting::class)->create([ - 'key' => 'foo', - 'value' => 'bar', - ]); + // When I get the setting using the key + $value = Setting::get('foo'); - // When I get the setting using the key - $value = Setting::get('foo'); - - // Then I receive the value in an unserialized format - $this->assertSame('bar', $value); - } + // Then I receive the value in an unserialized format + $this->assertSame('bar', $value); + } } diff --git a/tests/Integration/Models/SongZipArchiveTest.php b/tests/Integration/Models/SongZipArchiveTest.php index af738059..67828f1a 100644 --- a/tests/Integration/Models/SongZipArchiveTest.php +++ b/tests/Integration/Models/SongZipArchiveTest.php @@ -8,49 +8,49 @@ use Tests\TestCase; class SongZipArchiveTest extends TestCase { - /** @test */ - public function a_song_can_be_added_into_an_archive() - { - // Given a song - $song = factory(Song::class)->create([ - 'path' => realpath(__DIR__ . '/../../songs/full.mp3'), - ]); + /** @test */ + public function a_song_can_be_added_into_an_archive() + { + // Given a song + $song = factory(Song::class)->create([ + 'path' => realpath(__DIR__.'/../../songs/full.mp3'), + ]); - // When I add the song into the archive - $songArchive = new SongZipArchive(); - $songArchive->addSong($song); + // When I add the song into the archive + $songArchive = new SongZipArchive(); + $songArchive->addSong($song); - // Then I see the archive contains one file - $archive = $songArchive->getArchive(); - $this->assertEquals(1, $archive->numFiles); + // Then I see the archive contains one file + $archive = $songArchive->getArchive(); + $this->assertEquals(1, $archive->numFiles); - // and the file is our song - $this->assertEquals('full.mp3', $archive->getNameIndex(0)); - } + // and the file is our song + $this->assertEquals('full.mp3', $archive->getNameIndex(0)); + } - /** @test */ - public function multiple_songs_can_be_added_into_an_archive() - { - // Given some songs - $songs = collect([ - factory(Song::class)->create([ - 'path' => realpath(__DIR__ . '/../../songs/full.mp3'), - ]), - factory(Song::class)->create([ - 'path' => realpath(__DIR__ . '/../../songs/lorem.mp3'), - ]), - ]); + /** @test */ + public function multiple_songs_can_be_added_into_an_archive() + { + // Given some songs + $songs = collect([ + factory(Song::class)->create([ + 'path' => realpath(__DIR__.'/../../songs/full.mp3'), + ]), + factory(Song::class)->create([ + 'path' => realpath(__DIR__.'/../../songs/lorem.mp3'), + ]), + ]); - // When I add the songs into the archive - $songArchive = new SongZipArchive(); - $songArchive->addSongs($songs); + // When I add the songs into the archive + $songArchive = new SongZipArchive(); + $songArchive->addSongs($songs); - // Then I see the archive contains two files - $archive = $songArchive->getArchive(); - $this->assertEquals(2, $archive->numFiles); + // Then I see the archive contains two files + $archive = $songArchive->getArchive(); + $this->assertEquals(2, $archive->numFiles); - // and the files are our songs - $this->assertEquals('full.mp3', $archive->getNameIndex(0)); - $this->assertEquals('lorem.mp3', $archive->getNameIndex(1)); - } + // and the files are our songs + $this->assertEquals('full.mp3', $archive->getNameIndex(0)); + $this->assertEquals('lorem.mp3', $archive->getNameIndex(1)); + } } diff --git a/tests/Integration/Models/UserTest.php b/tests/Integration/Models/UserTest.php index 5009c681..92efc3ec 100644 --- a/tests/Integration/Models/UserTest.php +++ b/tests/Integration/Models/UserTest.php @@ -7,66 +7,65 @@ use Tests\TestCase; class UserTest extends TestCase { + /** @test */ + public function user_preferences_can_be_set() + { + // Given a user + /** @var User $user */ + $user = factory(User::class)->create(); - /** @test */ - public function user_preferences_can_be_set() - { - // Given a user - /** @var User $user */ - $user = factory(User::class)->create(); + // When I see the user's preference + $user->setPreference('foo', 'bar'); - // When I see the user's preference - $user->setPreference('foo', 'bar'); + // Then I see the preference properly set + $this->assertArraySubset(['foo' => 'bar'], $user->preferences); + } - // Then I see the preference properly set - $this->assertArraySubset(['foo' => 'bar'], $user->preferences); - } + /** @test */ + public function user_preferences_can_be_retrieved() + { + // Given a user with some preferences + /** @var User $user */ + $user = factory(User::class)->create([ + 'preferences' => ['foo' => 'bar'], + ]); - /** @test */ - public function user_preferences_can_be_retrieved() - { - // Given a user with some preferences - /** @var User $user */ - $user = factory(User::class)->create([ - 'preferences' => ['foo' => 'bar'], - ]); + // When I get a preference by its key + $value = $user->getPreference('foo'); - // When I get a preference by its key - $value = $user->getPreference('foo'); + // Then I retrieve the preference value + $this->assertEquals('bar', $value); + } - // Then I retrieve the preference value - $this->assertEquals('bar', $value); - } + /** @test */ + public function user_preferences_can_be_deleted() + { + // Given a user with some preferences + /** @var User $user */ + $user = factory(User::class)->create([ + 'preferences' => ['foo' => 'bar'], + ]); - /** @test */ - public function user_preferences_can_be_deleted() - { - // Given a user with some preferences - /** @var User $user */ - $user = factory(User::class)->create([ - 'preferences' => ['foo' => 'bar'], - ]); + // When I delete the preference by its key + $user->deletePreference('foo'); - // When I delete the preference by its key - $user->deletePreference('foo'); + // Then I see the preference gets deleted + $this->assertArrayNotHasKey('foo', $user->preferences); + } - // Then I see the preference gets deleted - $this->assertArrayNotHasKey('foo', $user->preferences); - } + /** @test */ + public function sensitive_preferences_are_hidden() + { + // Given a user with sensitive preferences + /** @var User $user */ + $user = factory(User::class)->create([ + 'preferences' => ['lastfm_session_key' => 'foo'], + ]); - /** @test */ - public function sensitive_preferences_are_hidden() - { - // Given a user with sensitive preferences - /** @var User $user */ - $user = factory(User::class)->create([ - 'preferences' => ['lastfm_session_key' => 'foo'], - ]); + // When I try to access the sensitive preferences + $value = $user->preferences['lastfm_session_key']; - // When I try to access the sensitive preferences - $value = $user->preferences['lastfm_session_key']; - - // Then the sensitive preferences are replaced with "hidden" - $this->assertEquals('hidden', $value); - } + // Then the sensitive preferences are replaced with "hidden" + $this->assertEquals('hidden', $value); + } } diff --git a/tests/Integration/Services/LastfmTest.php b/tests/Integration/Services/LastfmTest.php index 6fc091f4..d60d91ad 100644 --- a/tests/Integration/Services/LastfmTest.php +++ b/tests/Integration/Services/LastfmTest.php @@ -12,125 +12,127 @@ use Tests\TestCase; class LastfmTest extends TestCase { - protected function tearDown() - { - m::close(); - parent::tearDown(); - } + protected function tearDown() + { + m::close(); + parent::tearDown(); + } - /** - * @test - * @throws \Exception - */ - public function it_returns_artist_info_if_artist_is_found_on_lastfm() - { - // Given an artist that exists on Last.fm - /** @var Artist $artist */ - $artist = factory(Artist::class)->create(['name' => 'foo']); + /** + * @test + * + * @throws \Exception + */ + public function it_returns_artist_info_if_artist_is_found_on_lastfm() + { + // Given an artist that exists on Last.fm + /** @var Artist $artist */ + $artist = factory(Artist::class)->create(['name' => 'foo']); - // When I request the service for the artist's info - $client = m::mock(Client::class, [ - 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/lastfm/artist.xml')), - ]); + // When I request the service for the artist's info + $client = m::mock(Client::class, [ + 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/lastfm/artist.xml')), + ]); - $api = new Lastfm(null, null, $client); - $info = $api->getArtistInfo($artist->name); + $api = new Lastfm(null, null, $client); + $info = $api->getArtistInfo($artist->name); - // Then I see the info when the request is the successful - $this->assertEquals([ - 'url' => 'http://www.last.fm/music/Kamelot', - 'image' => 'http://foo.bar/extralarge.jpg', - 'bio' => [ - 'summary' => 'Quisque ut nisi.', - 'full' => 'Quisque ut nisi. Vestibulum ullamcorper mauris at ligula.', - ], - ], $info); + // Then I see the info when the request is the successful + $this->assertEquals([ + 'url' => 'http://www.last.fm/music/Kamelot', + 'image' => 'http://foo.bar/extralarge.jpg', + 'bio' => [ + 'summary' => 'Quisque ut nisi.', + 'full' => 'Quisque ut nisi. Vestibulum ullamcorper mauris at ligula.', + ], + ], $info); - // And the response XML is cached as well - $this->assertNotNull(cache('0aff3bc1259154f0e9db860026cda7a6')); - } + // And the response XML is cached as well + $this->assertNotNull(cache('0aff3bc1259154f0e9db860026cda7a6')); + } - /** @test */ - public function it_returns_false_if_artist_info_is_not_found_on_lastfm() - { - // Given an artist that doesn't exist on Last.fm - /** @var Artist $artist */ - $artist = factory(Artist::class)->create(); + /** @test */ + public function it_returns_false_if_artist_info_is_not_found_on_lastfm() + { + // Given an artist that doesn't exist on Last.fm + /** @var Artist $artist */ + $artist = factory(Artist::class)->create(); - // When I request the service for the artist info - $client = m::mock(Client::class, [ - 'get' => new Response(400, [], file_get_contents(__DIR__.'../../../blobs/lastfm/artist-notfound.xml')), - ]); + // When I request the service for the artist info + $client = m::mock(Client::class, [ + 'get' => new Response(400, [], file_get_contents(__DIR__.'../../../blobs/lastfm/artist-notfound.xml')), + ]); - $api = new Lastfm(null, null, $client); - $result = $api->getArtistInfo($artist->name); + $api = new Lastfm(null, null, $client); + $result = $api->getArtistInfo($artist->name); - // Then I receive boolean false - $this->assertFalse($result); - } + // Then I receive boolean false + $this->assertFalse($result); + } - /** - * @test - * @throws \Exception - */ - public function it_returns_album_info_if_album_is_found_on_lastfm() - { - // Given an album that exists on Last.fm - /** @var Album $album */ - $album = factory(Album::class)->create([ - 'artist_id' => factory(Artist::class)->create(['name' => 'bar'])->id, - 'name' => 'foo', - ]); + /** + * @test + * + * @throws \Exception + */ + public function it_returns_album_info_if_album_is_found_on_lastfm() + { + // Given an album that exists on Last.fm + /** @var Album $album */ + $album = factory(Album::class)->create([ + 'artist_id' => factory(Artist::class)->create(['name' => 'bar'])->id, + 'name' => 'foo', + ]); - // When I request the service for the album's info - $client = m::mock(Client::class, [ - 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/lastfm/album.xml')), - ]); + // When I request the service for the album's info + $client = m::mock(Client::class, [ + 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/lastfm/album.xml')), + ]); - $api = new Lastfm(null, null, $client); - $info = $api->getAlbumInfo($album->name, $album->artist->name); + $api = new Lastfm(null, null, $client); + $info = $api->getAlbumInfo($album->name, $album->artist->name); - // Then I get the album's info - $this->assertEquals([ - 'url' => 'http://www.last.fm/music/Kamelot/Epica', - 'image' => 'http://foo.bar/extralarge.jpg', - 'tracks' => [ - [ - 'title' => 'Track 1', - 'url' => 'http://foo/track1', - 'length' => 100, - ], - [ - 'title' => 'Track 2', - 'url' => 'http://foo/track2', - 'length' => 150, - ], - ], - 'wiki' => [ - 'summary' => 'Quisque ut nisi.', - 'full' => 'Quisque ut nisi. Vestibulum ullamcorper mauris at ligula.', - ], - ], $info); + // Then I get the album's info + $this->assertEquals([ + 'url' => 'http://www.last.fm/music/Kamelot/Epica', + 'image' => 'http://foo.bar/extralarge.jpg', + 'tracks' => [ + [ + 'title' => 'Track 1', + 'url' => 'http://foo/track1', + 'length' => 100, + ], + [ + 'title' => 'Track 2', + 'url' => 'http://foo/track2', + 'length' => 150, + ], + ], + 'wiki' => [ + 'summary' => 'Quisque ut nisi.', + 'full' => 'Quisque ut nisi. Vestibulum ullamcorper mauris at ligula.', + ], + ], $info); - // And the response is cached - $this->assertNotNull(cache('fca889d13b3222589d7d020669cc5a38')); - } + // And the response is cached + $this->assertNotNull(cache('fca889d13b3222589d7d020669cc5a38')); + } - /** @test */ - public function it_returns_false_if_album_info_is_not_found_on_lastfm() - { - // Given there's an album which doesn't exist on Last.fm - $album = factory(Album::class)->create(); + /** @test */ + public function it_returns_false_if_album_info_is_not_found_on_lastfm() + { + // Given there's an album which doesn't exist on Last.fm + $album = factory(Album::class)->create(); - // When I request the service for the album's info - $client = m::mock(Client::class, [ - 'get' => new Response(400, [], file_get_contents(__DIR__.'../../../blobs/lastfm/album-notfound.xml')), - ]); + // When I request the service for the album's info + $client = m::mock(Client::class, [ + 'get' => new Response(400, [], file_get_contents(__DIR__.'../../../blobs/lastfm/album-notfound.xml')), + ]); - $api = new Lastfm(null, null, $client); - $result = $api->getAlbumInfo($album->name, $album->artist->name); + $api = new Lastfm(null, null, $client); + $result = $api->getAlbumInfo($album->name, $album->artist->name); - // Then I receive a boolean false - $this->assertFalse($result); - } + // Then I receive a boolean false + $this->assertFalse($result); + } } diff --git a/tests/Integration/Services/MediaCacheTest.php b/tests/Integration/Services/MediaCacheTest.php index 6dcb2ad6..b3e45604 100644 --- a/tests/Integration/Services/MediaCacheTest.php +++ b/tests/Integration/Services/MediaCacheTest.php @@ -11,57 +11,58 @@ use Tests\TestCase; class MediaCacheTest extends TestCase { - /** @test */ - public function it_queries_fresh_data_from_database_or_use_the_cache() - { - // Given a database with artists, albums, and songs - factory(Song::class, 5)->create(); + /** @test */ + public function it_queries_fresh_data_from_database_or_use_the_cache() + { + // Given a database with artists, albums, and songs + factory(Song::class, 5)->create(); - Cache::shouldReceive('rememberForever')->andReturn([ - 'albums' => Album::orderBy('name')->get(), - 'artists' => Artist::orderBy('name')->get(), - 'songs' => Song::all(), - ]); + Cache::shouldReceive('rememberForever')->andReturn([ + 'albums' => Album::orderBy('name')->get(), + 'artists' => Artist::orderBy('name')->get(), + 'songs' => Song::all(), + ]); - // When I get data from the MediaCache service - $data = MediaCache::get(); + // When I get data from the MediaCache service + $data = MediaCache::get(); - // Then a complete set of data is retrieved - $this->assertCount(6, $data['albums']); // 5 new albums and the default Unknown Album - $this->assertCount(7, $data['artists']); // 5 new artists and the default Various and Unknown Artist - $this->assertCount(5, $data['songs']); - } + // Then a complete set of data is retrieved + $this->assertCount(6, $data['albums']); // 5 new albums and the default Unknown Album + $this->assertCount(7, $data['artists']); // 5 new artists and the default Various and Unknown Artist + $this->assertCount(5, $data['songs']); + } - /** @test */ - public function it_get_the_cached_data_if_found() - { - // Given there are media data cached - Cache::shouldReceive('rememberForever')->andReturn('dummy'); + /** @test */ + public function it_get_the_cached_data_if_found() + { + // Given there are media data cached + Cache::shouldReceive('rememberForever')->andReturn('dummy'); - // And koel.cache_media configuration is TRUE - config(['koel.cache_media' => true]); + // And koel.cache_media configuration is TRUE + config(['koel.cache_media' => true]); - // When I get data from the MediaCache service - $data = MediaCache::get(); + // When I get data from the MediaCache service + $data = MediaCache::get(); - // Then I receive the cached version - $this->assertEquals('dummy', $data); - } + // Then I receive the cached version + $this->assertEquals('dummy', $data); + } - /** - * @test - * @throws \Exception - */ - public function it_does_not_cache_queried_data_if_cache_media_is_configured_to_false() - { - Cache::shouldReceive('rememberForever')->never(); + /** + * @test + * + * @throws \Exception + */ + public function it_does_not_cache_queried_data_if_cache_media_is_configured_to_false() + { + Cache::shouldReceive('rememberForever')->never(); - // Given koel.cache_media configuration is FALSE - config(['koel.cache_media' => false]); + // Given koel.cache_media configuration is FALSE + config(['koel.cache_media' => false]); - // When I get data from the MediaCache service - MediaCache::get(); + // When I get data from the MediaCache service + MediaCache::get(); - // Then I don't see the cache-related methods being called - } + // Then I don't see the cache-related methods being called + } } diff --git a/tests/Integration/Services/iTunesTest.php b/tests/Integration/Services/iTunesTest.php index 2efcbc7b..2e8331b1 100644 --- a/tests/Integration/Services/iTunesTest.php +++ b/tests/Integration/Services/iTunesTest.php @@ -10,33 +10,34 @@ use Tests\TestCase; class iTunesTest extends TestCase { - public function tearDown() - { - m::close(); - parent::tearDown(); - } + public function tearDown() + { + m::close(); + parent::tearDown(); + } - /** - * @test - * @throws \Exception - */ - public function it_gets_itunes_track_url() - { - // Given there's a search term - $term = 'Foo Bar'; + /** + * @test + * + * @throws \Exception + */ + public function it_gets_itunes_track_url() + { + // Given there's a search term + $term = 'Foo Bar'; - // When I request the iTunes track URL for the song - $client = m::mock(Client::class, [ - 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/itunes/track.json')), - ]); + // When I request the iTunes track URL for the song + $client = m::mock(Client::class, [ + 'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/itunes/track.json')), + ]); - $url = (new iTunes($client))->getTrackUrl($term); + $url = (new iTunes($client))->getTrackUrl($term); - // Then I retrieve the track URL - $this->assertEquals('https://itunes.apple.com/us/album/i-remember-you/id265611220?i=265611396&uo=4&at=1000lsGu', - $url); + // Then I retrieve the track URL + $this->assertEquals('https://itunes.apple.com/us/album/i-remember-you/id265611220?i=265611396&uo=4&at=1000lsGu', + $url); - // And the track url is cached - $this->assertNotNull(cache('b57a14784d80c58a856e0df34ff0c8e2')); - } + // And the track url is cached + $this->assertNotNull(cache('b57a14784d80c58a856e0df34ff0c8e2')); + } } diff --git a/tests/Unit/Models/ArtistTest.php b/tests/Unit/Models/ArtistTest.php index c8331678..a2cbc02f 100644 --- a/tests/Unit/Models/ArtistTest.php +++ b/tests/Unit/Models/ArtistTest.php @@ -3,8 +3,6 @@ namespace Tests\Unit\Models; use App\Models\Artist; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use org\bovigo\vfs\vfsStream; use Tests\TestCase; class ArtistTest extends TestCase diff --git a/tests/Unit/Models/FileTest.php b/tests/Unit/Models/FileTest.php index 82ed5f5e..321ad9a5 100644 --- a/tests/Unit/Models/FileTest.php +++ b/tests/Unit/Models/FileTest.php @@ -11,9 +11,9 @@ class FileTest extends TestCase /** @test */ public function it_can_be_instantiated() { - $file = new File(__DIR__ . '/../songs/full.mp3'); + $file = new File(__DIR__.'/../songs/full.mp3'); $this->assertInstanceOf(File::class, $file); - $file = new File(new SplFileInfo(__DIR__ . '/../songs/full.mp3')); + $file = new File(new SplFileInfo(__DIR__.'/../songs/full.mp3')); $this->assertInstanceOf(File::class, $file); } } diff --git a/tests/Unit/Models/InteractionTest.php b/tests/Unit/Models/InteractionTest.php index 21a15d14..941f873a 100644 --- a/tests/Unit/Models/InteractionTest.php +++ b/tests/Unit/Models/InteractionTest.php @@ -2,11 +2,7 @@ namespace Tests\Unit\Models; -use App\Events\SongLikeToggled; use App\Models\Interaction; -use App\Models\Song; -use App\Models\User; -use Illuminate\Support\Collection; use Tests\TestCase; class InteractionTest extends TestCase @@ -16,5 +12,4 @@ class InteractionTest extends TestCase { $this->assertInstanceOf(Interaction::class, new Interaction()); } - } diff --git a/tests/Unit/Models/SongZipArchiveTest.php b/tests/Unit/Models/SongZipArchiveTest.php index aa392fda..9da82f7b 100644 --- a/tests/Unit/Models/SongZipArchiveTest.php +++ b/tests/Unit/Models/SongZipArchiveTest.php @@ -2,7 +2,6 @@ namespace Tests\Unit\Models; -use App\Models\Song; use App\Models\SongZipArchive; use Tests\TestCase; diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php index f3b74919..b7b9319d 100644 --- a/tests/Unit/Models/UserTest.php +++ b/tests/Unit/Models/UserTest.php @@ -12,5 +12,4 @@ class UserTest extends TestCase { $this->assertInstanceOf(User::class, new User()); } - }