blessing-skin-server/tests/BrowserKitTestCase.php

64 lines
1.3 KiB
PHP
Raw Normal View History

2018-07-13 16:41:50 +08:00
<?php
2018-08-17 15:25:08 +08:00
namespace Tests;
use DB;
use Artisan;
2018-08-17 23:24:08 +08:00
use Tests\Concerns\InteractsWithCache;
2018-08-17 15:25:08 +08:00
use Laravel\BrowserKitTesting\TestCase;
class BrowserKitTestCase extends TestCase
2018-07-13 16:41:50 +08:00
{
2018-08-17 23:24:08 +08:00
use InteractsWithCache;
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');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
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();
}
}
return $this->actingAs($role);
2018-07-13 16:41:50 +08:00
}
2019-02-27 23:44:50 +08:00
protected function tearDown(): void
2018-07-13 16:41:50 +08:00
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
}