/**
  * @dataProvider provider
  */
 public function testRun($command, $result)
 {
     $app = new \Phinx\Console\PhinxApplication('testing');
     $app->setAutoExit(false);
     // Set autoExit to false when testing
     $app->setCatchExceptions(false);
     $appTester = new ApplicationTester($app);
     $appTester->run(array('command' => $command));
     $stream = $appTester->getOutput()->getStream();
     rewind($stream);
     $this->assertRegExp($result, stream_get_contents($stream));
 }
Esempio n. 2
0
 public function testRun()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->add($command = new \Foo1Command());
     $_SERVER['argv'] = array('cli.php', 'foo:bar1');
     ob_start();
     $application->run();
     ob_end_clean();
     $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given');
     $this->assertInstanceOf('Symfony\\Component\\Console\\Output\\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $this->ensureStaticCommandHelp($application);
     $tester = new ApplicationTester($application);
     $tester->run(array(), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run1.txt', $tester->getDisplay(true), '->run() runs the list command if no argument is passed');
     $tester->run(array('--help' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if --help is passed');
     $tester->run(array('-h' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if -h is passed');
     $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if --help is passed');
     $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if -h is passed');
     $tester->run(array('--ansi' => true));
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
     $tester->run(array('--no-ansi' => true));
     $this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
     $tester->run(array('--version' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if --version is passed');
     $tester->run(array('-V' => true), array('decorated' => false));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if -v is passed');
     $tester->run(array('command' => 'list', '--quiet' => true));
     $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
     $tester->run(array('command' => 'list', '-q' => true));
     $this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');
     $tester->run(array('command' => 'list', '--verbose' => true));
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
     $tester->run(array('command' => 'list', '--verbose' => 1));
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed');
     $tester->run(array('command' => 'list', '--verbose' => 2));
     $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed');
     $tester->run(array('command' => 'list', '--verbose' => 3));
     $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');
     $tester->run(array('command' => 'list', '--verbose' => 4));
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');
     $tester->run(array('command' => 'list', '-v' => true));
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
     $tester->run(array('command' => 'list', '-vv' => true));
     $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
     $tester->run(array('command' => 'list', '-vvv' => true));
     $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->add(new \FooCommand());
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'foo:bar', '--no-interaction' => true), array('decorated' => false));
     $this->assertSame('called' . PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');
     $tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
     $this->assertSame('called' . PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
 }
Esempio n. 3
0
 public function testRun()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->add($command = new \Foo1Command());
     $_SERVER['argv'] = array('cli.php', 'foo:bar1');
     ob_start();
     $application->run();
     ob_end_clean();
     $this->assertEquals('Symfony\\Component\\Console\\Input\\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
     $this->assertEquals('Symfony\\Component\\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', $this->normalize($tester->getDisplay()), '->run() runs the list command if no argument is passed');
     $tester->run(array('--help' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $this->normalize($tester->getDisplay()), '->run() runs the help command if --help is passed');
     $tester->run(array('-h' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $this->normalize($tester->getDisplay()), '->run() runs the help command if -h 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', $this->normalize($tester->getDisplay()), '->run() displays the help if --help is passed');
     $tester->run(array('command' => 'list', '-h' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $this->normalize($tester->getDisplay()), '->run() displays the help if -h is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('--ansi' => true));
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
     $tester->run(array('-a' => true));
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if -a 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', $this->normalize($tester->getDisplay()), '->run() displays the program version if --version is passed');
     $tester->run(array('-V' => true));
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $this->normalize($tester->getDisplay()), '->run() displays the program version if -v is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'list', '--quiet' => true));
     $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if --quiet is passed');
     $tester->run(array('command' => 'list', '-q' => true));
     $this->assertEquals('', $this->normalize($tester->getDisplay()), '->run() removes all output if -q 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');
     $tester->run(array('command' => 'list', '-v' => true));
     $this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is -v is passed');
     $application = new Application();
     $application->setAutoExit(false);
     $application->setCatchExceptions(false);
     $application->add(new \FooCommand());
     $tester = new ApplicationTester($application);
     $tester->run(array('command' => 'foo:bar', '--no-interaction' => true));
     $this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if --no-interaction is passed');
     $tester->run(array('command' => 'foo:bar', '-n' => true));
     $this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if -n is passed');
 }