feature #9846 [Console] hide output of ProgressHelper when isDecorated is false (kbond)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[Console] hide output of ProgressHelper when isDecorated is false

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9511
| License       | MIT
| Doc PR        | n/a

Commits
-------

006cb81 [Console] show no output in ProgressHelper when isDecorated is false (fixes #9511)
This commit is contained in:
Fabien Potencier 2013-12-23 17:13:46 +01:00
commit 6a51831678
2 changed files with 16 additions and 3 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
/**
@ -185,7 +186,9 @@ class ProgressHelper extends Helper
$this->startTime = time();
$this->current = 0;
$this->max = (int) $max;
$this->output = $output;
// Disabling output when it does not support ANSI codes as it would result in a broken display anyway.
$this->output = $output->isDecorated() ? $output : new NullOutput();
$this->lastMessagesLength = 0;
$this->barCharOriginal = '';

View File

@ -192,9 +192,19 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%').$this->generateOutput(' 199/200 [===========================>] 99%').$this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream()));
}
protected function getOutputStream()
public function testNonDecoratedOutput()
{
return new StreamOutput(fopen('php://memory', 'r+', false));
$progress = new ProgressHelper();
$progress->start($output = $this->getOutputStream(false));
$progress->advance();
rewind($output->getStream());
$this->assertEquals('', stream_get_contents($output->getStream()));
}
protected function getOutputStream($decorated = true)
{
return new StreamOutput(fopen('php://memory', 'r+', false), StreamOutput::VERBOSITY_NORMAL, $decorated);
}
protected $lastMessagesLength;