Skip to content

Commit

Permalink
feature #9846 [Console] hide output of ProgressHelper when isDecorate…
Browse files Browse the repository at this point in the history
…d 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)
  • Loading branch information
fabpot committed Dec 23, 2013
2 parents 8d39213 + 006cb81 commit 6a51831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Symfony/Component/Console/Helper/ProgressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -185,7 +186,9 @@ public function start(OutputInterface $output, $max = null)
$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 = '';

Expand Down
14 changes: 12 additions & 2 deletions src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,19 @@ public function testPercentNotHundredBeforeComplete()
$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;
Expand Down

0 comments on commit 6a51831

Please sign in to comment.