diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 0b64b18a1db0..016e885f4b28 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -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(); @@ -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); } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index e22734a29e8e..ffe5bed08634 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -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); @@ -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 */