Skip to content

Commit d7e40a6

Browse files
committed
feat(tests): Add test to verify downloaded music exists
- Use `File::files()` to check if files exist in the download directory - Skip test on non-Darwin operating systems - Depends on 'chore(tests): Clean download directory before searching and downloading music'
1 parent e6dd388 commit d7e40a6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ tests.php
1717
.history/
1818
music-dl.phar
1919
/.env
20+
Download/

tests/Feature/MusicCommandTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,37 @@
1111
*/
1212

1313
use App\Commands\MusicCommand;
14+
use Illuminate\Support\Facades\File;
1415
use Mockery\Exception\InvalidOrderException;
1516

17+
beforeEach(function (): void {
18+
$this->downloadDir = base_path('tests/Download');
19+
});
20+
1621
it('can search and download music', function (): void {
22+
File::cleanDirectory($this->downloadDir);
23+
1724
$this
1825
->artisan(MusicCommand::class, [
1926
'keyword' => '不只是南方',
2027
'--driver' => 'fork',
28+
'--dir' => base_path('tests/Download'),
2129
'--sources' => 'netease',
2230
])
2331
->expectsConfirmation(config('music-dl.confirm_download'), 'yes')
2432
->expectsQuestion(config('music-dl.download_choice_tip'), '下载所有歌曲')
2533
->assertSuccessful();
26-
})->group(__DIR__, __FILE__)->throws(InvalidOrderException::class);
34+
})
35+
->group(__DIR__, __FILE__)
36+
->throws(InvalidOrderException::class)
37+
->skip(PHP_OS_FAMILY !== 'Darwin');
38+
39+
it('can find downloaded music', function (): void {
40+
expect(File::files($this->downloadDir))
41+
->toBeArray()
42+
->toBeTruthy()
43+
->not->toBeEmpty();
44+
})
45+
->group(__DIR__, __FILE__)
46+
->depends('it can search and download music')
47+
->skip(PHP_OS_FAMILY !== 'Darwin');

0 commit comments

Comments
 (0)