Make ProgressBar::setMaxSteps public
This is useful in cases when target of tracking changes its size during progress advancement.
This commit is contained in:
parent
0cfc00e717
commit
2b3c37a2d8
@ -295,6 +295,13 @@ final class ProgressBar
|
||||
}
|
||||
}
|
||||
|
||||
public function setMaxSteps(int $max)
|
||||
{
|
||||
$this->format = null;
|
||||
$this->max = max(0, $max);
|
||||
$this->stepWidth = $this->max ? Helper::strlen((string) $this->max) : 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the progress output.
|
||||
*/
|
||||
@ -362,12 +369,6 @@ final class ProgressBar
|
||||
$this->formatLineCount = substr_count($this->format, "\n");
|
||||
}
|
||||
|
||||
private function setMaxSteps(int $max)
|
||||
{
|
||||
$this->max = max(0, $max);
|
||||
$this->stepWidth = $this->max ? Helper::strlen((string) $this->max) : 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites a previous message to the output.
|
||||
*/
|
||||
|
@ -592,6 +592,29 @@ class ProgressBarTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testSettingMaxStepsDuringProgressing()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
$bar = new ProgressBar($output);
|
||||
$bar->start();
|
||||
$bar->setProgress(2);
|
||||
$bar->setMaxSteps(10);
|
||||
$bar->setProgress(5);
|
||||
$bar->setMaxSteps(100);
|
||||
$bar->setProgress(10);
|
||||
$bar->finish();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
rtrim(' 0 [>---------------------------]').
|
||||
rtrim($this->generateOutput(' 2 [-->-------------------------]')).
|
||||
rtrim($this->generateOutput(' 5/10 [==============>-------------] 50%')).
|
||||
rtrim($this->generateOutput(' 10/100 [==>-------------------------] 10%')).
|
||||
rtrim($this->generateOutput(' 100/100 [============================] 100%')),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithSmallScreen()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
|
Reference in New Issue
Block a user