2018-07-13 16:41:50 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
use Artisan;
|
|
|
|
use Laravel\BrowserKitTesting\TestCase;
|
|
|
|
|
|
|
|
class BrowserKitTestCase extends TestCase
|
2018-07-13 16:41:50 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
2018-07-13 16:41:50 +08:00
|
|
|
|
|
|
|
Artisan::call('migrate:refresh');
|
|
|
|
|
2019-09-06 23:53:47 +08:00
|
|
|
$files = $app->make('files');
|
|
|
|
if (! $files->exists(storage_path('install.lock'))) {
|
|
|
|
$files->put(storage_path('install.lock'), '');
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:41:50 +08:00
|
|
|
return $app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \App\Models\User|string $role
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function actAs($role)
|
|
|
|
{
|
|
|
|
if (is_string($role)) {
|
|
|
|
if ($role == 'normal') {
|
|
|
|
$role = factory(\App\Models\User::class)->create();
|
|
|
|
} else {
|
|
|
|
$role = factory(\App\Models\User::class, $role)->create();
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 22:58:37 +08:00
|
|
|
|
2018-07-20 14:42:43 +08:00
|
|
|
return $this->actingAs($role);
|
2018-07-13 16:41:50 +08:00
|
|
|
}
|
|
|
|
}
|