From 6d93a78d22771f10fad3af120c0e9eb53ac69261 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 18 Feb 2019 17:15:14 +0800 Subject: [PATCH] fix: check tables if it's existed when db is connected --- app/Http/Controllers/SetupController.php | 6 +++++- tests/MiddlewareTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index bc72403d..804e424b 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -245,7 +245,11 @@ class SetupController extends Controller { if (request()->is('setup') || request()->is('setup/database')) { // We're ready to install Blessing Skin, so skip the checks. - return false; + try { + DB::connection(env('DB_CONNECTION'))->getPdo(); + } catch (\Exception $e) { + return false; + } } $existingTables = []; diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index c6736069..8344ffd1 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -2,6 +2,7 @@ namespace Tests; +use DB; use App\Models\User; use App\Services\Facades\Option; use Illuminate\Support\Facades\Schema; @@ -119,6 +120,13 @@ class MiddlewareTest extends TestCase 'setup.wizard.welcome.text', ['version' => config('app.version')] )); + + DB::shouldReceive('connection')->once()->andThrow(new \Exception('fake exception')); + DB::shouldReceive('disconnect')->andReturnSelf(); + $this->get('/setup')->assertSee(trans( + 'setup.wizard.welcome.text', + ['version' => config('app.version')] + )); } public function testCheckPlayerExist()