23
23
*/
24
24
class ProgressBarTest extends TestCase
25
25
{
26
+ const TEN_MS = 100001 ;
27
+
26
28
public function testMultipleStart ()
27
29
{
28
30
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
29
31
$ bar ->start ();
32
+ usleep (self ::TEN_MS );
30
33
$ bar ->advance ();
31
34
$ bar ->start ();
32
35
@@ -43,6 +46,7 @@ public function testAdvance()
43
46
{
44
47
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
45
48
$ bar ->start ();
49
+ usleep (self ::TEN_MS );
46
50
$ bar ->advance ();
47
51
48
52
rewind ($ output ->getStream ());
@@ -57,6 +61,7 @@ public function testAdvanceWithStep()
57
61
{
58
62
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
59
63
$ bar ->start ();
64
+ usleep (self ::TEN_MS );
60
65
$ bar ->advance (5 );
61
66
62
67
rewind ($ output ->getStream ());
@@ -71,7 +76,9 @@ public function testAdvanceMultipleTimes()
71
76
{
72
77
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
73
78
$ bar ->start ();
79
+ usleep (self ::TEN_MS );
74
80
$ bar ->advance (3 );
81
+ usleep (self ::TEN_MS );
75
82
$ bar ->advance (2 );
76
83
77
84
rewind ($ output ->getStream ());
@@ -103,8 +110,11 @@ public function testRegress()
103
110
{
104
111
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
105
112
$ bar ->start ();
113
+ usleep (self ::TEN_MS );
106
114
$ bar ->advance ();
115
+ usleep (self ::TEN_MS );
107
116
$ bar ->advance ();
117
+ usleep (self ::TEN_MS );
108
118
$ bar ->advance (-1 );
109
119
110
120
rewind ($ output ->getStream ());
@@ -121,8 +131,11 @@ public function testRegressWithStep()
121
131
{
122
132
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
123
133
$ bar ->start ();
134
+ usleep (self ::TEN_MS );
124
135
$ bar ->advance (4 );
136
+ usleep (self ::TEN_MS );
125
137
$ bar ->advance (4 );
138
+ usleep (self ::TEN_MS );
126
139
$ bar ->advance (-2 );
127
140
128
141
rewind ($ output ->getStream ());
@@ -139,9 +152,13 @@ public function testRegressMultipleTimes()
139
152
{
140
153
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
141
154
$ bar ->start ();
155
+ usleep (self ::TEN_MS );
142
156
$ bar ->advance (3 );
157
+ usleep (self ::TEN_MS );
143
158
$ bar ->advance (3 );
159
+ usleep (self ::TEN_MS );
144
160
$ bar ->advance (-1 );
161
+ usleep (self ::TEN_MS );
145
162
$ bar ->advance (-2 );
146
163
147
164
rewind ($ output ->getStream ());
@@ -160,6 +177,7 @@ public function testRegressBelowMin()
160
177
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 10 );
161
178
$ bar ->setProgress (1 );
162
179
$ bar ->advance (-1 );
180
+ usleep (self ::TEN_MS );
163
181
$ bar ->advance (-1 );
164
182
165
183
rewind ($ output ->getStream ());
@@ -200,6 +218,7 @@ public function testFormat()
200
218
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 10 );
201
219
$ bar ->setFormat ('normal ' );
202
220
$ bar ->start ();
221
+ usleep (self ::TEN_MS );
203
222
$ bar ->advance (10 );
204
223
$ bar ->finish ();
205
224
@@ -210,6 +229,7 @@ public function testFormat()
210
229
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
211
230
$ bar ->setFormat ('normal ' );
212
231
$ bar ->start (10 );
232
+ usleep (self ::TEN_MS );
213
233
$ bar ->advance (10 );
214
234
$ bar ->finish ();
215
235
@@ -226,6 +246,7 @@ public function testCustomizations()
226
246
$ bar ->setProgressCharacter ('/ ' );
227
247
$ bar ->setFormat (' %current%/%max% [%bar%] %percent:3s%% ' );
228
248
$ bar ->start ();
249
+ usleep (self ::TEN_MS );
229
250
$ bar ->advance ();
230
251
231
252
rewind ($ output ->getStream ());
@@ -277,7 +298,9 @@ public function testPercent()
277
298
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
278
299
$ bar ->start ();
279
300
$ bar ->display ();
301
+ usleep (self ::TEN_MS );
280
302
$ bar ->advance ();
303
+ usleep (self ::TEN_MS );
281
304
$ bar ->advance ();
282
305
283
306
rewind ($ output ->getStream ());
@@ -296,7 +319,9 @@ public function testOverwriteWithShorterLine()
296
319
$ bar ->setFormat (' %current%/%max% [%bar%] %percent:3s%% ' );
297
320
$ bar ->start ();
298
321
$ bar ->display ();
322
+ usleep (self ::TEN_MS );
299
323
$ bar ->advance ();
324
+ usleep (self ::TEN_MS );
300
325
301
326
// set shorter format
302
327
$ bar ->setFormat (' %current%/%max% [%bar%] ' );
@@ -321,7 +346,9 @@ public function testOverwriteWithSectionOutput()
321
346
$ bar = new ProgressBar ($ output , 50 );
322
347
$ bar ->start ();
323
348
$ bar ->display ();
349
+ usleep (self ::TEN_MS );
324
350
$ bar ->advance ();
351
+ usleep (self ::TEN_MS );
325
352
$ bar ->advance ();
326
353
327
354
rewind ($ output ->getStream ());
@@ -346,8 +373,10 @@ public function testOverwriteMultipleProgressBarsWithSectionOutputs()
346
373
347
374
$ progress ->start ();
348
375
$ progress2 ->start ();
376
+ usleep (self ::TEN_MS );
349
377
350
378
$ progress2 ->advance ();
379
+ usleep (self ::TEN_MS );
351
380
$ progress ->advance ();
352
381
353
382
rewind ($ stream ->getStream ());
@@ -378,8 +407,10 @@ public function testMultipleSectionsWithCustomFormat()
378
407
379
408
$ progress ->start ();
380
409
$ progress2 ->start ();
410
+ usleep (self ::TEN_MS );
381
411
382
412
$ progress ->advance ();
413
+ usleep (self ::TEN_MS );
383
414
$ progress2 ->advance ();
384
415
385
416
rewind ($ stream ->getStream ());
@@ -399,6 +430,7 @@ public function testStartWithMax()
399
430
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
400
431
$ bar ->setFormat ('%current%/%max% [%bar%] ' );
401
432
$ bar ->start (50 );
433
+ usleep (self ::TEN_MS );
402
434
$ bar ->advance ();
403
435
404
436
rewind ($ output ->getStream ());
@@ -414,8 +446,11 @@ public function testSetCurrentProgress()
414
446
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
415
447
$ bar ->start ();
416
448
$ bar ->display ();
449
+ usleep (self ::TEN_MS );
417
450
$ bar ->advance ();
451
+ usleep (self ::TEN_MS );
418
452
$ bar ->setProgress (15 );
453
+ usleep (self ::TEN_MS );
419
454
$ bar ->setProgress (25 );
420
455
421
456
rewind ($ output ->getStream ());
@@ -490,6 +525,7 @@ public function testMultiByteSupport()
490
525
{
491
526
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
492
527
$ bar ->start ();
528
+ usleep (self ::TEN_MS );
493
529
$ bar ->setBarCharacter ('■ ' );
494
530
$ bar ->advance (3 );
495
531
@@ -505,6 +541,7 @@ public function testClear()
505
541
{
506
542
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
507
543
$ bar ->start ();
544
+ usleep (self ::TEN_MS );
508
545
$ bar ->setProgress (25 );
509
546
$ bar ->clear ();
510
547
@@ -521,8 +558,11 @@ public function testPercentNotHundredBeforeComplete()
521
558
{
522
559
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 200 );
523
560
$ bar ->start ();
561
+ usleep (self ::TEN_MS );
524
562
$ bar ->display ();
563
+ usleep (self ::TEN_MS );
525
564
$ bar ->advance (199 );
565
+ usleep (self ::TEN_MS );
526
566
$ bar ->advance ();
527
567
528
568
rewind ($ output ->getStream ());
@@ -541,6 +581,7 @@ public function testNonDecoratedOutput()
541
581
$ bar ->start ();
542
582
543
583
for ($ i = 0 ; $ i < 200 ; ++$ i ) {
584
+ usleep (self ::TEN_MS / 20 );
544
585
$ bar ->advance ();
545
586
}
546
587
@@ -567,9 +608,12 @@ public function testNonDecoratedOutputWithClear()
567
608
{
568
609
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (false ), 50 );
569
610
$ bar ->start ();
611
+ usleep (self ::TEN_MS );
570
612
$ bar ->setProgress (25 );
613
+ usleep (self ::TEN_MS );
571
614
$ bar ->clear ();
572
615
$ bar ->setProgress (50 );
616
+ usleep (self ::TEN_MS );
573
617
$ bar ->finish ();
574
618
575
619
rewind ($ output ->getStream ());
@@ -585,6 +629,7 @@ public function testNonDecoratedOutputWithoutMax()
585
629
{
586
630
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (false ));
587
631
$ bar ->start ();
632
+ usleep (self ::TEN_MS );
588
633
$ bar ->advance ();
589
634
590
635
rewind ($ output ->getStream ());
@@ -604,21 +649,27 @@ public function testParallelBars()
604
649
$ bar3 = new ProgressBar ($ output );
605
650
606
651
$ bar1 ->start ();
652
+ usleep (self ::TEN_MS );
607
653
$ output ->write ("\n" );
608
654
$ bar2 ->start ();
655
+ usleep (self ::TEN_MS );
609
656
$ output ->write ("\n" );
610
657
$ bar3 ->start ();
658
+ usleep (self ::TEN_MS );
611
659
612
660
for ($ i = 1 ; $ i <= 3 ; ++$ i ) {
613
661
// up two lines
614
662
$ output ->write ("\033[2A " );
615
663
if ($ i <= 2 ) {
616
664
$ bar1 ->advance ();
665
+ usleep (self ::TEN_MS );
617
666
}
618
667
$ output ->write ("\n" );
619
668
$ bar2 ->advance ();
669
+ usleep (self ::TEN_MS );
620
670
$ output ->write ("\n" );
621
671
$ bar3 ->advance ();
672
+ usleep (self ::TEN_MS );
622
673
}
623
674
$ output ->write ("\033[2A " );
624
675
$ output ->write ("\n" );
@@ -660,8 +711,11 @@ public function testWithoutMax()
660
711
661
712
$ bar = new ProgressBar ($ output );
662
713
$ bar ->start ();
714
+ usleep (self ::TEN_MS );
663
715
$ bar ->advance ();
716
+ usleep (self ::TEN_MS );
664
717
$ bar ->advance ();
718
+ usleep (self ::TEN_MS );
665
719
$ bar ->advance ();
666
720
$ bar ->finish ();
667
721
@@ -681,11 +735,15 @@ public function testSettingMaxStepsDuringProgressing()
681
735
$ output = $ this ->getOutputStream ();
682
736
$ bar = new ProgressBar ($ output );
683
737
$ bar ->start ();
738
+ usleep (self ::TEN_MS );
684
739
$ bar ->setProgress (2 );
740
+ usleep (self ::TEN_MS );
685
741
$ bar ->setMaxSteps (10 );
686
742
$ bar ->setProgress (5 );
743
+ usleep (self ::TEN_MS );
687
744
$ bar ->setMaxSteps (100 );
688
745
$ bar ->setProgress (10 );
746
+ usleep (self ::TEN_MS );
689
747
$ bar ->finish ();
690
748
691
749
rewind ($ output ->getStream ());
@@ -706,6 +764,7 @@ public function testWithSmallScreen()
706
764
$ bar = new ProgressBar ($ output );
707
765
putenv ('COLUMNS=12 ' );
708
766
$ bar ->start ();
767
+ usleep (self ::TEN_MS );
709
768
$ bar ->advance ();
710
769
putenv ('COLUMNS=120 ' );
711
770
@@ -726,7 +785,9 @@ public function testAddingPlaceholderFormatter()
726
785
$ bar ->setFormat (' %remaining_steps% [%bar%] ' );
727
786
728
787
$ bar ->start ();
788
+ usleep (self ::TEN_MS );
729
789
$ bar ->advance ();
790
+ usleep (self ::TEN_MS );
730
791
$ bar ->finish ();
731
792
732
793
rewind ($ output ->getStream ());
@@ -744,6 +805,7 @@ public function testMultilineFormat()
744
805
$ bar ->setFormat ("%bar% \nfoobar " );
745
806
746
807
$ bar ->start ();
808
+ usleep (self ::TEN_MS );
747
809
$ bar ->advance ();
748
810
$ bar ->clear ();
749
811
$ bar ->finish ();
@@ -789,6 +851,7 @@ public function testAnsiColorsAndEmojis()
789
851
rewind ($ output ->getStream ());
790
852
791
853
$ bar ->setMessage ('Looks good to me... ' , 'title ' );
854
+ usleep (self ::TEN_MS );
792
855
$ bar ->advance (4 );
793
856
794
857
rewind ($ output ->getStream ());
0 commit comments