diff --git a/src/Illuminate/Foundation/Console/EnvironmentEncryptCommand.php b/src/Illuminate/Foundation/Console/EnvironmentEncryptCommand.php index f2c55fd3e98d..192112569c8e 100644 --- a/src/Illuminate/Foundation/Console/EnvironmentEncryptCommand.php +++ b/src/Illuminate/Foundation/Console/EnvironmentEncryptCommand.php @@ -21,6 +21,7 @@ class EnvironmentEncryptCommand extends Command {--key= : The encryption key} {--cipher= : The encryption cipher} {--env= : The environment to be encrypted} + {--prune= : Delete the original environment file} {--force : Overwrite the existing encrypted environment file}'; /** @@ -98,6 +99,10 @@ public function handle() return Command::FAILURE; } + if ($this->option('prune')) { + $this->files->delete($environmentFile); + } + $this->components->info('Environment successfully encrypted.'); $this->components->twoColumnDetail('Key', $keyPassed ? $key : 'base64:'.base64_encode($key)); diff --git a/tests/Integration/Console/EnvironmentEncryptCommandTest.php b/tests/Integration/Console/EnvironmentEncryptCommandTest.php index ac99801d74b8..8de3023f5525 100644 --- a/tests/Integration/Console/EnvironmentEncryptCommandTest.php +++ b/tests/Integration/Console/EnvironmentEncryptCommandTest.php @@ -155,4 +155,24 @@ public function testItEncryptsWithGivenGeneratedBase64KeyAndDisplaysIt() ->expectsOutputToContain('.env.encrypted') ->assertExitCode(0); } + + public function testItCanRemoveTheOriginalFile() + { + $this->filesystem->shouldReceive('exists') + ->once() + ->andReturn(true) + ->shouldReceive('exists') + ->once() + ->andReturn(false); + + $this->artisan('env:encrypt', ['--prune' => true]) + ->expectsOutputToContain('.env.encrypted') + ->assertExitCode(0); + + $this->filesystem->shouldHaveReceived('put') + ->with(base_path('.env.encrypted'), m::any()); + + $this->filesystem->shouldHaveReceived('delete') + ->with(base_path('.env')); + } }