12 namespace Symfony\Component\Console\Tests;
31 use Symfony\Component\EventDispatcher\EventDispatcher;
39 self::$fixturesPath = realpath(__DIR__.
'/Fixtures/');
40 require_once self::$fixturesPath.
'/FooCommand.php';
41 require_once self::$fixturesPath.
'/Foo1Command.php';
42 require_once self::$fixturesPath.
'/Foo2Command.php';
43 require_once self::$fixturesPath.
'/Foo3Command.php';
44 require_once self::$fixturesPath.
'/Foo4Command.php';
45 require_once self::$fixturesPath.
'/Foo5Command.php';
46 require_once self::$fixturesPath.
'/FoobarCommand.php';
47 require_once self::$fixturesPath.
'/BarBucCommand.php';
48 require_once self::$fixturesPath.
'/FooSubnamespaced1Command.php';
49 require_once self::$fixturesPath.
'/FooSubnamespaced2Command.php';
54 return str_replace(PHP_EOL,
"\n", $text);
64 foreach ($application->
all() as $command) {
65 $command->setHelp(str_replace(
'%command.full_name%',
'app/console %command.name%', $command->getHelp()));
72 $this->assertEquals(
'foo', $application->getName(),
'__construct() takes the application name as its first argument');
73 $this->assertEquals(
'bar', $application->getVersion(),
'__construct() takes the application version as its second argument');
74 $this->assertEquals(array(
'help',
'list'), array_keys($application->all()),
'__construct() registered the help and list commands by default');
80 $application->setName(
'foo');
81 $this->assertEquals(
'foo', $application->getName(),
'->setName() sets the name of the application');
87 $application->setVersion(
'bar');
88 $this->assertEquals(
'bar', $application->getVersion(),
'->setVersion() sets the version of the application');
94 $this->assertEquals(
'<info>foo</info> version <comment>bar</comment>', $application->getLongVersion(),
'->getLongVersion() returns the long version of the application');
100 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_gethelp.txt', $this->
normalizeLineBreaks($application->getHelp()),
'->getHelp() returns a help message');
106 $commands = $application->all();
107 $this->assertInstanceOf(
'Symfony\\Component\\Console\\Command\\HelpCommand', $commands[
'help'],
'->all() returns the registered commands');
110 $commands = $application->all(
'foo');
111 $this->assertCount(1, $commands,
'->all() takes a namespace as its first argument');
117 $command = $application->register(
'foo');
118 $this->assertEquals(
'foo', $command->getName(),
'->register() registers a new command');
125 $commands = $application->all();
126 $this->assertEquals($foo, $commands[
'foo:bar'],
'->add() registers a command');
130 $commands = $application->all();
131 $this->assertEquals(array($foo, $foo1), array($commands[
'foo:bar'], $commands[
'foo:bar1']),
'->addCommands() registers an array of commands');
147 $this->assertTrue($application->has(
'list'),
'->has() returns true if a named command is registered');
148 $this->assertFalse($application->has(
'afoobar'),
'->has() returns false if a named command is not registered');
151 $this->assertTrue($application->has(
'afoobar'),
'->has() returns true if an alias is registered');
152 $this->assertEquals($foo, $application->get(
'foo:bar'),
'->get() returns a command by name');
153 $this->assertEquals($foo, $application->get(
'afoobar'),
'->get() returns a command by alias');
158 $r = new \ReflectionObject($application);
159 $p = $r->getProperty(
'wantHelps');
160 $p->setAccessible(
true);
161 $p->setValue($application,
true);
162 $command = $application->get(
'foo:bar');
163 $this->assertInstanceOf(
'Symfony\Component\Console\Command\HelpCommand', $command,
'->get() returns the help command if --help is provided as the input');
169 $application->setAutoExit(
false);
170 $application->setCatchExceptions(
false);
173 $tester->run(array(
'-h' =>
true,
'-q' =>
true), array(
'decorated' =>
false));
175 $this->assertEmpty($tester->getDisplay(
true));
185 $application->get(
'foofoo');
193 $this->assertEquals(array(
'foo'), $application->getNamespaces(),
'->getNamespaces() returns an array of unique used namespaces');
200 $this->assertEquals(
'foo', $application->findNamespace(
'foo'),
'->findNamespace() returns the given namespace if it exists');
201 $this->assertEquals(
'foo', $application->findNamespace(
'f'),
'->findNamespace() finds a namespace given an abbreviation');
203 $this->assertEquals(
'foo', $application->findNamespace(
'foo'),
'->findNamespace() returns the given namespace if it exists');
211 $this->assertEquals(
'foo', $application->findNamespace(
'foo'),
'->findNamespace() returns commands even if the commands are only contained in subnamespaces');
224 $application->findNamespace(
'f');
234 $application->findNamespace(
'bar');
248 $application->find($commandName =
'foo1');
256 $this->assertInstanceOf(
'FooCommand', $application->find(
'foo:bar'),
'->find() returns a command if its name exists');
257 $this->assertInstanceOf(
'Symfony\Component\Console\Command\HelpCommand', $application->find(
'h'),
'->find() returns a command if its name exists');
258 $this->assertInstanceOf(
'FooCommand', $application->find(
'f:bar'),
'->find() returns a command if the abbreviation for the namespace exists');
259 $this->assertInstanceOf(
'FooCommand', $application->find(
'f:b'),
'->find() returns a command if the abbreviation for the namespace and the command name exist');
260 $this->assertInstanceOf(
'FooCommand', $application->find(
'a'),
'->find() returns a command if the abbreviation exists for an alias');
268 $this->setExpectedException(
'InvalidArgumentException', $expectedExceptionMessage);
275 $application->find($abbreviation);
281 array(
'f',
'Command "f" is not defined.'),
282 array(
'a',
'Command "a" is ambiguous (afoobar, afoobar1 and 1 more).'),
283 array(
'foo:b',
'Command "foo:b" is ambiguous (foo:bar, foo:bar1 and 1 more).'),
293 $this->assertInstanceOf(
'Foo3Command', $application->find(
'foo3:bar'),
'->find() returns the good command even if a namespace has same name');
294 $this->assertInstanceOf(
'Foo4Command', $application->find(
'foo3:bar:toh'),
'->find() returns a command even if its namespace equals another command name');
303 $this->assertInstanceOf(
'FoobarCommand', $application->find(
'f:f'));
311 $this->assertInstanceOf(
'Foo4Command', $application->find(
'f::t'));
323 $application->find($name);
343 $application->find(
'foo:baR');
344 $this->fail(
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
345 }
catch (\Exception $e) {
346 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
347 $this->assertRegExp(
'/Did you mean one of these/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
348 $this->assertRegExp(
'/foo1:bar/', $e->getMessage());
349 $this->assertRegExp(
'/foo:bar/', $e->getMessage());
354 $application->find(
'foo2:bar');
355 $this->fail(
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
356 }
catch (\Exception $e) {
357 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
358 $this->assertRegExp(
'/Did you mean one of these/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
359 $this->assertRegExp(
'/foo1/', $e->getMessage());
367 $a = $application->find(
'foo3:');
368 $this->fail(
'->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives');
369 }
catch (\Exception $e) {
370 $this->assertInstanceOf(
'\InvalidArgumentException', $e);
371 $this->assertRegExp(
'/foo3:bar/', $e->getMessage());
372 $this->assertRegExp(
'/foo3:bar:toh/', $e->getMessage());
385 $application->find($commandName =
'Unknown command');
386 $this->fail(
'->find() throws an \InvalidArgumentException if command does not exist');
387 }
catch (\Exception $e) {
388 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if command does not exist');
389 $this->assertEquals(sprintf(
'Command "%s" is not defined.', $commandName), $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, without alternatives');
395 $application->find($commandName =
'bar1');
396 $this->fail(
'->find() throws an \InvalidArgumentException if command does not exist');
397 }
catch (\Exception $e) {
398 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if command does not exist');
399 $this->assertRegExp(sprintf(
'/Command "%s" is not defined./', $commandName), $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
400 $this->assertRegExp(
'/afoobar1/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, with alternative : "afoobar1"');
401 $this->assertRegExp(
'/foo:bar1/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
402 $this->assertNotRegExp(
'/foo:bar(?>!1)/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative');
408 $fooCommand = new \FooCommand();
409 $fooCommand->setAliases(array(
'foo2'));
412 $application->add($fooCommand);
414 $result = $application->find(
'foo');
416 $this->assertSame($fooCommand, $result);
426 $application->add(
new \foo3Command());
429 $application->find(
'Unknown-namespace:Unknown-command');
430 $this->fail(
'->find() throws an \InvalidArgumentException if namespace does not exist');
431 }
catch (\Exception $e) {
432 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if namespace does not exist');
433 $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');
437 $application->find(
'foo2:command');
438 $this->fail(
'->find() throws an \InvalidArgumentException if namespace does not exist');
439 }
catch (\Exception $e) {
440 $this->assertInstanceOf(
'\InvalidArgumentException', $e,
'->find() throws an \InvalidArgumentException if namespace does not exist');
441 $this->assertRegExp(
'/There are no commands defined in the "foo2" namespace./', $e->getMessage(),
'->find() throws an \InvalidArgumentException if namespace does not exist, with alternative');
442 $this->assertRegExp(
'/foo/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"');
443 $this->assertRegExp(
'/foo1/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
444 $this->assertRegExp(
'/foo3/', $e->getMessage(),
'->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
450 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getNamespaces'));
451 $application->expects($this->once())
452 ->method(
'getNamespaces')
453 ->will($this->returnValue(array(
'foo:sublong',
'bar:sub')));
455 $this->assertEquals(
'foo:sublong', $application->findNamespace(
'f:sub'));
467 $application->find(
'foo::bar');
472 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getTerminalWidth'));
473 $application->setAutoExit(
false);
474 $application->expects($this->any())
475 ->method(
'getTerminalWidth')
476 ->will($this->returnValue(120));
479 $application->setCatchExceptions(
true);
480 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
481 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception1.txt', $tester->getDisplay(
true),
'->setCatchExceptions() sets the catch exception flag');
483 $application->setCatchExceptions(
false);
485 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
486 $this->fail(
'->setCatchExceptions() sets the catch exception flag');
487 }
catch (\Exception $e) {
488 $this->assertInstanceOf(
'\Exception', $e,
'->setCatchExceptions() sets the catch exception flag');
489 $this->assertEquals(
'Command "foo" is not defined.', $e->getMessage(),
'->setCatchExceptions() sets the catch exception flag');
501 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_astext1.txt', $this->
normalizeLineBreaks($application->asText()),
'->asText() returns a text representation of the application');
502 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_astext2.txt', $this->
normalizeLineBreaks($application->asText(
'foo')),
'->asText() returns a text representation of the application');
513 $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.
'/application_asxml1.txt', $application->asXml(),
'->asXml() returns an XML representation of the application');
514 $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.
'/application_asxml2.txt', $application->asXml(
'foo'),
'->asXml() returns an XML representation of the application');
519 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getTerminalWidth'));
520 $application->setAutoExit(
false);
521 $application->expects($this->any())
522 ->method(
'getTerminalWidth')
523 ->will($this->returnValue(120));
526 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
527 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception1.txt', $tester->getDisplay(
true),
'->renderException() renders a pretty exception');
530 $this->assertContains(
'Exception trace', $tester->getDisplay(),
'->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
532 $tester->run(array(
'command' =>
'list',
'--foo' =>
true), array(
'decorated' =>
false));
533 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception2.txt', $tester->getDisplay(
true),
'->renderException() renders the command synopsis when an exception occurs in the context of a command');
537 $tester->run(array(
'command' =>
'foo3:bar'), array(
'decorated' =>
false));
538 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception3.txt', $tester->getDisplay(
true),
'->renderException() renders a pretty exceptions with previous exceptions');
540 $tester->run(array(
'command' =>
'foo3:bar'), array(
'decorated' =>
true));
541 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception3decorated.txt', $tester->getDisplay(
true),
'->renderException() renders a pretty exceptions with previous exceptions');
543 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getTerminalWidth'));
544 $application->setAutoExit(
false);
545 $application->expects($this->any())
546 ->method(
'getTerminalWidth')
547 ->will($this->returnValue(32));
550 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
551 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception4.txt', $tester->getDisplay(
true),
'->renderException() wraps messages when they are bigger than the terminal');
556 if (!function_exists(
'mb_strwidth')) {
557 $this->markTestSkipped(
'The "mb_strwidth" function is not available');
560 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getTerminalWidth'));
561 $application->setAutoExit(
false);
562 $application->expects($this->any())
563 ->method(
'getTerminalWidth')
564 ->will($this->returnValue(120));
565 $application->register(
'foo')->setCode(
function () {
566 throw new \Exception(
'エラーメッセージ');
570 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
571 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception_doublewidth1.txt', $tester->getDisplay(
true),
'->renderException() renders a pretty exceptions with previous exceptions');
573 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
true));
574 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception_doublewidth1decorated.txt', $tester->getDisplay(
true),
'->renderException() renders a pretty exceptions with previous exceptions');
576 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'getTerminalWidth'));
577 $application->setAutoExit(
false);
578 $application->expects($this->any())
579 ->method(
'getTerminalWidth')
580 ->will($this->returnValue(32));
581 $application->register(
'foo')->setCode(
function () {
582 throw new \Exception(
'コマンドの実行中にエラーが発生しました。');
585 $tester->run(array(
'command' =>
'foo'), array(
'decorated' =>
false));
586 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_renderexception_doublewidth2.txt', $tester->getDisplay(
true),
'->renderException() wraps messages when they are bigger than the terminal');
592 $application->setAutoExit(
false);
593 $application->setCatchExceptions(
false);
595 $_SERVER[
'argv'] = array(
'cli.php',
'foo:bar1');
601 $this->assertInstanceOf(
'Symfony\Component\Console\Input\ArgvInput', $command->input,
'->run() creates an ArgvInput by default if none is given');
602 $this->assertInstanceOf(
'Symfony\Component\Console\Output\ConsoleOutput', $command->output,
'->run() creates a ConsoleOutput by default if none is given');
605 $application->setAutoExit(
false);
606 $application->setCatchExceptions(
false);
611 $tester->run(array(), array(
'decorated' =>
false));
612 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run1.txt', $tester->getDisplay(
true),
'->run() runs the list command if no argument is passed');
614 $tester->run(array(
'--help' =>
true), array(
'decorated' =>
false));
615 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run2.txt', $tester->getDisplay(
true),
'->run() runs the help command if --help is passed');
617 $tester->run(array(
'-h' =>
true), array(
'decorated' =>
false));
618 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run2.txt', $tester->getDisplay(
true),
'->run() runs the help command if -h is passed');
620 $tester->run(array(
'command' =>
'list',
'--help' =>
true), array(
'decorated' =>
false));
621 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run3.txt', $tester->getDisplay(
true),
'->run() displays the help if --help is passed');
623 $tester->run(array(
'command' =>
'list',
'-h' =>
true), array(
'decorated' =>
false));
624 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run3.txt', $tester->getDisplay(
true),
'->run() displays the help if -h is passed');
626 $tester->run(array(
'--ansi' =>
true));
627 $this->assertTrue($tester->getOutput()->isDecorated(),
'->run() forces color output if --ansi is passed');
629 $tester->run(array(
'--no-ansi' =>
true));
630 $this->assertFalse($tester->getOutput()->isDecorated(),
'->run() forces color output to be disabled if --no-ansi is passed');
632 $tester->run(array(
'--version' =>
true), array(
'decorated' =>
false));
633 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run4.txt', $tester->getDisplay(
true),
'->run() displays the program version if --version is passed');
635 $tester->run(array(
'-V' =>
true), array(
'decorated' =>
false));
636 $this->assertStringEqualsFile(self::$fixturesPath.
'/application_run4.txt', $tester->getDisplay(
true),
'->run() displays the program version if -v is passed');
638 $tester->run(array(
'command' =>
'list',
'--quiet' =>
true));
639 $this->assertSame(
'', $tester->getDisplay(),
'->run() removes all output if --quiet is passed');
641 $tester->run(array(
'command' =>
'list',
'-q' =>
true));
642 $this->assertSame(
'', $tester->getDisplay(),
'->run() removes all output if -q is passed');
644 $tester->run(array(
'command' =>
'list',
'--verbose' =>
true));
645 $this->assertSame(
Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(),
'->run() sets the output to verbose if --verbose is passed');
647 $tester->run(array(
'command' =>
'list',
'--verbose' => 1));
648 $this->assertSame(
Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(),
'->run() sets the output to verbose if --verbose=1 is passed');
650 $tester->run(array(
'command' =>
'list',
'--verbose' => 2));
651 $this->assertSame(
Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(),
'->run() sets the output to very verbose if --verbose=2 is passed');
653 $tester->run(array(
'command' =>
'list',
'--verbose' => 3));
654 $this->assertSame(
Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(),
'->run() sets the output to debug if --verbose=3 is passed');
656 $tester->run(array(
'command' =>
'list',
'--verbose' => 4));
657 $this->assertSame(
Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(),
'->run() sets the output to verbose if unknown --verbose level is passed');
659 $tester->run(array(
'command' =>
'list',
'-v' =>
true));
660 $this->assertSame(
Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(),
'->run() sets the output to verbose if -v is passed');
662 $tester->run(array(
'command' =>
'list',
'-vv' =>
true));
665 $tester->run(array(
'command' =>
'list',
'-vvv' =>
true));
666 $this->assertSame(
Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(),
'->run() sets the output to verbose if -v is passed');
669 $application->setAutoExit(
false);
670 $application->setCatchExceptions(
false);
674 $tester->run(array(
'command' =>
'foo:bar',
'--no-interaction' =>
true), array(
'decorated' =>
false));
675 $this->assertSame(
'called'.PHP_EOL, $tester->getDisplay(),
'->run() does not call interact() if --no-interaction is passed');
677 $tester->run(array(
'command' =>
'foo:bar',
'-n' =>
true), array(
'decorated' =>
false));
678 $this->assertSame(
'called'.PHP_EOL, $tester->getDisplay(),
'->run() does not call interact() if -n is passed');
691 $application->setAutoExit(
false);
692 $application->setCatchExceptions(
false);
695 $output =
new StreamOutput(fopen(
'php://memory',
'w',
false));
697 $input =
new ArgvInput(array(
'cli.php',
'-v',
'foo:bar'));
698 $application->run($input, $output);
700 $input =
new ArgvInput(array(
'cli.php',
'--verbose',
'foo:bar'));
701 $application->run($input, $output);
706 $exception = new \Exception(
'', 4);
708 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'doRun'));
709 $application->setAutoExit(
false);
710 $application->expects($this->once())
712 ->will($this->throwException($exception));
716 $this->assertSame(4, $exitCode,
'->run() returns integer exit code extracted from raised exception');
721 $exception = new \Exception(
'', 0);
723 $application = $this->getMock(
'Symfony\Component\Console\Application', array(
'doRun'));
724 $application->setAutoExit(
false);
725 $application->expects($this->once())
727 ->will($this->throwException($exception));
731 $this->assertSame(1, $exitCode,
'->run() returns exit code 1 when exception code is 0');
741 $application->setAutoExit(
false);
742 $application->setCatchExceptions(
false);
745 ->setDefinition(array($def))
749 $input =
new ArrayInput(array(
'command' =>
'foo'));
751 $application->run($input, $output);
766 $application->setAutoExit(
false);
767 $application->setCatchExceptions(
false);
769 $helperSet = $application->getHelperSet();
771 $this->assertTrue($helperSet->has(
'formatter'));
772 $this->assertTrue($helperSet->has(
'dialog'));
773 $this->assertTrue($helperSet->has(
'progress'));
779 $application->setAutoExit(
false);
780 $application->setCatchExceptions(
false);
784 $helperSet = $application->getHelperSet();
786 $this->assertTrue($helperSet->has(
'formatter'));
789 $this->assertFalse($helperSet->has(
'dialog'));
790 $this->assertFalse($helperSet->has(
'progress'));
796 $application->setAutoExit(
false);
797 $application->setCatchExceptions(
false);
801 $helperSet = $application->getHelperSet();
803 $this->assertTrue($helperSet->has(
'formatter'));
806 $this->assertFalse($helperSet->has(
'dialog'));
807 $this->assertFalse($helperSet->has(
'progress'));
813 $application->setAutoExit(
false);
814 $application->setCatchExceptions(
false);
816 $inputDefinition = $application->getDefinition();
818 $this->assertTrue($inputDefinition->hasArgument(
'command'));
820 $this->assertTrue($inputDefinition->hasOption(
'help'));
821 $this->assertTrue($inputDefinition->hasOption(
'quiet'));
822 $this->assertTrue($inputDefinition->hasOption(
'verbose'));
823 $this->assertTrue($inputDefinition->hasOption(
'version'));
824 $this->assertTrue($inputDefinition->hasOption(
'ansi'));
825 $this->assertTrue($inputDefinition->hasOption(
'no-ansi'));
826 $this->assertTrue($inputDefinition->hasOption(
'no-interaction'));
832 $application->setAutoExit(
false);
833 $application->setCatchExceptions(
false);
835 $inputDefinition = $application->getDefinition();
838 $this->assertFalse($inputDefinition->hasArgument(
'command'));
840 $this->assertFalse($inputDefinition->hasOption(
'help'));
841 $this->assertFalse($inputDefinition->hasOption(
'quiet'));
842 $this->assertFalse($inputDefinition->hasOption(
'verbose'));
843 $this->assertFalse($inputDefinition->hasOption(
'version'));
844 $this->assertFalse($inputDefinition->hasOption(
'ansi'));
845 $this->assertFalse($inputDefinition->hasOption(
'no-ansi'));
846 $this->assertFalse($inputDefinition->hasOption(
'no-interaction'));
848 $this->assertTrue($inputDefinition->hasOption(
'custom'));
854 $application->setAutoExit(
false);
855 $application->setCatchExceptions(
false);
859 $inputDefinition = $application->getDefinition();
862 $this->assertFalse($inputDefinition->hasArgument(
'command'));
864 $this->assertFalse($inputDefinition->hasOption(
'help'));
865 $this->assertFalse($inputDefinition->hasOption(
'quiet'));
866 $this->assertFalse($inputDefinition->hasOption(
'verbose'));
867 $this->assertFalse($inputDefinition->hasOption(
'version'));
868 $this->assertFalse($inputDefinition->hasOption(
'ansi'));
869 $this->assertFalse($inputDefinition->hasOption(
'no-ansi'));
870 $this->assertFalse($inputDefinition->hasOption(
'no-interaction'));
872 $this->assertTrue($inputDefinition->hasOption(
'custom'));
878 $application->setAutoExit(
false);
882 $output->
write(
'foo.');
886 $tester->run(array(
'command' =>
'foo'));
887 $this->assertEquals(
'before.foo.after.', $tester->getDisplay());
898 $application->setAutoExit(
false);
899 $application->setCatchExceptions(
false);
902 throw new \RuntimeException(
'foo');
906 $tester->run(array(
'command' =>
'foo'));
913 $application->setAutoExit(
false);
916 $output->
write(
'foo.');
918 throw new \RuntimeException(
'foo');
922 $tester->run(array(
'command' =>
'foo'));
923 $this->assertContains(
'before.foo.after.caught.', $tester->getDisplay());
930 $application->setAutoExit(
false);
933 $output->
write(
'foo.');
937 $exitCode = $tester->run(array(
'command' =>
'foo'));
938 $this->assertContains(
'before.after.', $tester->getDisplay());
945 $originalDimensions = $application->getTerminalDimensions();
946 $this->assertCount(2, $originalDimensions);
949 if ($originalDimensions[0] == $width) {
953 $application->setTerminalDimensions($width, 80);
954 $this->assertSame(array($width, 80), $application->getTerminalDimensions());
959 $dispatcher =
new EventDispatcher();
960 $dispatcher->addListener(
'console.command',
function (
ConsoleCommandEvent $event) use ($skipCommand) {
967 $dispatcher->addListener(
'console.terminate',
function (
ConsoleTerminateEvent $event) use ($skipCommand) {
985 $command = new \FooCommand();
988 $application->setAutoExit(
false);
989 $application->add($command);
990 $application->setDefaultCommand($command->getName());
993 $tester->run(array());
994 $this->assertEquals(
'interact called'.PHP_EOL.
'called'.PHP_EOL, $tester->getDisplay(),
'Application runs the default set command if different from \'list\' command');
997 $application->setAutoExit(
false);
1000 $tester->run(array());
1002 $this->assertEquals(
'interact called'.PHP_EOL.
'called'.PHP_EOL, $tester->getDisplay(),
'Application runs the default set command if different from \'list\' command');
1007 if (!function_exists(
'posix_isatty')) {
1008 $this->markTestSkipped(
'posix_isatty function is required');
1012 $application->setAutoExit(
false);
1015 $tester->run(array(
'command' =>
'help'));
1017 $this->assertFalse($tester->getInput()->hasParameterOption(array(
'--no-interaction',
'-n')));
1019 $inputStream = $application->getHelperSet()->get(
'question')->getInputStream();
1020 $this->assertEquals($tester->getInput()->isInteractive(), @posix_isatty($inputStream));
1054 parent::__construct();
1056 $command = new \FooCommand();
1057 $this->
add($command);