Set the redraw frequency at least to 1. Setting it to 0 would otherwise produce an error.
This commit is contained in:
parent
42a9da9588
commit
a1c207c7d1
@ -67,10 +67,8 @@ class ProgressBar
|
||||
// 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 @@ class ProgressBar
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,7 +296,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase
|
||||
$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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user