diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 72c8eff2..9f8e37f1 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -18,6 +18,15 @@ class SetupController extends Controller { public function database(Request $request) { + if ($request->isMethod('get')) { + try { + DB::getPdo(); + return redirect('setup/info'); + } catch (\Exception $e) { + return view('setup.wizard.database'); + } + } + config([ 'database.connections.temp.driver' => $request->input('type'), 'database.connections.temp.host' => $request->input('host'), @@ -273,7 +282,7 @@ class SetupController extends Controller } if (count($existingTables) == count($tables)) { - return true; + return $returnExistingTables ? $existingTables : true; } else { return $returnExistingTables ? $existingTables : false; } diff --git a/routes/setup.php b/routes/setup.php index eef21b8a..95590382 100644 --- a/routes/setup.php +++ b/routes/setup.php @@ -17,8 +17,7 @@ Route::group(['prefix' => 'setup'], function () { Route::group(['middleware' => 'setup'], function () { Route::view('/', 'setup.wizard.welcome'); - Route::view('/database', 'setup.wizard.database'); - Route::post('/database', 'SetupController@database'); + Route::any('/database', 'SetupController@database'); Route::get('/info', 'SetupController@info'); Route::post('/finish', 'SetupController@finish'); }); diff --git a/tests/SetupControllerTest.php b/tests/SetupControllerTest.php index 2891ce1f..ea56f9d4 100644 --- a/tests/SetupControllerTest.php +++ b/tests/SetupControllerTest.php @@ -2,6 +2,7 @@ namespace Tests; +use DB; use Mockery; use Exception; use CreateAllTables; @@ -61,6 +62,11 @@ class SetupControllerTest extends TestCase File::shouldReceive('get')->with('..'.DIRECTORY_SEPARATOR.'.env')->andReturn(''); File::shouldReceive('put')->with('..'.DIRECTORY_SEPARATOR.'.env', ''); $this->post('/setup/database', $fake)->assertRedirect('/setup/info'); + + $this->get('/setup/database')->assertRedirect('/setup/info'); + DB::shouldReceive('getPdo')->andThrow(new Exception()); + DB::shouldReceive('disconnect')->andReturn(true); + $this->get('/setup/database')->assertViewIs('setup.wizard.database'); } public function testReportDatabaseConnectionError()