Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,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 @@ -317,11 +315,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
Original file line number Diff line number Diff line change
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();
}

public function testMultiByteSupport()
{
$bar = new ProgressBar($output = $this->getOutputStream());
Expand Down