minor #19097 [Console] Test SymfonyStyle::ask() output (chalasr)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Console] Test SymfonyStyle::ask() output

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Now that we can test an interactive command that uses SymfonyStyle (after #18999), we should test their output.

Commits
-------

e870758 [Console] Test SymfonyStyle::ask() output
This commit is contained in:
Fabien Potencier 2016-06-20 06:58:14 +02:00
commit 88cf87ea64
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure that questions have the expected outputs
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$stream = fopen('php://memory', 'r+', false);
fputs($stream, "Foo\nBar\nBaz");
rewind($stream);
$input->setStream($stream);
$output->ask('What\'s your name?');
$output->ask('How are you?');
$output->ask('Where do you come from?');
};

View File

@ -0,0 +1,7 @@
What's your name?:
>
How are you?:
>
Where do you come from?:
>

View File

@ -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';