Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Tests / ApplicationTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests;
13
14 use Symfony\Component\Console\Application;
15 use Symfony\Component\Console\Input\ArrayInput;
16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputOption;
18 use Symfony\Component\Console\Output\NullOutput;
19 use Symfony\Component\Console\Output\Output;
20 use Symfony\Component\Console\Tester\ApplicationTester;
21
22 class ApplicationTest extends \PHPUnit_Framework_TestCase
23 {
24     protected static $fixturesPath;
25
26     public static function setUpBeforeClass()
27     {
28         self::$fixturesPath = realpath(__DIR__.'/Fixtures/');
29         require_once self::$fixturesPath.'/FooCommand.php';
30         require_once self::$fixturesPath.'/Foo1Command.php';
31         require_once self::$fixturesPath.'/Foo2Command.php';
32         require_once self::$fixturesPath.'/Foo3Command.php';
33     }
34
35     protected function normalizeLineBreaks($text)
36     {
37         return str_replace(PHP_EOL, "\n", $text);
38     }
39
40     /**
41      * Replaces the dynamic placeholders of the command help text with a static version.
42      * The placeholder %command.full_name% includes the script path that is not predictable
43      * and can not be tested against.
44      */
45     protected function ensureStaticCommandHelp(Application $application)
46     {
47         foreach ($application->all() as $command) {
48             $command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
49         }
50     }
51
52     public function testConstructor()
53     {
54         $application = new Application('foo', 'bar');
55         $this->assertEquals('foo', $application->getName(), '__construct() takes the application name as its first argument');
56         $this->assertEquals('bar', $application->getVersion(), '__construct() takes the application version as its first argument');
57         $this->assertEquals(array('help', 'list'), array_keys($application->all()), '__construct() registered the help and list commands by default');
58     }
59
60     public function testSetGetName()
61     {
62         $application = new Application();
63         $application->setName('foo');
64         $this->assertEquals('foo', $application->getName(), '->setName() sets the name of the application');
65     }
66
67     public function testSetGetVersion()
68     {
69         $application = new Application();
70         $application->setVersion('bar');
71         $this->assertEquals('bar', $application->getVersion(), '->setVersion() sets the version of the application');
72     }
73
74     public function testGetLongVersion()
75     {
76         $application = new Application('foo', 'bar');
77         $this->assertEquals('<info>foo</info> version <comment>bar</comment>', $application->getLongVersion(), '->getLongVersion() returns the long version of the application');
78     }
79
80     public function testHelp()
81     {
82         $application = new Application();
83         $this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->setHelp() returns a help message');
84     }
85
86     public function testAll()
87     {
88         $application = new Application();
89         $commands = $application->all();
90         $this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
91
92         $application->add(new \FooCommand());
93         $commands = $application->all('foo');
94         $this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
95     }
96
97     public function testRegister()
98     {
99         $application = new Application();
100         $command = $application->register('foo');
101         $this->assertEquals('foo', $command->getName(), '->register() registers a new command');
102     }
103
104     public function testAdd()
105     {
106         $application = new Application();
107         $application->add($foo = new \FooCommand());
108         $commands = $application->all();
109         $this->assertEquals($foo, $commands['foo:bar'], '->add() registers a command');
110
111         $application = new Application();
112         $application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
113         $commands = $application->all();
114         $this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
115     }
116
117     public function testHasGet()
118     {
119         $application = new Application();
120         $this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
121         $this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
122
123         $application->add($foo = new \FooCommand());
124         $this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
125         $this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
126         $this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
127
128         try {
129             $application->get('foofoo');
130             $this->fail('->get() throws an \InvalidArgumentException if the command does not exist');
131         } catch (\Exception $e) {
132             $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an \InvalidArgumentException if the command does not exist');
133             $this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->get() throws an \InvalidArgumentException if the command does not exist');
134         }
135
136         $application = new Application();
137         $application->add($foo = new \FooCommand());
138         // simulate --help
139         $r = new \ReflectionObject($application);
140         $p = $r->getProperty('wantHelps');
141         $p->setAccessible(true);
142         $p->setValue($application, true);
143         $command = $application->get('foo:bar');
144         $this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($command), '->get() returns the help command if --help is provided as the input');
145     }
146
147     public function testGetNamespaces()
148     {
149         $application = new Application();
150         $application->add(new \FooCommand());
151         $application->add(new \Foo1Command());
152         $this->assertEquals(array('foo'), $application->getNamespaces(), '->getNamespaces() returns an array of unique used namespaces');
153     }
154
155     public function testFindNamespace()
156     {
157         $application = new Application();
158         $application->add(new \FooCommand());
159         $this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
160         $this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
161         $application->add(new \Foo2Command());
162         $this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
163         try {
164             $application->findNamespace('f');
165             $this->fail('->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
166         } catch (\Exception $e) {
167             $this->assertInstanceOf('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
168             $this->assertEquals('The namespace "f" is ambiguous (foo, foo1).', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
169         }
170
171         try {
172             $application->findNamespace('bar');
173             $this->fail('->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
174         } catch (\Exception $e) {
175             $this->assertInstanceOf('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
176             $this->assertEquals('There are no commands defined in the "bar" namespace.', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
177         }
178     }
179
180     public function testFind()
181     {
182         $application = new Application();
183         $application->add(new \FooCommand());
184         $this->assertEquals('FooCommand', get_class($application->find('foo:bar')), '->find() returns a command if its name exists');
185         $this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($application->find('h')), '->find() returns a command if its name exists');
186         $this->assertEquals('FooCommand', get_class($application->find('f:bar')), '->find() returns a command if the abbreviation for the namespace exists');
187         $this->assertEquals('FooCommand', get_class($application->find('f:b')), '->find() returns a command if the abbreviation for the namespace and the command name exist');
188         $this->assertEquals('FooCommand', get_class($application->find('a')), '->find() returns a command if the abbreviation exists for an alias');
189
190         $application->add(new \Foo1Command());
191         $application->add(new \Foo2Command());
192
193         try {
194             $application->find('f');
195             $this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
196         } catch (\Exception $e) {
197             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
198             $this->assertRegExp('/Command "f" is not defined./', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
199         }
200
201         try {
202             $application->find('a');
203             $this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
204         } catch (\Exception $e) {
205             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
206             $this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
207         }
208
209         try {
210             $application->find('foo:b');
211             $this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
212         } catch (\Exception $e) {
213             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
214             $this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
215         }
216     }
217
218     public function testFindAlternativeExceptionMessage()
219     {
220         $application = new Application();
221         $application->add(new \FooCommand());
222
223         // Command + singular
224         try {
225             $application->find('foo:baR');
226             $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
227         } catch (\Exception $e) {
228             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
229             $this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
230         }
231
232         // Namespace + singular
233         try {
234             $application->find('foO:bar');
235             $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
236         } catch (\Exception $e) {
237             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
238             $this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
239         }
240
241
242         $application->add(new \Foo1Command());
243         $application->add(new \Foo2Command());
244
245         // Command + plural
246         try {
247             $application->find('foo:baR');
248             $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
249         } catch (\Exception $e) {
250             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
251             $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
252         }
253
254         // Namespace + plural
255         try {
256             $application->find('foo2:bar');
257             $this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
258         } catch (\Exception $e) {
259             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
260             $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
261         }
262     }
263
264     public function testFindAlternativeCommands()
265     {
266         $application = new Application();
267
268         $application->add(new \FooCommand());
269         $application->add(new \Foo1Command());
270         $application->add(new \Foo2Command());
271
272         try {
273             $application->find($commandName = 'Unknown command');
274             $this->fail('->find() throws an \InvalidArgumentException if command does not exist');
275         } catch (\Exception $e) {
276             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
277             $this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without alternatives');
278         }
279
280         try {
281             $application->find($commandName = 'foo');
282             $this->fail('->find() throws an \InvalidArgumentException if command does not exist');
283         } catch (\Exception $e) {
284             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
285             $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
286             $this->assertRegExp('/foo:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar"');
287             $this->assertRegExp('/foo1:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo1:bar"');
288             $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
289         }
290
291         // Test if "foo1" command throw an "\InvalidArgumentException" and does not contain
292         // "foo:bar" as alternative because "foo1" is too far from "foo:bar"
293         try {
294             $application->find($commandName = 'foo1');
295             $this->fail('->find() throws an \InvalidArgumentException if command does not exist');
296         } catch (\Exception $e) {
297             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
298             $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
299             $this->assertFalse(strpos($e->getMessage(), 'foo:bar'), '->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative');
300         }
301     }
302
303     public function testFindAlternativeNamespace()
304     {
305         $application = new Application();
306
307         $application->add(new \FooCommand());
308         $application->add(new \Foo1Command());
309         $application->add(new \Foo2Command());
310         $application->add(new \foo3Command());
311
312         try {
313             $application->find('Unknown-namespace:Unknown-command');
314             $this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
315         } catch (\Exception $e) {
316             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
317             $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, without alternatives');
318         }
319
320         try {
321             $application->find('foo2:command');
322             $this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
323         } catch (\Exception $e) {
324             $this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
325             $this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative');
326             $this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"');
327             $this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
328             $this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
329         }
330     }
331
332     public function testSetCatchExceptions()
333     {
334         $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
335         $application->setAutoExit(false);
336         $application->expects($this->any())
337             ->method('getTerminalWidth')
338             ->will($this->returnValue(120));
339         $tester = new ApplicationTester($application);
340
341         $application->setCatchExceptions(true);
342         $tester->run(array('command' => 'foo'), array('decorated' => false));
343         $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->setCatchExceptions() sets the catch exception flag');
344
345         $application->setCatchExceptions(false);
346         try {
347             $tester->run(array('command' => 'foo'), array('decorated' => false));
348             $this->fail('->setCatchExceptions() sets the catch exception flag');
349         } catch (\Exception $e) {
350             $this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
351             $this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
352         }
353     }
354
355     public function testAsText()
356     {
357         $application = new Application();
358         $application->add(new \FooCommand);
359         $this->ensureStaticCommandHelp($application);
360         $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application');
361         $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application');
362     }
363
364     public function testAsXml()
365     {
366         $application = new Application();
367         $application->add(new \FooCommand);
368         $this->ensureStaticCommandHelp($application);
369         $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
370         $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
371     }
372
373     public function testRenderException()
374     {
375         $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
376         $application->setAutoExit(false);
377         $application->expects($this->any())
378             ->method('getTerminalWidth')
379             ->will($this->returnValue(120));
380         $tester = new ApplicationTester($application);
381
382         $tester->run(array('command' => 'foo'), array('decorated' => false));
383         $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exception');
384
385         $tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
386         $this->assertContains('Exception trace', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
387
388         $tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
389         $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
390
391         $application->add(new \Foo3Command);
392         $tester = new ApplicationTester($application);
393         $tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
394         $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');
395
396         $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
397         $application->setAutoExit(false);
398         $application->expects($this->any())
399             ->method('getTerminalWidth')
400             ->will($this->returnValue(32));
401         $tester = new ApplicationTester($application);
402
403         $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
404         $application->setAutoExit(false);
405         $application->expects($this->any())
406             ->method('getTerminalWidth')
407             ->will($this->returnValue(32));
408         $tester = new ApplicationTester($application);
409
410         $tester->run(array('command' => 'foo'), array('decorated' => false));
411         $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() wraps messages when they are bigger than the terminal');
412     }
413
414     public function testRun()
415     {
416         $application = new Application();
417         $application->setAutoExit(false);
418         $application->setCatchExceptions(false);
419         $application->add($command = new \Foo1Command());
420         $_SERVER['argv'] = array('cli.php', 'foo:bar1');
421
422         ob_start();
423         $application->run();
424         ob_end_clean();
425
426         $this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
427         $this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
428
429         $application = new Application();
430         $application->setAutoExit(false);
431         $application->setCatchExceptions(false);
432
433         $this->ensureStaticCommandHelp($application);
434         $tester = new ApplicationTester($application);
435
436         $tester->run(array(), array('decorated' => false));
437         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the list command if no argument is passed');
438
439         $tester->run(array('--help' => true), array('decorated' => false));
440         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if --help is passed');
441
442         $tester->run(array('-h' => true), array('decorated' => false));
443         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if -h is passed');
444
445         $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
446         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if --help is passed');
447
448         $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
449         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if -h is passed');
450
451         $tester->run(array('--ansi' => true));
452         $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
453
454         $tester->run(array('--no-ansi' => true));
455         $this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
456
457         $tester->run(array('--version' => true), array('decorated' => false));
458         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if --version is passed');
459
460         $tester->run(array('-V' => true), array('decorated' => false));
461         $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if -v is passed');
462
463         $tester->run(array('command' => 'list', '--quiet' => true));
464         $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
465
466         $tester->run(array('command' => 'list', '-q' => true));
467         $this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');
468
469         $tester->run(array('command' => 'list', '--verbose' => true));
470         $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
471
472         $tester->run(array('command' => 'list', '-v' => true));
473         $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
474
475         $application = new Application();
476         $application->setAutoExit(false);
477         $application->setCatchExceptions(false);
478         $application->add(new \FooCommand());
479         $tester = new ApplicationTester($application);
480
481         $tester->run(array('command' => 'foo:bar', '--no-interaction' => true), array('decorated' => false));
482         $this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');
483
484         $tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
485         $this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
486     }
487
488     /**
489      * @expectedException \LogicException
490      * @dataProvider getAddingAlreadySetDefinitionElementData
491      */
492     public function testAddingAlreadySetDefinitionElementData($def)
493     {
494         $application = new Application();
495         $application->setAutoExit(false);
496         $application->setCatchExceptions(false);
497         $application
498             ->register('foo')
499             ->setDefinition(array($def))
500             ->setCode(function (InputInterface $input, OutputInterface $output) {})
501         ;
502
503         $input = new ArrayInput(array('command' => 'foo'));
504         $output = new NullOutput();
505         $application->run($input, $output);
506     }
507
508     public function getAddingAlreadySetDefinitionElementData()
509     {
510         return array(
511             array(new InputArgument('command', InputArgument::REQUIRED)),
512             array(new InputOption('quiet', '', InputOption::VALUE_NONE)),
513             array(new InputOption('query', 'q', InputOption::VALUE_NONE)),
514         );
515     }
516 }