Navigation Menu

Skip to content

Commit

Permalink
minor #19097 [Console] Test SymfonyStyle::ask() output (chalasr)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Jun 20, 2016
2 parents 414a4b4 + e870758 commit 88cf87e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
@@ -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?:
>
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php
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 comments on commit 88cf87e

Please sign in to comment.