From 447d46814c72c20d071a53dbdeb46c9f01262c67 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 21 Mar 2012 05:15:35 +0100 Subject: [PATCH] restore previous testing style with static fixtures for console --- .../Component/Console/ApplicationTest.php | 19 +++++++------ .../Console/Fixtures/application_run1.txt | 17 ++++++++++++ .../Console/Fixtures/application_run2.txt | 26 ++++++++++++++++++ .../Console/Fixtures/application_run3.txt | 27 +++++++++++++++++++ .../Console/Fixtures/application_run4.txt | 1 + 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt create mode 100644 tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt diff --git a/tests/Symfony/Tests/Component/Console/ApplicationTest.php b/tests/Symfony/Tests/Component/Console/ApplicationTest.php index f3e5a51e63..99784754d6 100644 --- a/tests/Symfony/Tests/Component/Console/ApplicationTest.php +++ b/tests/Symfony/Tests/Component/Console/ApplicationTest.php @@ -12,7 +12,6 @@ namespace Symfony\Tests\Component\Console; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -359,27 +358,27 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given'); $this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given'); - $formatter = new OutputFormatter(false); - $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); + + $this->ensureStaticCommandHelp($application); $tester = new ApplicationTester($application); $tester->run(array(), array('decorated' => false)); - $this->assertSame($formatter->format($application->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the list command if no argument is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the list command if no argument is passed'); $tester->run(array('--help' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if --help is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if --help is passed'); $tester->run(array('-h' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('help')->asText()).PHP_EOL, $tester->getDisplay(), '->run() runs the help command if -h is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if -h is passed'); $tester->run(array('command' => 'list', '--help' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->run() displays the help if --help is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if --help is passed'); $tester->run(array('command' => 'list', '-h' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->get('list')->asText()).PHP_EOL, $tester->getDisplay(), '->run() displays the help if -h is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->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'); @@ -388,10 +387,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if --version is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if --version is passed'); $tester->run(array('-V' => true), array('decorated' => false)); - $this->assertSame($formatter->format($application->getLongVersion()).PHP_EOL, $tester->getDisplay(), '->run() displays the program version if -V is passed'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->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'); diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt new file mode 100644 index 0000000000..176dc88101 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run1.txt @@ -0,0 +1,17 @@ +Console Tool + +Usage: + [options] command [arguments] + +Options: + --help -h Display this help message. + --quiet -q Do not output any message. + --verbose -v Increase verbosity of messages. + --version -V Display this application version. + --ansi Force ANSI output. + --no-ansi Disable ANSI output. + --no-interaction -n Do not ask any interactive question. + +Available commands: + help Displays help for a command + list Lists commands diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt new file mode 100644 index 0000000000..f717033ad3 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt @@ -0,0 +1,26 @@ +Usage: + help [--xml] [command_name] + +Arguments: + command The command to execute + command_name The command name (default: 'help') + +Options: + --xml To output help as XML + --help (-h) Display this help message. + --quiet (-q) Do not output any message. + --verbose (-v) Increase verbosity of messages. + --version (-V) Display this application version. + --ansi Force ANSI output. + --no-ansi Disable ANSI output. + --no-interaction (-n) Do not ask any interactive question. + +Help: + The help command displays help for a given command: + + php app/console help list + + You can also output the help as XML by using the --xml option: + + php app/console help --xml list + diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt new file mode 100644 index 0000000000..441db54857 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run3.txt @@ -0,0 +1,27 @@ +Usage: + list [--xml] [--raw] [namespace] + +Arguments: + namespace The namespace name + +Options: + --xml To output help as XML + --raw To output raw command list + +Help: + The list command lists all commands: + + php app/console list + + You can also display the commands for a specific namespace: + + php app/console list test + + You can also output the information as XML by using the --xml option: + + php app/console list --xml + + It's also possible to get raw list of commands (useful for embedding command runner): + + php app/console list --raw + diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt b/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt new file mode 100644 index 0000000000..47187fc267 --- /dev/null +++ b/tests/Symfony/Tests/Component/Console/Fixtures/application_run4.txt @@ -0,0 +1 @@ +Console Tool