@@ -74,13 +74,13 @@ protected function resetEnvironment()
74
74
75
75
public function testGenerateKeyShowsEncodedKey ()
76
76
{
77
- command ('key:generate -show ' );
77
+ command ('key:generate -- show ' );
78
78
$ this ->assertStringContainsString ('hex2bin: ' , $ this ->getBuffer ());
79
79
80
- command ('key:generate -prefix base64 -show ' );
80
+ command ('key:generate -- prefix base64 - -show ' );
81
81
$ this ->assertStringContainsString ('base64: ' , $ this ->getBuffer ());
82
82
83
- command ('key:generate -prefix hex2bin -show ' );
83
+ command ('key:generate -- prefix hex2bin - -show ' );
84
84
$ this ->assertStringContainsString ('hex2bin: ' , $ this ->getBuffer ());
85
85
}
86
86
@@ -95,12 +95,12 @@ public function testGenerateKeyCreatesNewKey()
95
95
$ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
96
96
$ this ->assertStringContainsString ('hex2bin: ' , file_get_contents ($ this ->envPath ));
97
97
98
- command ('key:generate -prefix base64 -force ' );
98
+ command ('key:generate -- prefix base64 - -force ' );
99
99
$ this ->assertStringContainsString ('successfully set. ' , $ this ->getBuffer ());
100
100
$ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
101
101
$ this ->assertStringContainsString ('base64: ' , file_get_contents ($ this ->envPath ));
102
102
103
- command ('key:generate -prefix hex2bin -force ' );
103
+ command ('key:generate -- prefix hex2bin - -force ' );
104
104
$ this ->assertStringContainsString ('successfully set. ' , $ this ->getBuffer ());
105
105
$ this ->assertStringContainsString (env ('encryption.key ' ), file_get_contents ($ this ->envPath ));
106
106
$ this ->assertStringContainsString ('hex2bin: ' , file_get_contents ($ this ->envPath ));
@@ -115,4 +115,17 @@ public function testDefaultShippedEnvIsMissing()
115
115
$ this ->assertStringContainsString ('Both default shipped ' , $ this ->getBuffer ());
116
116
$ this ->assertStringContainsString ('Error in setting ' , $ this ->getBuffer ());
117
117
}
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
+ }
118
131
}
0 commit comments