From 36baa5632fae270c1c9899fee2141cfa9fa414e0 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Sat, 7 Sep 2019 23:06:00 +0200 Subject: [PATCH 1/2] added solution for running Laravel Dusk in production Signed-off-by: Tonko Mulder --- src/IgnitionServiceProvider.php | 2 ++ ...RunningLaravelDuskInProductionProvider.php | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/SolutionProviders/RunningLaravelDuskInProductionProvider.php diff --git a/src/IgnitionServiceProvider.php b/src/IgnitionServiceProvider.php index 923cddb1..f5fc37b1 100644 --- a/src/IgnitionServiceProvider.php +++ b/src/IgnitionServiceProvider.php @@ -51,6 +51,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; @@ -308,6 +309,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.'), + ]; + } +} From f71ba5da047e7472d7b884ed30b1412449e75a17 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Fri, 13 Sep 2019 20:40:07 +0200 Subject: [PATCH 2/2] added tests for the laravel dusk exception Signed-off-by: Tonko Mulder --- ...elDuskInProductionSolutionProviderTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Solutions/RunningLaravelDuskInProductionSolutionProviderTest.php 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.'); + } +}