[Console] Test SymfonyStyle::ask() output

This commit is contained in:
Robin Chalas 2016-06-18 11:29:22 +02:00
parent afed2f888d
commit e870758dae
No known key found for this signature in database
GPG Key ID: 4F0208BDE2AA841F
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';