Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a0a811

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

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function testRegressProgress()
296296

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

302302
$bar->setRedrawFrequency(2);
@@ -307,6 +307,26 @@ 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'), array($this->getOutputStream()));
313+
314+
$bar->expects($this->exactly(2))->method('display');
315+
$bar->setRedrawFrequency(0);
316+
$bar->start();
317+
$bar->advance();
318+
}
319+
320+
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
321+
{
322+
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));
323+
324+
$bar->expects($this->exactly(2))->method('display');
325+
$bar->setRedrawFrequency(0.9);
326+
$bar->start();
327+
$bar->advance();
328+
}
329+
310330
public function testMultiByteSupport()
311331
{
312332
$bar = new ProgressBar($output = $this->getOutputStream());

0 commit comments

Comments
 (0)