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

do not blindly overwrite configuration files #154

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 24 additions & 2 deletions src/Console/DuskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class DuskCommand extends Command
*/
protected $description = 'Run the Dusk tests for the application';

/**
* Whether the project has its own phpunit.dusk.xml file.
*
* @var boolean
*/
protected $phpunitDuskXmlExists = false;

/**
* Create a new command instance.
*
Expand Down Expand Up @@ -105,6 +112,14 @@ protected function purgeScreenshots()
protected function withDuskEnvironment($callback)
{
if (file_exists(base_path($this->duskFile()))) {
if (file_exists(base_path('.env.backup'))) {
$this->error('Cannot backup the current environment because there is already a .env.backup file in place!');
$this->error('Please check the contents of .env and .env.backup, remove the latter one if redundant, and then start Dusk again.');
$this->error('Aborting...');

return 2; // non-zero exit code to indicate failure
}

$this->backupEnvironment();

$this->refreshEnvironment();
Expand Down Expand Up @@ -162,7 +177,12 @@ protected function refreshEnvironment()
*/
protected function writeConfiguration()
{
copy(realpath(__DIR__.'/../../stubs/phpunit.xml'), base_path('phpunit.dusk.xml'));
$file = base_path('phpunit.dusk.xml');
if (file_exists($file)) {
$this->phpunitDuskXmlExists = true;
} else {
copy(realpath(__DIR__.'/../../stubs/phpunit.xml'), $file);
}
}

/**
Expand All @@ -172,7 +192,9 @@ protected function writeConfiguration()
*/
protected function removeConfiguration()
{
unlink(base_path('phpunit.dusk.xml'));
if (! $this->phpunitDuskXmlExists) {
unlink(base_path('phpunit.dusk.xml'));
}
}

/**
Expand Down