From e2aab65ac717868cad407a3852229738bdf7ac40 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Wed, 18 Sep 2019 21:01:56 +0200 Subject: [PATCH] added solution for running Laravel Dusk in production (#121) * added solution for running Laravel Dusk in production Signed-off-by: Tonko Mulder * added tests for the laravel dusk exception Signed-off-by: Tonko Mulder --- src/IgnitionServiceProvider.php | 2 ++ ...RunningLaravelDuskInProductionProvider.php | 30 +++++++++++++++++++ ...elDuskInProductionSolutionProviderTest.php | 30 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/SolutionProviders/RunningLaravelDuskInProductionProvider.php create mode 100644 tests/Solutions/RunningLaravelDuskInProductionSolutionProviderTest.php diff --git a/src/IgnitionServiceProvider.php b/src/IgnitionServiceProvider.php index 3fecd825..1d80d7bc 100644 --- a/src/IgnitionServiceProvider.php +++ b/src/IgnitionServiceProvider.php @@ -52,6 +52,7 @@ use Illuminate\View\Engines\CompilerEngine as LaravelCompilerEngine; use Facade\Ignition\SolutionProviders\MissingPackageSolutionProvider; use Facade\Ignition\SolutionProviders\InvalidRouteActionSolutionProvider; +use Facade\Ignition\SolutionProviders\RunningLaravelDuskInProductionProvider; use Facade\Ignition\SolutionProviders\IncorrectValetDbCredentialsSolutionProvider; use Facade\IgnitionContracts\SolutionProviderRepository as SolutionProviderRepositoryContract; @@ -310,6 +311,7 @@ protected function getDefaultSolutions(): array InvalidRouteActionSolutionProvider::class, ViewNotFoundSolutionProvider::class, MergeConflictSolutionProvider::class, + RunningLaravelDuskInProductionProvider::class, MissingColumnSolutionProvider::class, ]; } diff --git a/src/SolutionProviders/RunningLaravelDuskInProductionProvider.php b/src/SolutionProviders/RunningLaravelDuskInProductionProvider.php new file mode 100644 index 00000000..bfb66a49 --- /dev/null +++ b/src/SolutionProviders/RunningLaravelDuskInProductionProvider.php @@ -0,0 +1,30 @@ +getMessage() === 'It is unsafe to run Dusk in production.'; + } + + public function getSolutions(Throwable $throwable): array + { + return [ + BaseSolution::create('Laravel Dusk should not be run in production.') + ->setSolutionDescription('Install the dependencies with the `--no-dev` flag.'), + BaseSolution::create('Laravel Dusk can be run in other environments.') + ->setSolutionDescription('Consider setting the `APP_ENV` to something other than `production` like `local` for example.'), + ]; + } +} diff --git a/tests/Solutions/RunningLaravelDuskInProductionSolutionProviderTest.php b/tests/Solutions/RunningLaravelDuskInProductionSolutionProviderTest.php new file mode 100644 index 00000000..2ed5f894 --- /dev/null +++ b/tests/Solutions/RunningLaravelDuskInProductionSolutionProviderTest.php @@ -0,0 +1,30 @@ +generate_dusk_exception(); + $canSolve = app(RunningLaravelDuskInProductionProvider::class)->canSolve($exception); + [$first_solution, $second_solution] = app(RunningLaravelDuskInProductionProvider::class)->getSolutions($exception); + + $this->assertTrue($canSolve); + $this->assertSame($first_solution->getSolutionTitle(), 'Laravel Dusk should not be run in production.'); + $this->assertSame($first_solution->getSolutionDescription(), 'Install the dependencies with the `--no-dev` flag.'); + + $this->assertSame($second_solution->getSolutionTitle(), 'Laravel Dusk can be run in other environments.'); + $this->assertSame($second_solution->getSolutionDescription(), 'Consider setting the `APP_ENV` to something other than `production` like `local` for example.'); + } + + private function generate_dusk_exception(): Exception + { + return new Exception('It is unsafe to run Dusk in production.'); + } +}