-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPest.php
66 lines (53 loc) · 1.4 KB
/
Pest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
use App\Models\PlaylistItem;
use App\Models\Room;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Config;
use function Pest\Laravel\actingAs;
uses(
Tests\TestCase::class,
Illuminate\Foundation\Testing\RefreshDatabase::class,
)->in('Feature');
function user(string $name = null, string $email = null): ?User
{
if ($name || $email) {
return User::query()
->when($name, fn ($query) => $query->where('name', $name))
->when($email, fn ($query) => $query->where('email', $email))
->first();
}
return null;
}
function loginUser(string $email = '[email protected]'): ?User
{
if ($user = user(email: $email)) {
actingAs($user);
return $user;
}
return null;
}
function passwordless()
{
Config::set('ycsplayer.password_less', true);
}
function room(string $name): ?Room
{
return Room::where('name', $name)->first();
}
function playlist(Room $room, string $itemTitle): ?PlaylistItem
{
return $room->playlistItems()
->where('title', $itemTitle)
->first();
}
function fakeFileFromPath(string $path, string $filename = null)
{
$filename = $filename ?? basename($path);
$r = fopen(base_path($path), 'rb');
$contents = fread($r, filesize(base_path($path)));
fclose($r);
return UploadedFile::fake()->createWithContent(
$filename, $contents
);
}