2017-02-14 06:53:02 +00:00
|
|
|
<?php
|
|
|
|
|
2020-06-13 12:19:24 +00:00
|
|
|
namespace Tests\Traits;
|
2017-02-14 06:53:02 +00:00
|
|
|
|
2019-07-22 09:54:39 +00:00
|
|
|
use App\Console\Kernel;
|
2017-06-10 13:25:30 +00:00
|
|
|
use App\Models\User;
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Contracts\Console\Kernel as Artisan;
|
2018-08-23 06:58:17 +00:00
|
|
|
use Illuminate\Foundation\Application;
|
2017-02-14 06:53:02 +00:00
|
|
|
|
|
|
|
trait CreatesApplication
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
protected string $mediaPath = __DIR__ . '/../songs';
|
|
|
|
private Kernel $artisan;
|
|
|
|
protected string $baseUrl = 'http://localhost';
|
2017-02-14 06:53:02 +00:00
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
public function createApplication(): Application
|
2017-02-14 06:53:02 +00:00
|
|
|
{
|
2022-07-07 10:45:57 +00:00
|
|
|
$this->mediaPath = realpath($this->mediaPath);
|
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
/** @var Application $app */
|
2020-12-22 20:11:22 +00:00
|
|
|
$app = require __DIR__ . '/../../bootstrap/app.php';
|
2017-02-14 06:53:02 +00:00
|
|
|
|
2018-08-31 13:47:15 +00:00
|
|
|
$this->artisan = $app->make(Artisan::class);
|
|
|
|
$this->artisan->bootstrap();
|
2017-02-14 06:53:02 +00:00
|
|
|
|
|
|
|
return $app;
|
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
private function prepareForTests(): void
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2022-07-29 08:26:18 +00:00
|
|
|
$this->artisan->call('migrate');
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2022-08-09 18:45:11 +00:00
|
|
|
if (!User::query()->count()) {
|
2018-08-31 13:47:15 +00:00
|
|
|
$this->artisan->call('db:seed');
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-14 06:53:02 +00:00
|
|
|
}
|