$t->ok($tester->getOutput()->isDecorated(), '->run() forces color output if --color is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--version' => true)); $t->is($tester->getDisplay(), file_get_contents($fixtures.'/application_run4.txt'), '->run() displays the program version if --version is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--quiet' => true)); $t->is($tester->getDisplay(), '', '->run() removes all output if --quiet is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--verbose' => true)); $t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->run() sets the output to verbose is --verbose is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->addCommand(new FooCommand()); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo:bar', '--no-interaction' => true)); $t->is($tester->getDisplay(), "called\n", '->run() does not called interact() if --no-interaction is passed');
public function testRun() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->addCommand($command = new \Foo1Command()); $_SERVER['argv'] = array('cli.php', 'foo:bar1'); ob_start(); $application->run(); ob_end_clean(); $this->assertEquals('Symfony\\Components\\Console\\Input\\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given'); $this->assertEquals('Symfony\\Components\\Console\\Output\\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array()); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run1.txt', $tester->getDisplay(), '->run() runs the list command if no argument is passed'); $tester->run(array('--help' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(), '->run() runs the help command if --help is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--help' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(), '->run() displays the help if --help is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--color' => true)); $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --color is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('--version' => true)); $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(), '->run() displays the program version if --version is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--quiet' => true)); $this->assertEquals('', $tester->getDisplay(), '->run() removes all output if --quiet is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('command' => 'list', '--verbose' => true)); $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is --verbose is passed'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->addCommand(new \FooCommand()); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo:bar', '--no-interaction' => true)); $this->assertEquals("called\n", $tester->getDisplay(), '->run() does not called interact() if --no-interaction is passed'); }
$application = new Application(); $application->setAutoExit(false); $application->register('foo') ->addArgument('command') ->addArgument('foo') ->setCode(function ($input, $output) { $output->writeln('foo'); }) ; $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo', 'foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE)); // ->run() $t->diag('->run()'); $t->is($tester->getInput()->isInteractive(), false, '->execute() takes an interactive option'); $t->is($tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option'); $t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option'); // ->getInput() $t->diag('->getInput()'); $t->is($tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance'); // ->getOutput() $t->diag('->getOutput()'); rewind($tester->getOutput()->getStream()); $t->is(stream_get_contents($tester->getOutput()->getStream()), "foo\n", '->getOutput() returns the current output instance'); // ->getDisplay() $t->diag('->getDisplay()'); $t->is($tester->getDisplay(), "foo\n", '->getDisplay() returns the display of the last execution');