Exemplo n.º 1
0
 public function testGetDisplay()
 {
     $output = $this->tester->getOutput();
     $this->provider->alias('Danack\\Console\\Output\\Output', get_class($output));
     $this->provider->share($output);
     $callable = $this->parsedCommand->getCallable();
     $this->provider->execute($callable, []);
     $this->assertEquals('foo' . PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
 }
Exemplo n.º 2
0
 public function testRun()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $application->add($command = new \Foo1Command());
     $_SERVER['argv'] = array('cli.php', 'foo:bar1');
     ob_start();
     $application->parseCommandLine();
     ob_end_clean();
     $this->assertInstanceOf('Danack\\Console\\Input\\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given');
     $this->assertInstanceOf('Danack\\Console\\Output\\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given');
     $application = new Application();
     $application->setAutoExit(false);
     $this->ensureStaticCommandHelp($application);
     $tester = new ApplicationTester($application);
     $provider = new Provider();
     //TODO - this should be in a loop with data defined in an array
     $parsedCommand = $tester->run(array(), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run1.txt', $tester->getDisplay(true), '->run() runs the list command if no argument is passed');
     $parsedCommand = $tester->run(array('--help' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if --help is passed');
     $parsedCommand = $tester->run(array('-h' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if -h is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if --help is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if -h is passed');
     $parsedCommand = $tester->run(array('--ansi' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
     $parsedCommand = $tester->run(array('--no-ansi' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
     $parsedCommand = $tester->run(array('--version' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if --version is passed');
     $parsedCommand = $tester->run(array('-V' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertStringEqualsFile(self::$fixturesPath . '/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if -v is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--quiet' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '-q' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--verbose' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--verbose' => 1));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--verbose' => 2));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--verbose' => 3));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '--verbose' => 4));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '-v' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '-vv' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
     $parsedCommand = $tester->run(array('command' => 'list', '-vvv' => true));
     $provider->execute($parsedCommand->getCallable(), []);
     $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->add(new \FooCommand());
     $tester = new ApplicationTester($application);
     $parsedCommand = $tester->run(array('command' => 'foo:bar', '--no-interaction' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame('called' . PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');
     $parsedCommand = $tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertSame('called' . PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
 }