Skip to content

Commit 368423b

Browse files
committed
Set the redraw frequency at least to 1. Setting it to 0 would otherwise produce an error.
1 parent fad3d38 commit 368423b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ public function __construct(OutputInterface $output, $max = 0)
6868
// disable overwrite when output does not support ANSI codes.
6969
$this->overwrite = false;
7070

71-
if ($this->max > 10) {
72-
// set a reasonable redraw frequency so output isn't flooded
73-
$this->setRedrawFrequency($max / 10);
74-
}
71+
// set a reasonable redraw frequency so output isn't flooded
72+
$this->setRedrawFrequency($max / 10);
7573
}
7674

7775
$this->startTime = time();
@@ -317,11 +315,11 @@ public function setFormat($format)
317315
/**
318316
* Sets the redraw frequency.
319317
*
320-
* @param int $freq The frequency in steps
318+
* @param int|float $freq The frequency in steps
321319
*/
322320
public function setRedrawFrequency($freq)
323321
{
324-
$this->redrawFreq = (int) $freq;
322+
$this->redrawFreq = max((int) $freq, 1);
325323
}
326324

327325
/**

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,30 @@ public function testRedrawFrequency()
307307
$bar->advance(1);
308308
}
309309

310+
public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
311+
{
312+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'),
313+
array($output = $this->getOutputStream(), 6));
314+
315+
$bar->expects($this->exactly(2))->method('display');
316+
$bar->setRedrawFrequency(0);
317+
$bar->start();
318+
$bar->advance();
319+
}
320+
321+
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
322+
{
323+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($output = $this->getOutputStream(), 6));
324+
325+
$bar->expects($this->exactly(2))->method('display');
326+
$bar->setRedrawFrequency(0.9);
327+
$bar->start();
328+
$bar->advance();
329+
}
330+
331+
/**
332+
* @requires extension mbstring
333+
*/
310334
public function testMultiByteSupport()
311335
{
312336
$bar = new ProgressBar($output = $this->getOutputStream());

0 commit comments

Comments
 (0)