@@ -74,13 +74,13 @@ protected function resetEnvironment()
7474
7575 public function testGenerateKeyShowsEncodedKey ()
7676 {
77- command ('key:generate -show ' );
77+ command ('key:generate -- show ' );
7878 $ this ->assertStringContainsString ('hex2bin: ' , $ this ->getBuffer ());
7979
80- command ('key:generate -prefix base64 -show ' );
80+ command ('key:generate -- prefix base64 - -show ' );
8181 $ this ->assertStringContainsString ('base64: ' , $ this ->getBuffer ());
8282
83- command ('key:generate -prefix hex2bin -show ' );
83+ command ('key:generate -- prefix hex2bin - -show ' );
8484 $ this ->assertStringContainsString ('hex2bin: ' , $ this ->getBuffer ());
8585 }
8686
@@ -95,12 +95,12 @@ public function testGenerateKeyCreatesNewKey()
9595 $ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
9696 $ this ->assertStringContainsString ('hex2bin: ' , file_get_contents ($ this ->envPath ));
9797
98- command ('key:generate -prefix base64 -force ' );
98+ command ('key:generate -- prefix base64 - -force ' );
9999 $ this ->assertStringContainsString ('successfully set. ' , $ this ->getBuffer ());
100100 $ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
101101 $ this ->assertStringContainsString ('base64: ' , file_get_contents ($ this ->envPath ));
102102
103- command ('key:generate -prefix hex2bin -force ' );
103+ command ('key:generate -- prefix hex2bin - -force ' );
104104 $ this ->assertStringContainsString ('successfully set. ' , $ this ->getBuffer ());
105105 $ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
106106 $ this ->assertStringContainsString ('hex2bin: ' , file_get_contents ($ this ->envPath ));
@@ -115,4 +115,17 @@ public function testDefaultShippedEnvIsMissing()
115115 $ this ->assertStringContainsString ('Both default shipped ' , $ this ->getBuffer ());
116116 $ this ->assertStringContainsString ('Error in setting ' , $ this ->getBuffer ());
117117 }
118+
119+ /**
120+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/6838
121+ */
122+ public function testKeyGenerateWhenKeyIsMissingInDotEnvFile ()
123+ {
124+ file_put_contents ($ this ->envPath , '' );
125+
126+ command ('key:generate ' );
127+
128+ $ this ->assertStringContainsString ('Application \'s new encryption key was successfully set. ' , $ this ->getBuffer ());
129+ $ this ->assertSame ("\nencryption.key = " . env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
130+ }
118131}
0 commit comments