Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added solution for running Laravel Dusk in production #121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -308,6 +309,7 @@ protected function getDefaultSolutions(): array
InvalidRouteActionSolutionProvider::class,
ViewNotFoundSolutionProvider::class,
MergeConflictSolutionProvider::class,
RunningLaravelDuskInProductionProvider::class,
MissingColumnSolutionProvider::class,
];
}
Expand Down
30 changes: 30 additions & 0 deletions src/SolutionProviders/RunningLaravelDuskInProductionProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Facade\Ignition\SolutionProviders;

use Exception;
use Throwable;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\HasSolutionsForThrowable;

class RunningLaravelDuskInProductionProvider implements HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool
{
if (! $throwable instanceof Exception) {
return false;
}

return $throwable->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.'),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Facade\Ignition\Tests\Solutions;

use Exception;
use Facade\Ignition\Tests\TestCase;
use Facade\Ignition\SolutionProviders\RunningLaravelDuskInProductionProvider;

class RunningLaravelDuskInProductionSolutionProviderTest extends TestCase
{
/** @test */
public function it_can_solve_dusk_in_production_exception()
{
$exception = $this->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.');
}
}