@@ -19,6 +19,14 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase
19
19
{
20
20
protected $ lastMessagesLength ;
21
21
22
+ /**
23
+ * @expectedException InvalidArgumentException
24
+ */
25
+ public function testInitializeWithNegativeMax ()
26
+ {
27
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream (), -1 );
28
+ }
29
+
22
30
public function testAdvance ()
23
31
{
24
32
$ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
@@ -82,6 +90,42 @@ public function testCustomizations()
82
90
);
83
91
}
84
92
93
+ public function testDisplayWithoutStart ()
94
+ {
95
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
96
+ $ bar ->display ();
97
+
98
+ rewind ($ output ->getStream ());
99
+ $ this ->assertEquals (
100
+ $ this ->generateOutput (' 0/50 [>---------------------------] 0% ' ),
101
+ stream_get_contents ($ output ->getStream ())
102
+ );
103
+ }
104
+
105
+ public function testDisplayWithQuietVerbosity ()
106
+ {
107
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream (true , StreamOutput::VERBOSITY_QUIET ), 50 );
108
+ $ bar ->display ();
109
+
110
+ rewind ($ output ->getStream ());
111
+ $ this ->assertEquals (
112
+ '' ,
113
+ stream_get_contents ($ output ->getStream ())
114
+ );
115
+ }
116
+
117
+ public function testFinishWithoutStart ()
118
+ {
119
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
120
+ $ bar ->finish ();
121
+
122
+ rewind ($ output ->getStream ());
123
+ $ this ->assertEquals (
124
+ $ this ->generateOutput (' 50/50 [============================] 100% ' ),
125
+ stream_get_contents ($ output ->getStream ())
126
+ );
127
+ }
128
+
85
129
public function testPercent ()
86
130
{
87
131
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
@@ -122,6 +166,23 @@ public function testOverwriteWithShorterLine()
122
166
);
123
167
}
124
168
169
+ public function testStartWithMax ()
170
+ {
171
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
172
+ $ bar ->setFormat ('%current%/%max% [%bar%] ' );
173
+ $ bar ->start (50 );
174
+ $ bar ->display ();
175
+ $ bar ->advance ();
176
+
177
+ rewind ($ output ->getStream ());
178
+ $ this ->assertEquals (
179
+ $ this ->generateOutput (' 0/50 [>---------------------------] ' ).
180
+ $ this ->generateOutput (' 0/50 [>---------------------------] ' ).
181
+ $ this ->generateOutput (' 1/50 [>---------------------------] ' ),
182
+ stream_get_contents ($ output ->getStream ())
183
+ );
184
+ }
185
+
125
186
public function testSetCurrentProgress ()
126
187
{
127
188
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
@@ -143,13 +204,12 @@ public function testSetCurrentProgress()
143
204
}
144
205
145
206
/**
146
- * @expectedException \LogicException
147
- * @expectedExceptionMessage You must start the progress bar
148
207
*/
149
208
public function testSetCurrentBeforeStarting ()
150
209
{
151
210
$ bar = new ProgressBar ($ this ->getOutputStream ());
152
211
$ bar ->setCurrent (15 );
212
+ $ this ->assertNotNull ($ bar ->getStartTime ());
153
213
}
154
214
155
215
/**
@@ -302,7 +362,7 @@ public function testParallelBars()
302
362
public function testAddingPlaceholderFormatter ()
303
363
{
304
364
ProgressBar::setPlaceholderFormatterDefinition ('remaining_steps ' , function (ProgressBar $ bar ) {
305
- return $ bar ->getMaxSteps () - $ bar ->getStep ();
365
+ return $ bar ->getMaxSteps () - $ bar ->getCurrent ();
306
366
});
307
367
$ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 3 );
308
368
$ bar ->setFormat (' %remaining_steps% [%bar%] ' );
@@ -432,9 +492,9 @@ public function provideFormat()
432
492
);
433
493
}
434
494
435
- protected function getOutputStream ($ decorated = true )
495
+ protected function getOutputStream ($ decorated = true , $ verbosity = StreamOutput:: VERBOSITY_NORMAL )
436
496
{
437
- return new StreamOutput (fopen ('php://memory ' , 'r+ ' , false ), StreamOutput:: VERBOSITY_NORMAL , $ decorated );
497
+ return new StreamOutput (fopen ('php://memory ' , 'r+ ' , false ), $ verbosity , $ decorated );
438
498
}
439
499
440
500
protected function generateOutput ($ expected )
0 commit comments