@@ -514,6 +514,40 @@ public function testEmptyChoices()
514
514
new ChoiceQuestion ('Question ' , array (), 'irrelevant ' );
515
515
}
516
516
517
+ public function testTraversableAutocomplete ()
518
+ {
519
+ if (!$ this ->hasSttyAvailable ()) {
520
+ $ this ->markTestSkipped ('`stty` is required to test autocomplete functionality ' );
521
+ }
522
+
523
+ // Acm<NEWLINE>
524
+ // Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
525
+ // <NEWLINE>
526
+ // <UP ARROW><UP ARROW><NEWLINE>
527
+ // <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
528
+ // <DOWN ARROW><NEWLINE>
529
+ // S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
530
+ // F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
531
+ $ inputStream = $ this ->getInputStream ("Acm \nAc \177\177s \tTest \n\n\033[A \033[A \n\033[A \033[A \033[A \033[A \033[A \tTest \n\033[B \nS \177\177\033[B \033[B \nF00 \177\177oo \t\n" );
532
+
533
+ $ dialog = new QuestionHelper ();
534
+ $ dialog ->setInputStream ($ inputStream );
535
+ $ helperSet = new HelperSet (array (new FormatterHelper ()));
536
+ $ dialog ->setHelperSet ($ helperSet );
537
+
538
+ $ question = new Question ('Please select a bundle ' , 'FrameworkBundle ' );
539
+ $ question ->setAutocompleterValues (new AutocompleteValues (array ('irrelevant ' => 'AcmeDemoBundle ' , 'AsseticBundle ' , 'SecurityBundle ' , 'FooBundle ' )));
540
+
541
+ $ this ->assertEquals ('AcmeDemoBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
542
+ $ this ->assertEquals ('AsseticBundleTest ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
543
+ $ this ->assertEquals ('FrameworkBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
544
+ $ this ->assertEquals ('SecurityBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
545
+ $ this ->assertEquals ('FooBundleTest ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
546
+ $ this ->assertEquals ('AcmeDemoBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
547
+ $ this ->assertEquals ('AsseticBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
548
+ $ this ->assertEquals ('FooBundle ' , $ dialog ->ask ($ this ->createInputInterfaceMock (), $ this ->createOutputInterface (), $ question ));
549
+ }
550
+
517
551
protected function getInputStream ($ input )
518
552
{
519
553
$ stream = fopen ('php://memory ' , 'r+ ' , false );
@@ -545,3 +579,18 @@ private function hasSttyAvailable()
545
579
return 0 === $ exitcode ;
546
580
}
547
581
}
582
+
583
+ class AutocompleteValues implements \IteratorAggregate
584
+ {
585
+ private $ values ;
586
+
587
+ public function __construct (array $ values )
588
+ {
589
+ $ this ->values = $ values ;
590
+ }
591
+
592
+ public function getIterator ()
593
+ {
594
+ return new \ArrayIterator ($ this ->values );
595
+ }
596
+ }
0 commit comments