@@ -128,4 +128,40 @@ public function testKeyGenerateWhenKeyIsMissingInDotEnvFile()
128128 $ this ->assertStringContainsString ('Application \'s new encryption key was successfully set. ' , $ this ->getBuffer ());
129129 $ this ->assertSame ("\nencryption.key = " . env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
130130 }
131+
132+ public function testKeyGenerateWhenNewHexKeyIsSubsequentlyCommentedOut ()
133+ {
134+ command ('key:generate ' );
135+ $ key = env ('encryption.key ' , '' );
136+ file_put_contents ($ this ->envPath , str_replace (
137+ 'encryption.key = ' . $ key ,
138+ '# encryption.key = ' . $ key ,
139+ file_get_contents ($ this ->envPath ),
140+ $ count
141+ ));
142+ $ this ->assertSame (1 , $ count , 'Failed commenting out the previously set application key. ' );
143+
144+ CITestStreamFilter::$ buffer = '' ;
145+ command ('key:generate --force ' );
146+ $ this ->assertStringContainsString ('was successfully set. ' , $ this ->getBuffer ());
147+ $ this ->assertNotSame ($ key , env ('encryption.key ' , $ key ), 'Failed replacing the commented out key. ' );
148+ }
149+
150+ public function testKeyGenerateWhenNewBase64KeyIsSubsequentlyCommentedOut ()
151+ {
152+ command ('key:generate --prefix base64 ' );
153+ $ key = env ('encryption.key ' , '' );
154+ file_put_contents ($ this ->envPath , str_replace (
155+ 'encryption.key = ' . $ key ,
156+ '# encryption.key = ' . $ key ,
157+ file_get_contents ($ this ->envPath ),
158+ $ count
159+ ));
160+ $ this ->assertSame (1 , $ count , 'Failed commenting out the previously set application key. ' );
161+
162+ CITestStreamFilter::$ buffer = '' ;
163+ command ('key:generate --force ' );
164+ $ this ->assertStringContainsString ('was successfully set. ' , $ this ->getBuffer ());
165+ $ this ->assertNotSame ($ key , env ('encryption.key ' , $ key ), 'Failed replacing the commented out key. ' );
166+ }
131167}
0 commit comments