koel/tests/CreatesApplication.php

55 lines
1.1 KiB
PHP
Raw Normal View History

2017-02-14 06:53:02 +00:00
<?php
namespace Tests;
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
{
protected $coverPath;
2017-06-10 13:25:30 +00:00
protected $mediaPath = __DIR__.'/songs';
2017-02-14 06:53:02 +00:00
2019-07-22 09:54:39 +00:00
/** @var Kernel */
2018-08-31 13:47:15 +00:00
private $artisan;
2017-02-14 06:53:02 +00:00
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
2018-08-23 06:58:17 +00:00
* @return Application
2017-02-14 06:53:02 +00:00
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
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
$this->coverPath = $app->basePath().'/public/img/covers';
return $app;
}
2017-06-10 13:25:30 +00:00
private function prepareForTests()
{
2018-08-31 13:47:15 +00:00
$this->artisan->call('migrate');
2017-06-10 13:25:30 +00:00
if (!User::all()->count()) {
2018-08-31 13:47:15 +00:00
$this->artisan->call('db:seed');
2017-06-10 13:25:30 +00:00
}
if (!file_exists($this->coverPath)) {
mkdir($this->coverPath, 0777, true);
}
}
2017-02-14 06:53:02 +00:00
}