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

Skip to content

Commit 206f3c9

Browse files
committed
add a test to verify setMaxSteps, fix format not recalculated
1 parent 58b8aa0 commit 206f3c9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ private function setRealFormat(string $format)
364364

365365
public function setMaxSteps(int $max)
366366
{
367+
$this->format = null;
367368
$this->max = max(0, $max);
368369
$this->stepWidth = $this->max ? Helper::strlen((string) $this->max) : 4;
369370
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ public function testWithoutMax()
592592
);
593593
}
594594

595+
public function testSettingMaxStepsDuringProgressing()
596+
{
597+
$output = $this->getOutputStream();
598+
$bar = new ProgressBar($output);
599+
$bar->start();
600+
$bar->setProgress(2);
601+
$bar->setMaxSteps(10);
602+
$bar->setProgress(5);
603+
$bar->setMaxSteps(100);
604+
$bar->setProgress(10);
605+
$bar->finish();
606+
607+
rewind($output->getStream());
608+
$this->assertEquals(
609+
rtrim(' 0 [>---------------------------]').
610+
rtrim($this->generateOutput(' 2 [-->-------------------------]')).
611+
rtrim($this->generateOutput(' 5/10 [==============>-------------] 50%')).
612+
rtrim($this->generateOutput(' 10/100 [==>-------------------------] 10%')).
613+
rtrim($this->generateOutput(' 100/100 [============================] 100%')),
614+
stream_get_contents($output->getStream())
615+
);
616+
}
617+
595618
public function testWithSmallScreen()
596619
{
597620
$output = $this->getOutputStream();

0 commit comments

Comments
 (0)