From aff4b9d9fcecf1e98b121c7a32091201c30fd52e Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 28 Dec 2022 03:10:01 -0500 Subject: [PATCH] Add option --skip-install-check to `dusk:chrome` When `php artisan dusk:chrome` checks DuskTestCase.php contains a call to `$this->startChromeDriver()`, loosen the pattern check so apps can pass $arguments into the method. Also add a --skip-install-check option if apps wish to further customize the stub without calling startChromeDriver(). --- src/Console/ChromeCommand.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Console/ChromeCommand.php b/src/Console/ChromeCommand.php index 3c746be..81e76a5 100644 --- a/src/Console/ChromeCommand.php +++ b/src/Console/ChromeCommand.php @@ -14,7 +14,9 @@ class ChromeCommand extends Command * * @var string */ - protected $signature = 'dusk:chrome {--without-tty : Disable output to TTY}'; + protected $signature = 'dusk:chrome + {--skip-install-check : Don\'t check DuskTestCase.php references ChromeDriver.} + {--without-tty : Disable output to TTY}'; /** * The console command description. @@ -49,13 +51,15 @@ public function __construct() */ public function handle() { - if (! $this->hasChromedriverSetup()) { + if (! $this->option('skip-install-check') && ! $this->hasChromedriverSetup()) { $this->info('It looks like you must configure your application for Chromedriver.'); $this->info('Run "php artisan dusk:install-firefox --with-chrome" to install new scaffolding.'); return 1; } + $this->cleanArgv(); + $duskFile = new DuskFile($this->laravel->environment()); if (! $duskFile->append($this->environmentVariable)) { @@ -80,7 +84,7 @@ public function handle() */ protected function hasChromedriverSetup() { - return Str::contains($this->duskTestCaseContents(), 'startChromeDriver()'); + return Str::contains($this->duskTestCaseContents(), 'startChromeDriver'); } /** @@ -92,4 +96,16 @@ protected function duskTestCaseContents() { return file_get_contents(base_path('tests/DuskTestCase.php')); } + + /** + * Remove --skip-install-check to prevent Symfony method Command::run() + * applying invalid option: 'php artisan dusk --skip-install-check'. + * + * @return void + */ + protected function cleanArgv() + { + $_SERVER['argv'] = array_diff($_SERVER['argv'], ['--skip-install-check']); + $_SERVER['argc'] = count($_SERVER['argv']); + } }