@@ -34,6 +34,7 @@ public function testItFailsWithInvalidCipherFails()
34
34
->andReturn (false );
35
35
36
36
$ this ->artisan ('env:encrypt ' , ['--cipher ' => 'invalid ' ])
37
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
37
38
->expectsOutputToContain ('Unsupported cipher ' )
38
39
->assertExitCode (1 );
39
40
}
@@ -62,6 +63,7 @@ public function testItGeneratesTheCorrectFileWhenUsingEnvironment()
62
63
->andReturn (false );
63
64
64
65
$ this ->artisan ('env:encrypt ' , ['--env ' => 'production ' ])
66
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
65
67
->expectsOutputToContain ('.env.production.encrypted ' )
66
68
->assertExitCode (0 );
67
69
@@ -80,6 +82,7 @@ public function testItGeneratesTheCorrectFileWhenNotUsingEnvironment()
80
82
->shouldReceive ('get ' );
81
83
82
84
$ this ->artisan ('env:encrypt ' )
85
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
83
86
->expectsOutputToContain ('.env.encrypted ' )
84
87
->assertExitCode (0 );
85
88
@@ -92,6 +95,7 @@ public function testItFailsWhenEnvironmentFileCannotBeFound()
92
95
$ this ->filesystem ->shouldReceive ('exists ' )->andReturn (false );
93
96
94
97
$ this ->artisan ('env:encrypt ' )
98
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
95
99
->expectsOutputToContain ('Environment file not found. ' )
96
100
->assertExitCode (1 );
97
101
}
@@ -101,6 +105,7 @@ public function testItFailsWhenEncryptionFileExists()
101
105
$ this ->filesystem ->shouldReceive ('exists ' )->andReturn (true );
102
106
103
107
$ this ->artisan ('env:encrypt ' )
108
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
104
109
->expectsOutputToContain ('Encrypted environment file already exists. ' )
105
110
->assertExitCode (1 );
106
111
}
@@ -115,6 +120,7 @@ public function testItGeneratesTheEncryptionFileWhenForcing()
115
120
->andReturn (true );
116
121
117
122
$ this ->artisan ('env:encrypt ' , ['--force ' => true ])
123
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
118
124
->expectsOutputToContain ('.env.encrypted ' )
119
125
->assertExitCode (0 );
120
126
@@ -166,6 +172,7 @@ public function testItCanRemoveTheOriginalFile()
166
172
->andReturn (false );
167
173
168
174
$ this ->artisan ('env:encrypt ' , ['--prune ' => true ])
175
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'generate ' )
169
176
->expectsOutputToContain ('.env.encrypted ' )
170
177
->assertExitCode (0 );
171
178
@@ -175,4 +182,22 @@ public function testItCanRemoveTheOriginalFile()
175
182
$ this ->filesystem ->shouldHaveReceived ('delete ' )
176
183
->with (base_path ('.env ' ));
177
184
}
185
+
186
+ public function testItEncryptsWithInteractivelyGivenKeyAndDisplaysIt ()
187
+ {
188
+ $ this ->filesystem ->shouldReceive ('exists ' )
189
+ ->once ()
190
+ ->andReturn (true )
191
+ ->shouldReceive ('exists ' )
192
+ ->once ()
193
+ ->andReturn (false );
194
+
195
+ $ this ->artisan ('env:encrypt ' )
196
+ ->expectsQuestion ('What encryption key would you like to use? ' , 'ask ' )
197
+ ->expectsQuestion ('What is the encryption key? ' , $ key = 'ANvVbPbE0tWMHpUySh6liY4WaCmAYKXP ' )
198
+ ->expectsOutputToContain ('Environment successfully encrypted ' )
199
+ ->expectsOutputToContain ($ key )
200
+ ->expectsOutputToContain ('.env.encrypted ' )
201
+ ->assertExitCode (0 );
202
+ }
178
203
}
0 commit comments