@@ -207,6 +207,70 @@ public function testExecuteCreatesEnvironmentDirectory(): void
207207 $ this ->assertStringContainsString ( "Secrets saved to: {$ credentialsPath }" , $ outputContent );
208208 }
209209
210+ /**
211+ * Test editor option handling with various input types
212+ */
213+ public function testEditorOptionHandling (): void
214+ {
215+ // Create a key file first
216+ $ keyPath = $ this ->testConfigPath . '/master.key ' ;
217+ $ secretManager = new SecretManager ();
218+ $ secretManager ->generateKey ( $ keyPath );
219+
220+ // Create initial credentials file
221+ $ credentialsPath = $ this ->testConfigPath . '/secrets.yml.enc ' ;
222+ $ tempPlaintextPath = $ this ->testConfigPath . '/temp.yml ' ;
223+ file_put_contents ( $ tempPlaintextPath , "test: value " );
224+ $ secretManager ->encrypt ( $ tempPlaintextPath , $ credentialsPath , $ keyPath );
225+ unlink ( $ tempPlaintextPath );
226+
227+ // Test 1: Editor option with value
228+ $ input1 = new Input ( [
229+ '--config= ' . $ this ->testConfigPath ,
230+ '--editor=echo ' // Use echo as a no-op editor
231+ ] );
232+ $ input1 ->parse ( $ this ->command );
233+
234+ $ output1 = new Output ( false );
235+ $ this ->command ->setInput ( $ input1 );
236+ $ this ->command ->setOutput ( $ output1 );
237+
238+ // This should use 'echo' as editor
239+ ob_start ();
240+ $ result1 = $ this ->command ->execute ();
241+ $ outputContent1 = ob_get_clean ();
242+
243+ // Should succeed with echo editor
244+ $ this ->assertEquals ( 0 , $ result1 );
245+ $ this ->assertStringContainsString ( "Secrets saved to " , $ outputContent1 );
246+
247+ // Test 2: Editor option without value (becomes boolean true)
248+ $ input2 = new Input ( [
249+ '--config= ' . $ this ->testConfigPath ,
250+ '--editor ' // No value - becomes boolean true
251+ ] );
252+ $ input2 ->parse ( $ this ->command );
253+
254+ $ output2 = new Output ( false );
255+ $ this ->command ->setInput ( $ input2 );
256+ $ this ->command ->setOutput ( $ output2 );
257+
258+ // This should fall back to EDITOR env var or 'vi'
259+ // Set a test editor to avoid vi
260+ putenv ( 'EDITOR=echo ' );
261+
262+ ob_start ();
263+ $ result2 = $ this ->command ->execute ();
264+ $ outputContent2 = ob_get_clean ();
265+
266+ // Should succeed with fallback to env var
267+ $ this ->assertEquals ( 0 , $ result2 );
268+ $ this ->assertStringContainsString ( "Secrets saved to " , $ outputContent2 );
269+
270+ // Clean up env var
271+ putenv ( 'EDITOR ' );
272+ }
273+
210274 /**
211275 * Test that error is handled gracefully
212276 */
0 commit comments