Skip to content

Commit

Permalink
Set the redraw frequency at least to 1. Setting it to 0 would otherwi…
Browse files Browse the repository at this point in the history
…se produce an error.
  • Loading branch information
dritter authored and stof committed Dec 5, 2015
1 parent 42a9da9 commit a1c207c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/Symfony/Component/Console/Helper/ProgressBar.php
Expand Up @@ -67,10 +67,8 @@ public function __construct(OutputInterface $output, $max = 0)
// disable overwrite when output does not support ANSI codes.
$this->overwrite = false;

if ($this->max > 10) {
// set a reasonable redraw frequency so output isn't flooded
$this->setRedrawFrequency($max / 10);
}
// set a reasonable redraw frequency so output isn't flooded
$this->setRedrawFrequency($max / 10);
}

$this->startTime = time();
Expand Down Expand Up @@ -316,11 +314,11 @@ public function setFormat($format)
/**
* Sets the redraw frequency.
*
* @param int $freq The frequency in steps
* @param int|float $freq The frequency in steps
*/
public function setRedrawFrequency($freq)
{
$this->redrawFreq = (int) $freq;
$this->redrawFreq = max((int) $freq, 1);
}

/**
Expand Down
22 changes: 21 additions & 1 deletion src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
Expand Up @@ -296,7 +296,7 @@ public function testRegressProgress()

public function testRedrawFrequency()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($output = $this->getOutputStream(), 6));
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream(), 6));
$bar->expects($this->exactly(4))->method('display');

$bar->setRedrawFrequency(2);
Expand All @@ -307,6 +307,26 @@ public function testRedrawFrequency()
$bar->advance(1);
}

public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));

$bar->expects($this->exactly(2))->method('display');
$bar->setRedrawFrequency(0);
$bar->start();
$bar->advance();
}

public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));

$bar->expects($this->exactly(2))->method('display');
$bar->setRedrawFrequency(0.9);
$bar->start();
$bar->advance();
}

/**
* @requires extension mbstring
*/
Expand Down

0 comments on commit a1c207c

Please sign in to comment.