@@ -96,6 +96,77 @@ public function testAdvanceOverMax()
96
96
);
97
97
}
98
98
99
+ public function testRegress ()
100
+ {
101
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
102
+ $ bar ->start ();
103
+ $ bar ->advance ();
104
+ $ bar ->advance ();
105
+ $ bar ->advance (-1 );
106
+
107
+ rewind ($ output ->getStream ());
108
+ $ this ->assertEquals (
109
+ ' 0 [>---------------------------] ' .
110
+ $ this ->generateOutput (' 1 [->--------------------------] ' ).
111
+ $ this ->generateOutput (' 2 [-->-------------------------] ' ).
112
+ $ this ->generateOutput (' 1 [->--------------------------] ' ),
113
+ stream_get_contents ($ output ->getStream ())
114
+ );
115
+ }
116
+
117
+ public function testRegressWithStep ()
118
+ {
119
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
120
+ $ bar ->start ();
121
+ $ bar ->advance (4 );
122
+ $ bar ->advance (4 );
123
+ $ bar ->advance (-2 );
124
+
125
+ rewind ($ output ->getStream ());
126
+ $ this ->assertEquals (
127
+ ' 0 [>---------------------------] ' .
128
+ $ this ->generateOutput (' 4 [---->-----------------------] ' ).
129
+ $ this ->generateOutput (' 8 [-------->-------------------] ' ).
130
+ $ this ->generateOutput (' 6 [------>---------------------] ' ),
131
+ stream_get_contents ($ output ->getStream ())
132
+ );
133
+ }
134
+
135
+ public function testRegressMultipleTimes ()
136
+ {
137
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream ());
138
+ $ bar ->start ();
139
+ $ bar ->advance (3 );
140
+ $ bar ->advance (3 );
141
+ $ bar ->advance (-1 );
142
+ $ bar ->advance (-2 );
143
+
144
+ rewind ($ output ->getStream ());
145
+ $ this ->assertEquals (
146
+ ' 0 [>---------------------------] ' .
147
+ $ this ->generateOutput (' 3 [--->------------------------] ' ).
148
+ $ this ->generateOutput (' 6 [------>---------------------] ' ).
149
+ $ this ->generateOutput (' 5 [----->----------------------] ' ).
150
+ $ this ->generateOutput (' 3 [--->------------------------] ' ),
151
+ stream_get_contents ($ output ->getStream ())
152
+ );
153
+ }
154
+
155
+ public function testRegressBelowMin ()
156
+ {
157
+ $ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 10 );
158
+ $ bar ->setProgress (1 );
159
+ $ bar ->advance (-1 );
160
+ $ bar ->advance (-1 );
161
+
162
+ rewind ($ output ->getStream ());
163
+ $ this ->assertEquals (
164
+ ' 1/10 [==>-------------------------] 10% ' .
165
+ $ this ->generateOutput (' 0/10 [>---------------------------] 0% ' ),
166
+ stream_get_contents ($ output ->getStream ())
167
+ );
168
+ }
169
+
99
170
public function testFormat ()
100
171
{
101
172
$ expected =
@@ -282,18 +353,6 @@ public function testSetCurrentBeforeStarting()
341A
div>
282
353
$ this ->assertNotNull ($ bar ->getStartTime ());
283
354
}
284
355
285
- /**
286
- * @expectedException \LogicException
287
- * @expectedExceptionMessage You can't regress the progress bar
288
- */
289
- public function testRegressProgress ()
290
- {
291
- $ bar = new ProgressBar ($ output = $ this ->getOutputStream (), 50 );
292
- $ bar ->start ();
293
- $ bar ->setProgress (15 );
294
- $ bar ->setProgress (10 );
295
- }
296
-
297
356
public function testRedrawFrequency ()
298
357
{
299
358
$ bar = $ this ->getMock ('Symfony\Component\Console\Helper\ProgressBar ' , array ('display ' ), array ($ this ->getOutputStream (), 6 ));
0 commit comments