12 namespace Symfony\Component\Console\Tests\Helper;
30 $dialog->setHelperSet($helperSet);
32 $heroes = array(
'Superman',
'Batman',
'Spiderman');
34 $dialog->setInputStream($this->
getInputStream(
"\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
35 $this->assertEquals(
'2', $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes,
'2'));
36 $this->assertEquals(
'1', $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes));
37 $this->assertEquals(
'1', $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes));
38 $this->assertEquals(
'1', $dialog->select($output = $this->getOutputStream(),
'What is your favorite superhero?', $heroes, null,
false,
'Input "%s" is not a superhero!',
false));
40 rewind($output->getStream());
41 $this->assertContains(
'Input "Fabien" is not a superhero!', stream_get_contents($output->getStream()));
44 $this->assertEquals(
'1', $dialog->select($output = $this->getOutputStream(),
'What is your favorite superhero?', $heroes, null, 1));
46 }
catch (\InvalidArgumentException $e) {
47 $this->assertEquals(
'Value "Fabien" is invalid', $e->getMessage());
50 $this->assertEquals(array(
'1'), $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes, null,
false,
'Input "%s" is not a superhero!',
true));
51 $this->assertEquals(array(
'0',
'2'), $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes, null,
false,
'Input "%s" is not a superhero!',
true));
52 $this->assertEquals(array(
'0',
'2'), $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes, null,
false,
'Input "%s" is not a superhero!',
true));
53 $this->assertEquals(array(
'0',
'1'), $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes,
'0,1',
false,
'Input "%s" is not a superhero!',
true));
54 $this->assertEquals(array(
'0',
'1'), $dialog->select($this->getOutputStream(),
'What is your favorite superhero?', $heroes,
' 0 , 1 ',
false,
'Input "%s" is not a superhero!',
true));
63 $this->assertEquals(
'2PM', $dialog->ask($this->getOutputStream(),
'What time is it?',
'2PM'));
64 $this->assertEquals(
'8AM', $dialog->ask($output = $this->getOutputStream(),
'What time is it?',
'2PM'));
66 rewind($output->getStream());
67 $this->assertEquals(
'What time is it?', stream_get_contents($output->getStream()));
73 $this->markTestSkipped(
'`stty` is required to test autocomplete functionality');
84 $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");
87 $dialog->setInputStream($inputStream);
89 $bundles = array(
'AcmeDemoBundle',
'AsseticBundle',
'SecurityBundle',
'FooBundle');
91 $this->assertEquals(
'AcmeDemoBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
92 $this->assertEquals(
'AsseticBundleTest', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
93 $this->assertEquals(
'FrameworkBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
94 $this->assertEquals(
'SecurityBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
95 $this->assertEquals(
'FooBundleTest', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
96 $this->assertEquals(
'AcmeDemoBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
97 $this->assertEquals(
'AsseticBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
98 $this->assertEquals(
'FooBundle', $dialog->ask($this->getOutputStream(),
'Please select a bundle',
'FrameworkBundle', $bundles));
106 if (
'\\' === DIRECTORY_SEPARATOR) {
107 $this->markTestSkipped(
'This test is not supported on Windows');
114 $this->assertEquals(
'8AM', $dialog->askHiddenResponse($this->getOutputStream(),
'What time is it?'));
122 $this->assertTrue($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?'));
123 $this->assertFalse($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?',
false));
126 $this->assertTrue($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?',
false));
127 $this->assertTrue($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?',
false));
130 $this->assertFalse($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?',
true));
131 $this->assertFalse($dialog->askConfirmation($this->getOutputStream(),
'Do you like French fries?',
true));
138 $dialog->setHelperSet($helperSet);
140 $question =
'What color was the white horse of Henry IV?';
141 $error =
'This is not a color!';
142 $validator =
function ($color) use ($error) {
143 if (!in_array($color, array(
'white',
'black'))) {
144 throw new \InvalidArgumentException($error);
151 $this->assertEquals(
'white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2,
'white'));
152 $this->assertEquals(
'black', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2,
'white'));
154 $dialog->setInputStream($this->
getInputStream(
"green\nyellow\norange\n"));
156 $this->assertEquals(
'white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2,
'white'));
158 }
catch (\InvalidArgumentException $e) {
159 $this->assertEquals($error, $e->getMessage());
168 $input->setInteractive(
false);
170 $dialog->setInput($input);
172 $this->assertEquals(
'not yet', $dialog->ask($this->getOutputStream(),
'Do you have a job?',
'not yet'));
177 $stream = fopen(
'php://memory',
'r+',
false);
178 fwrite($stream, $input);
186 return new StreamOutput(fopen(
'php://memory',
'r+',
false));
191 exec(
'stty 2>&1', $output, $exitcode);
193 return $exitcode === 0;