2018-07-13 16:41:50 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class BrowserKitTestCase extends Laravel\BrowserKitTesting\TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
|
|
|
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 14:42:43 +08:00
|
|
|
return $this->actingAs($role);
|
2018-07-13 16:41:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->beforeApplicationDestroyed(function () {
|
|
|
|
DB::disconnect();
|
|
|
|
});
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
}
|