@@ -943,23 +943,47 @@ public function testBarWidthWithMultilineFormat()
943
943
putenv ('COLUMNS=120 ' );
944
944
}
945
945
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
947
970
{
948
971
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 0 , 0 );
949
972
$ bar ->setRedrawFrequency (4 ); // disable step based redraws
950
973
$ bar ->start ();
974
+
951
975
$ bar ->setProgress (1 ); // No treshold hit, no redraw
952
- $ bar ->forceRedrawSlowerThan (2 );
976
+ $ bar ->maxSecondsBetweenRedraws (2 );
953
977
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
955
979
sleep (1 );
956
980
$ bar ->setProgress (3 ); // 1+1 = 2 -> redraw finally
957
981
$ bar ->setProgress (4 ); // step based redraw freq hit, redraw even without sleep
958
982
$ bar ->setProgress (5 ); // No treshold hit, no redraw
959
- $ bar ->preventRedrawFasterThan (3 );
983
+ $ bar ->maxSecondsBetweenRedraws (3 );
960
984
sleep (2 );
961
985
$ bar ->setProgress (6 ); // No redraw even though 2 seconds passed. Throttling has priority
962
- $ bar ->preventRedrawFasterThan (2 );
986
+ $ bar ->maxSecondsBetweenRedraws (2 );
963
987
$ bar ->setProgress (7 ); // Throttling relaxed, draw
964
988
965
989
rewind ($ output ->getStream ());
@@ -972,16 +996,16 @@ public function testForceRedrawSlowerThan(): void
972
996
);
973
997
}
974
998
975
- public function testPreventRedrawFasterThan ()
999
+ public function testMinSecondsBetweenRedraws ()
976
1000
{
977
1001
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 0 , 0 );
978
1002
$ bar ->setRedrawFrequency (1 );
979
- $ bar ->preventRedrawFasterThan (1 );
1003
+ $ bar ->minSecondsBetweenRedraws (1 );
980
1004
$ bar ->start ();
981
1005
$ bar ->setProgress (1 ); // Too fast, should not draw
982
1006
sleep (1 );
983
1007
$ bar ->setProgress (2 ); // 1 second passed, draw
984
- $ bar ->preventRedrawFasterThan (2 );
1008
+ $ bar ->minSecondsBetweenRedraws (2 );
985
1009
sleep (1 );
986
1010
$ bar ->setProgress (3 ); // 1 second passed but we changed threshold, should not draw
987
1011
sleep (1 );
0 commit comments