2017-10-26 23:24:33 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
use DB;
|
|
|
|
use Artisan;
|
|
|
|
|
|
|
|
class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
2017-10-26 23:24:33 +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();
|
2017-10-26 23:24:33 +08:00
|
|
|
|
2017-11-09 12:09:41 +08:00
|
|
|
Artisan::call('migrate:refresh');
|
2017-10-29 09:19:02 +08:00
|
|
|
|
2017-10-30 12:40:34 +08:00
|
|
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
|
|
|
|
2017-10-26 23:24:33 +08:00
|
|
|
return $app;
|
|
|
|
}
|
2017-10-29 09:19:02 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
2017-10-29 09:19:02 +08:00
|
|
|
}
|
2018-03-11 11:20:21 +08:00
|
|
|
|
2019-02-27 23:44:50 +08:00
|
|
|
protected function tearDown(): void
|
2018-03-11 11:20:21 +08:00
|
|
|
{
|
|
|
|
$this->beforeApplicationDestroyed(function () {
|
|
|
|
DB::disconnect();
|
|
|
|
});
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2017-10-26 23:24:33 +08:00
|
|
|
}
|