Tweak TestCase

This commit is contained in:
Pig Fang 2019-09-04 21:28:21 +08:00
parent 9402f5f83e
commit e48bd1f9c6
3 changed files with 9 additions and 36 deletions

View File

@ -299,21 +299,13 @@ if (! function_exists('get_client_ip')) {
*/ */
function get_client_ip(): string function get_client_ip(): string
{ {
$request = request();
if (option('ip_get_method') == '0') { if (option('ip_get_method') == '0') {
// Use `HTTP_X_FORWARDED_FOR` if available first $ip = $request->server('HTTP_X_FORWARDED_FOR')
$ip = Arr::get( ?? $request->server('HTTP_CLIENT_IP')
$_SERVER, ?? $request->server('REMOTE_ADDR');
'HTTP_X_FORWARDED_FOR',
// Fallback to `HTTP_CLIENT_IP`
Arr::get(
$_SERVER,
'HTTP_CLIENT_IP',
// Fallback to `REMOTE_ADDR`
Arr::get($_SERVER, 'REMOTE_ADDR')
)
);
} else { } else {
$ip = Arr::get($_SERVER, 'REMOTE_ADDR'); $ip = $request->server('REMOTE_ADDR');
} }
return $ip; return $ip;
@ -350,15 +342,16 @@ if (! function_exists('is_request_secure')) {
*/ */
function is_request_secure(): bool function is_request_secure(): bool
{ {
if (Arr::get($_SERVER, 'HTTPS') == 'on') { $request = request();
if ($request->server('HTTPS') == 'on') {
return true; return true;
} }
if (Arr::get($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') { if ($request->server('HTTP_X_FORWARDED_PROTO') == 'https') {
return true; return true;
} }
if (Arr::get($_SERVER, 'HTTP_X_FORWARDED_SSL') == 'on') { if ($request->server('HTTP_X_FORWARDED_SSL') == 'on') {
return true; return true;
} }

View File

@ -28,8 +28,6 @@ class BrowserKitTestCase extends TestCase
Artisan::call('migrate:refresh'); Artisan::call('migrate:refresh');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
return $app; return $app;
} }
@ -49,12 +47,4 @@ class BrowserKitTestCase extends TestCase
return $this->actingAs($role); return $this->actingAs($role);
} }
protected function tearDown(): void
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
} }

View File

@ -27,8 +27,6 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase
Artisan::call('migrate:refresh'); Artisan::call('migrate:refresh');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
return $app; return $app;
} }
@ -48,12 +46,4 @@ class TestCase extends \Illuminate\Foundation\Testing\TestCase
return $this->actingAs($role); return $this->actingAs($role);
} }
protected function tearDown(): void
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
} }