[Console] Test SymfonyStyle::ask() output
This commit is contained in:
parent
afed2f888d
commit
e870758dae
|
@ -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?');
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
What's your name?:
|
||||||
|
>
|
||||||
|
How are you?:
|
||||||
|
>
|
||||||
|
Where do you come from?:
|
||||||
|
>
|
|
@ -48,6 +48,24 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
|
$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()
|
public function inputCommandToOutputFilesProvider()
|
||||||
{
|
{
|
||||||
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
|
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
|
||||||
|
|
Reference in New Issue