koel/tests/CreatesApplication.php

51 lines
1.1 KiB
PHP
Raw Normal View History

2017-02-14 14:53:02 +08:00
<?php
namespace Tests;
2019-07-22 11:54:39 +02:00
use App\Console\Kernel;
2017-06-10 14:25:30 +01:00
use App\Models\User;
2018-08-31 20:47:15 +07:00
use Illuminate\Contracts\Console\Kernel as Artisan;
2018-08-23 08:58:17 +02:00
use Illuminate\Foundation\Application;
2017-02-14 14:53:02 +08:00
trait CreatesApplication
{
protected $coverPath;
2017-06-10 14:25:30 +01:00
protected $mediaPath = __DIR__.'/songs';
2017-02-14 14:53:02 +08:00
2019-07-22 11:54:39 +02:00
/** @var Kernel */
2018-08-31 20:47:15 +07:00
private $artisan;
2017-02-14 14:53:02 +08:00
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
public function createApplication(): Application
2017-02-14 14:53:02 +08:00
{
/** @var Application $app */
2017-02-14 14:53:02 +08:00
$app = require __DIR__.'/../bootstrap/app.php';
2018-08-31 20:47:15 +07:00
$this->artisan = $app->make(Artisan::class);
$this->artisan->bootstrap();
2017-02-14 14:53:02 +08:00
$this->coverPath = $app->basePath('/public/img/covers');
2017-02-14 14:53:02 +08:00
return $app;
}
2017-06-10 14:25:30 +01:00
private function prepareForTests(): void
2017-06-10 14:25:30 +01:00
{
2018-08-31 20:47:15 +07:00
$this->artisan->call('migrate');
2017-06-10 14:25:30 +01:00
if (!User::all()->count()) {
2018-08-31 20:47:15 +07:00
$this->artisan->call('db:seed');
2017-06-10 14:25:30 +01:00
}
if (!file_exists($this->coverPath)) {
mkdir($this->coverPath, 0777, true);
}
}
2017-02-14 14:53:02 +08:00
}