Skip to content

Commit 8bb6143

Browse files
committed
test(Unit): Add SanitizerTest
- Create SanitizerTest - Test the batch sanitization of songs
1 parent ee5e959 commit 8bb6143

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<directory suffix=".php">app/</directory>
2323
</include>
2424
<exclude>
25-
<file>src/Skeleton.php</file>
25+
<file>app/Support/helpers.php</file>
2626
</exclude>
2727
</source>
2828
</phpunit>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/music-dl.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
namespace Tests\Unit\Concerns;
14+
15+
use App\Concerns\HttpClientFactory;
16+
use GuzzleHttp\Client;
17+
18+
it('can create http client', function (): void {
19+
expect(new class() {
20+
use HttpClientFactory;
21+
})
22+
->createHttpClient()->toBeInstanceOf(Client::class)
23+
->createHttpClient()->toBeInstanceOf(Client::class);
24+
})->group(__DIR__, __FILE__);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/music-dl.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
namespace Tests\Unit\Concerns;
14+
15+
use App\Concerns\Sanitizer;
16+
use Illuminate\Support\Collection;
17+
18+
it('can batch sanitize songs', function (): void {
19+
$songs = [
20+
1 => [
21+
'id' => 1386737246,
22+
'name' => '公路之光',
23+
'artist' => ['腰乐队'],
24+
'album' => '他们说忘了摇滚有问题',
25+
'pic_id' => '109951164323917099',
26+
'url_id' => 1386737246,
27+
'lyric_id' => 1386737246,
28+
'source' => 'netease',
29+
'url' => 'http://m8.music.126.net/20231125211927/8af8b7988921529700b6c770fd2022f4/ymusic/obj/w5zDlMODwrDDiGjCn8Ky/3307382749/f61f/636f/6518/ee00afde1ad90a3153401cae2d813de0.mp3',
30+
'size' => 12142803,
31+
'br' => 320,
32+
],
33+
2 => [
34+
'id' => 390593,
35+
'name' => '你饿吗',
36+
'artist' => ['腰乐队'],
37+
'album' => '明日小城',
38+
'pic_id' => '76965813960184',
39+
'url_id' => 390593,
40+
'lyric_id' => 390593,
41+
'source' => 'netease',
42+
'url' => 'http://m7.music.126.net/20231125211927/d638dcb80d53828a275456f7a7355884/ymusic/9f50/1194/614e/227ed156b06a6b4fa9aac9b9351669f1.mp3',
43+
'size' => 8712028,
44+
'br' => 192,
45+
],
46+
];
47+
48+
expect(new class() {
49+
use Sanitizer;
50+
})->sanitizes(collect($songs), '腰乐队')->toBeInstanceOf(Collection::class);
51+
})->group(__DIR__, __FILE__);

0 commit comments

Comments
 (0)