8000 [Console] Rename some methods related to redraw frequency · symfony/symfony@e6ee7b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6ee7b0

Browse files
javiereguiluzfabpot
authored andcommitted
[Console] Rename some methods related to redraw frequency
1 parent b829439 commit e6ee7b0

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
-----
66

77
* added `Question::setTrimmable` default to true to allow the answer to be trimmed
8-
* added method `preventRedrawFasterThan()` and `forceRedrawSlowerThan()` on `ProgressBar`
8+
* added method `minSecondsBetweenRedraws()` and `maxSecondsBetweenRedraws()` on `ProgressBar`
99
* `Application` implements `ResetInterface`
1010
* marked all dispatched event classes as `@final`
1111
* added support for displaying table horizontally

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ public function setRedrawFrequency(?int $freq)
256256
$this->redrawFreq = null !== $freq ? max(1, $freq) : null;
257257
}
258258

259-
public function preventRedrawFasterThan(float $intervalInSeconds): void
259+
public function minSecondsBetweenRedraws(float $seconds): void
260260
{
261-
$this->minSecondsBetweenRedraws = $intervalInSeconds;
261+
$this->minSecondsBetweenRedraws = $seconds;
262262
}
263263

264-
public function forceRedrawSlowerThan(float $intervalInSeconds): void
264+
public function maxSecondsBetweenRedraws(float $seconds): void
265265
{
266-
$this->maxSecondsBetweenRedraws = $intervalInSeconds;
266+
$this->maxSecondsBetweenRedraws = $seconds;
267267
}
268268

269269
/**

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -943,23 +943,47 @@ public function testBarWidthWithMultilineFormat()
943943
putenv('COLUMNS=120');
944944
}
945945

946-
public function testForceRedrawSlowerThan(): void
946+
public function testMinAndMaxSecondsBetweenRedraws(): void
947+
{
948+
$bar = new ProgressBar($output = $this->getOutputStream());
949+
$bar->setRedrawFrequency(1);
950+
$bar->minSecondsBetweenRedraws(5);
951+
$bar->maxSecondsBetweenRedraws(10);
952+
953+
$bar->start();
954+
$bar->setProgress(1);
955+
sleep(10);
956+
$bar->setProgress(2);
957+
sleep(20);
958+
$bar->setProgress(3);
959+
960+
rewind($output->getStream());
961+
$this->assertEquals(
962+
' 0 [>---------------------------]'.
963+
$this->generateOutput(' 2 [-->-------------------------]').
964+
$this->generateOutput(' 3 [--->------------------------]'),
965+
stream_get_contents($output->getStream())
966+
);
967+
}
968+
969+
public function testMaxSecondsBetweenRedraws(): void
947970
{
948971
$bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
949972
$bar->setRedrawFrequency(4); // disable step based redraws
950973
$bar->start();
974+
951975
$bar->setProgress(1); // No treshold hit, no redraw
952-
$bar->forceRedrawSlowerThan(2);
976+
$bar->maxSecondsBetweenRedraws(2);
953977
sleep(1);
954-
$bar->setProgress(2); // Still no redraw because redraw is forced after 2 seconds only
978+
$bar->setProgress(2); // Still no redraw because it takes 2 seconds for a redraw
955979
sleep(1);
956980
$bar->setProgress(3); // 1+1 = 2 -> redraw finally
957981
$bar->setProgress(4); // step based redraw freq hit, redraw even without sleep
958982
$bar->setProgress(5); // No treshold hit, no redraw
959-
$bar->preventRedrawFasterThan(3);
983+
$bar->maxSecondsBetweenRedraws(3);
960984
sleep(2);
961985
$bar->setProgress(6); // No redraw even though 2 seconds passed. Throttling has priority
962-
$bar->preventRedrawFasterThan(2);
986+
$bar->maxSecondsBetweenRedraws(2);
963987
$bar->setProgress(7); // Throttling relaxed, draw
964988

965989
rewind($output->getStream());
@@ -972,16 +996,16 @@ public function testForceRedrawSlowerThan(): void
972996
);
973997
}
974998

975-
public function testPreventRedrawFasterThan()
999+
public function testMinSecondsBetweenRedraws()
9761000
{
9771001
$bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
9781002
$bar->setRedrawFrequency(1);
979-
$bar->preventRedrawFasterThan(1);
1003+
$bar->minSecondsBetweenRedraws(1);
9801004
$bar->start();
9811005
$bar->setProgress(1); // Too fast, should not draw
9821006
sleep(1);
9831007
$bar->setProgress(2); // 1 second passed, draw
984-
$bar->preventRedrawFasterThan(2);
1008+
$bar->minSecondsBetweenRedraws(2);
9851009
sleep(1);
9861010
$bar->setProgress(3); // 1 second passed but we changed threshold, should not draw
9871011
sleep(1);

0 commit comments

Comments
 (0)
0