diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index b9e837a8d10c..d61ba5115559 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -5,7 +5,7 @@ CHANGELOG ----- * added `Question::setTrimmable` default to true to allow the answer to be trimmed - * added method `preventRedrawFasterThan()` and `forceRedrawSlowerThan()` on `ProgressBar` + * added method `minSecondsBetweenRedraws()` and `maxSecondsBetweenRedraws()` on `ProgressBar` * `Application` implements `ResetInterface` * marked all dispatched event classes as `@final` * added support for displaying table horizontally diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 3751439fa307..0bb7dfc776d7 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -256,14 +256,14 @@ public function setRedrawFrequency(?int $freq) $this->redrawFreq = null !== $freq ? max(1, $freq) : null; } - public function preventRedrawFasterThan(float $intervalInSeconds): void + public function minSecondsBetweenRedraws(float $seconds): void { - $this->minSecondsBetweenRedraws = $intervalInSeconds; + $this->minSecondsBetweenRedraws = $seconds; } - public function forceRedrawSlowerThan(float $intervalInSeconds): void + public function maxSecondsBetweenRedraws(float $seconds): void { - $this->maxSecondsBetweenRedraws = $intervalInSeconds; + $this->maxSecondsBetweenRedraws = $seconds; } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index 877b1dfd197b..6da0af20b40f 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -943,23 +943,47 @@ public function testBarWidthWithMultilineFormat() putenv('COLUMNS=120'); } - public function testForceRedrawSlowerThan(): void + public function testMinAndMaxSecondsBetweenRedraws(): void + { + $bar = new ProgressBar($output = $this->getOutputStream()); + $bar->setRedrawFrequency(1); + $bar->minSecondsBetweenRedraws(5); + $bar->maxSecondsBetweenRedraws(10); + + $bar->start(); + $bar->setProgress(1); + sleep(10); + $bar->setProgress(2); + sleep(20); + $bar->setProgress(3); + + rewind($output->getStream()); + $this->assertEquals( + ' 0 [>---------------------------]'. + $this->generateOutput(' 2 [-->-------------------------]'). + $this->generateOutput(' 3 [--->------------------------]'), + stream_get_contents($output->getStream()) + ); + } + + public function testMaxSecondsBetweenRedraws(): void { $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); $bar->setRedrawFrequency(4); // disable step based redraws $bar->start(); + $bar->setProgress(1); // No treshold hit, no redraw - $bar->forceRedrawSlowerThan(2); + $bar->maxSecondsBetweenRedraws(2); sleep(1); - $bar->setProgress(2); // Still no redraw because redraw is forced after 2 seconds only + $bar->setProgress(2); // Still no redraw because it takes 2 seconds for a redraw sleep(1); $bar->setProgress(3); // 1+1 = 2 -> redraw finally $bar->setProgress(4); // step based redraw freq hit, redraw even without sleep $bar->setProgress(5); // No treshold hit, no redraw - $bar->preventRedrawFasterThan(3); + $bar->maxSecondsBetweenRedraws(3); sleep(2); $bar->setProgress(6); // No redraw even though 2 seconds passed. Throttling has priority - $bar->preventRedrawFasterThan(2); + $bar->maxSecondsBetweenRedraws(2); $bar->setProgress(7); // Throttling relaxed, draw rewind($output->getStream()); @@ -972,16 +996,16 @@ public function testForceRedrawSlowerThan(): void ); } - public function testPreventRedrawFasterThan() + public function testMinSecondsBetweenRedraws() { $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); $bar->setRedrawFrequency(1); - $bar->preventRedrawFasterThan(1); + $bar->minSecondsBetweenRedraws(1); $bar->start(); $bar->setProgress(1); // Too fast, should not draw sleep(1); $bar->setProgress(2); // 1 second passed, draw - $bar->preventRedrawFasterThan(2); + $bar->minSecondsBetweenRedraws(2); sleep(1); $bar->setProgress(3); // 1 second passed but we changed threshold, should not draw sleep(1); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy