8000 [Console] Test SymfonyStyle::ask() output by chalasr · Pull Request #19097 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] Test SymfonyStyle::ask() output
  • Loading branch information
chalasr committed Jun 18, 2016
commit e870758dae63bdd0d3ec2ffde205b1568b6cfdd9
Original file line number Diff line number Diff line change
@@ -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?');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

What's your name?:
>
How are you?:
>
Where do you come from?:
>
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ public function testOutputs($inputCommandFilepath, $outputFilepath)
$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';
Expand Down
0