Skip to content

Commit 2c46328

Browse files
committed
Add filename option
1 parent 77d3b68 commit 2c46328

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Illuminate/Foundation/Console/EnvironmentDecryptCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class EnvironmentDecryptCommand extends Command
2222
{--key= : The encryption key}
2323
{--cipher= : The encryption cipher}
2424
{--env= : The environment to be decrypted}
25-
{--force : Overwrite existing environment file}';
25+
{--force : Overwrite existing environment file}
26+
{--filename : Filename to which to write the decrypted contents}';
2627

2728
/**
2829
* The name of the console command.
@@ -77,6 +78,7 @@ public function handle()
7778
? base_path('.env').'.'.$this->option('env')
7879
: $this->laravel->environmentFilePath();
7980
$encryptedFile = $environmentFile.'.encrypted';
81+
$filename = $this->option('filename') ? base_path($this->option('filename')) : $environmentFile;
8082

8183
if (! $this->files->exists($encryptedFile)) {
8284
$this->components->error('Encrypted environment file not found.');
@@ -94,7 +96,7 @@ public function handle()
9496
$encrypter = new Encrypter($key, $cipher);
9597

9698
$this->files->put(
97-
$environmentFile,
99+
$filename,
98100
$encrypter->decrypt($this->files->get($encryptedFile))
99101
);
100102
} catch (Exception $e) {

tests/Integration/Console/EnvironmentDecryptCommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,27 @@ public function testItDecryptsMultiLineEnvironmentCorrectly()
202202
$this->filesystem->shouldHaveReceived('put')
203203
->with(base_path('.env'), $contents);
204204
}
205+
206+
public function testItWritesTheEnvironmentFileCustomFilename()
207+
{
208+
$this->filesystem->shouldReceive('exists')
209+
->once()
210+
->andReturn(true)
211+
->shouldReceive('exists')
212+
->once()
213+
->andReturn(false)
214+
->shouldReceive('get')
215+
->once()
216+
->andReturn(
217+
(new Encrypter('abcdefghijklmnop'))
218+
->encrypt('APP_NAME="Laravel Two"')
219+
);
220+
221+
$this->artisan('env:decrypt', ['--env' => 'production', '--key' => 'abcdefghijklmnop', '--filename' => '.env'])
222+
->expectsOutputToContain('Environment successfully decrypted.')
223+
->assertExitCode(0);
224+
225+
$this->filesystem->shouldHaveReceived('put')
226+
->with(base_path('.env'), 'APP_NAME="Laravel Two"');
227+
}
205228
}

0 commit comments

Comments
 (0)