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;
|
2022-12-04 13:56:25 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2024-05-19 05:49:42 +00:00
|
|
|
use Tests\TestCase;
|
2017-02-14 06:53:02 +00:00
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\test_path;
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
trait CreatesApplication
|
|
|
|
{
|
2024-01-06 11:31:50 +00:00
|
|
|
protected string $mediaPath;
|
2021-06-05 10:47:56 +00:00
|
|
|
protected string $baseUrl = 'http://localhost';
|
2022-12-04 13:56:25 +00:00
|
|
|
public static bool $migrated = false;
|
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
|
|
|
{
|
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
|
|
|
|
2024-01-06 11:31:50 +00:00
|
|
|
$this->mediaPath = test_path('songs');
|
|
|
|
|
2022-12-15 16:28:06 +00:00
|
|
|
/** @var Kernel $artisan */
|
|
|
|
$artisan = $app->make(Artisan::class);
|
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
$artisan->bootstrap();
|
2017-02-14 06:53:02 +00:00
|
|
|
|
2024-10-17 04:41:30 +00:00
|
|
|
// We need to migrate the DB only once for the whole test suite.
|
2024-05-19 05:49:42 +00:00
|
|
|
if (!TestCase::$migrated || DB::connection()->getDatabaseName() === ':memory:') {
|
|
|
|
$artisan->call('migrate');
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2022-12-04 13:56:25 +00:00
|
|
|
if (!User::query()->count()) {
|
2024-05-19 05:49:42 +00:00
|
|
|
$artisan->call('db:seed');
|
2022-12-04 13:56:25 +00:00
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
TestCase::$migrated = true;
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
2022-12-04 13:56:25 +00:00
|
|
|
|
|
|
|
return $app;
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
2017-02-14 06:53:02 +00:00
|
|
|
}
|