forked from koel/koel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCase.php
83 lines (67 loc) · 1.83 KB
/
TestCase.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use App\Models\Album;
use App\Models\Artist;
use App\Models\Song;
use App\Models\User;
use Illuminate\Foundation\Testing\TestCase as IlluminateTestCase;
use Illuminate\Support\Facades\Artisan;
abstract class TestCase extends IlluminateTestCase
{
protected $mediaPath;
protected $coverPath;
public function __construct()
{
parent::__construct();
$this->mediaPath = dirname(__FILE__).'/songs';
}
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$this->coverPath = $app->publicPath().'/img/covers';
return $app;
}
private function prepareForTests()
{
Artisan::call('migrate');
if (!User::all()->count()) {
Artisan::call('db:seed');
}
if (!file_exists($this->coverPath)) {
mkdir($this->coverPath, 0777, true);
}
}
/**
* Create a sample media set, with a complete artist+album+song trio.
*/
protected function createSampleMediaSet()
{
$artist = factory(Artist::class)->create();
// Sample 3 albums
$albums = factory(Album::class, 3)->create([
'artist_id' => $artist->id,
]);
// 7-15 songs per albums
foreach ($albums as $album) {
factory(Song::class, rand(7, 15))->create([
'album_id' => $album->id,
]);
};
}
}