diff --git a/src/Exceptions/InternalException.php b/src/Exceptions/InternalException.php new file mode 100644 index 0000000..53e2061 --- /dev/null +++ b/src/Exceptions/InternalException.php @@ -0,0 +1,25 @@ +slug = $slug; + $this->wizardTitle = $wizardTitle; + } } diff --git a/src/Http/Controllers/WizardController.php b/src/Http/Controllers/WizardController.php index 71da8ec..c1d0945 100644 --- a/src/Http/Controllers/WizardController.php +++ b/src/Http/Controllers/WizardController.php @@ -326,24 +326,20 @@ protected function getLastProcessedStepIndex(Request $request) protected function getWizardStep(Request $request, $slug) { /** @var \Ycs77\LaravelWizard\Step|null $step */ - try { - if (isset($slug)) { - $step = $this->wizard()->stepRepo()->find($slug); - } else { - $lastProcessedStepIndex = $this->getLastProcessedStepIndex($request); - $step = $this->wizard()->stepRepo()->get($lastProcessedStepIndex); - } + if (isset($slug)) { + $step = $this->wizard()->stepRepo()->find($slug); + } else { + $lastProcessedStepIndex = $this->getLastProcessedStepIndex($request); + $step = $this->wizard()->stepRepo()->get($lastProcessedStepIndex); + } - if (is_null($step)) { - throw new StepNotFoundException(); - } + if (is_null($step)) { + throw new StepNotFoundException($this->wizardTitle, $slug); + } - $this->wizard()->stepRepo()->setCurrentIndex($step->index()); + $this->wizard()->stepRepo()->setCurrentIndex($step->index()); - $step->setModel($request); - } catch (StepNotFoundException $e) { - abort(404); - } + $step->setModel($request); return $step; } diff --git a/tests/Feature/HttpTest.php b/tests/Feature/HttpTest.php index 9c99631..e4346e9 100644 --- a/tests/Feature/HttpTest.php +++ b/tests/Feature/HttpTest.php @@ -90,12 +90,21 @@ public function testRunAllWizardSteps() ]); } - public function testWizardFormThrowStepNotFoundException() + public function testThrowStepNotFoundException() { + $this->app['config']->set('app.debug', false); + $response = $this->get('/wizard/test/step-not-found'); $response->assertStatus(404); } + public function testThrowStepNotFoundExceptionFromDebugMode() + { + $response = $this->get('/wizard/test/step-not-found'); + $response->assertStatus(500); + $response->assertSee('Step [step-not-found] is not found to wizard Test.'); + } + public function testWizardStepNotEquialToLastProcessedStep() { $this->session([ diff --git a/tests/Stubs/WizardControllerOptionsStub.php b/tests/Stubs/WizardControllerOptionsStub.php index e6017f2..dc916d7 100644 --- a/tests/Stubs/WizardControllerOptionsStub.php +++ b/tests/Stubs/WizardControllerOptionsStub.php @@ -2,17 +2,8 @@ namespace Ycs77\LaravelWizard\Test\Stubs; -use Ycs77\LaravelWizard\Http\Controllers\WizardController; - -class WizardControllerOptionsStub extends WizardController +class WizardControllerOptionsStub extends WizardControllerStub { - /** - * The wizard name. - * - * @var string - */ - protected $wizardName = 'test'; - /** * The wizard options. * @@ -23,24 +14,4 @@ class WizardControllerOptionsStub extends WizardController protected $wizardOptions = [ 'cache' => false, ]; - - /** - * The wizard steps instance. - * - * @var array - */ - protected $steps = [ - UserStepStub::class, - PostStepStub::class, - ]; - - /** - * Get controller main class name. - * - * @return string - */ - public function getControllerClass() - { - return static::class; - } } diff --git a/tests/Stubs/WizardControllerStub.php b/tests/Stubs/WizardControllerStub.php index ea96cbf..943db35 100644 --- a/tests/Stubs/WizardControllerStub.php +++ b/tests/Stubs/WizardControllerStub.php @@ -13,6 +13,13 @@ class WizardControllerStub extends WizardController */ protected $wizardName = 'test'; + /** + * The wizard title. + * + * @var string + */ + protected $wizardTitle = 'Test'; + /** * The wizard steps instance. * diff --git a/tests/TestCase.php b/tests/TestCase.php index c3ca24d..6064a31 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,6 +34,7 @@ protected function setUp() protected function getEnvironmentSetUp($app) { // App + $app['config']->set('app.debug', true); $app['config']->set('app.key', 'base64:tqASP1YzC4hhdT1nMEc+DFGMRq6WQmfMzYFW522Ce8g='); // Database