8000 [Console] Fix: Allow to inject QuestionHelper into SymfonyStyle by localheinz · Pull Request #17468 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix: Allow to inject QuestionHelper into SymfonyStyle #17468

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

Closed
Closed
Changes from 1 commit
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
Next Next commit
Enhancement: Assert that QuestionHelper can be injected into SymfonyS…
…tyle
  • Loading branch information
localheinz committed Jan 21, 2016
commit f785039ad1c325f16d0ca2143d2c63b7cba6da13
38 changes: 38 additions & 0 deletions src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit_Framework_TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -70,6 +72,42 @@ public function testLongWordsBlockWrapping()
$expectedCount = (int) ceil($wordLength / ($maxLineLength)) + (int) ($wordLength > $maxLineLength - 5);
$this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
}

public function testCanSetQuestionHelper()
{
$questionHelper = new QuestionHelper();

$this->command->setHelperSet(new HelperSet([
'question' => $questionHelper,
]));

$this->command->setCode(function (InputInterface $input, OutputInterface $output) {
$io = new SymfonyStyle($input, $output);

$questionHelper = $this->command->getHelper('question');

$io->setQuestionHelper($questionHelper);

if ($io->ask('Are you really sure?') !== 'yes') {
return 1;
}

return 0;
});

$questionHelper->setInputStream($this->getInputStream("yes\n"));

$this->assertSame(0, $this->tester->execute([]));
}

private function getInputStream($input)
{
$stream = fopen('php://memory', 'r+', false);
fputs($stream, $input);
rewind($stream);

return $stream;
}
}

/**
Expand Down
0