From e870758dae63bdd0d3ec2ffde205b1568b6cfdd9 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 18 Jun 2016 11:29:22 +0200 Subject: [PATCH] [Console] Test SymfonyStyle::ask() output --- .../command/interactive_command_1.php | 19 +++++++++++++++++++ .../output/interactive_output_1.txt | 7 +++++++ .../Console/Tests/Style/SymfonyStyleTest.php | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/interactive_output_1.txt diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php new file mode 100644 index 0000000000..e246b43170 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php @@ -0,0 +1,19 @@ +setStream($stream); + + $output->ask('What\'s your name?'); + $output->ask('How are you?'); + $output->ask('Where do you come from?'); +}; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/interactive_output_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/interactive_output_1.txt new file mode 100644 index 0000000000..6fc7d7eb4d --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/interactive_output_1.txt @@ -0,0 +1,7 @@ + + What's your name?: + > + How are you?: + > + Where do you come from?: + > diff --git a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php index e4ce037bb8..00b307067d 100644 --- a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php @@ -48,6 +48,24 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true)); } + /** + * @dataProvider inputInteractiveCommandToOutputFilesProvider + */ + public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath) + { + $code = require $inputCommandFilepath; + $this->command->setCode($code); + $this->tester->execute(array(), array('interactive' => true, 'decorated' => false)); + $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true)); + } + + public function inputInteractiveCommandToOutputFilesProvider() + { + $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle'; + + return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt')); + } + public function inputCommandToOutputFilesProvider() { $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';