Skip to content

Commit 90df479

Browse files
committed
feature symfony#20487 [Console] Disallow inheritance from ProgressBar (a-ast)
This PR was squashed before being merged into the 3.3-dev branch (closes symfony#20487). Discussion ---------- [Console] Disallow inheritance from ProgressBar | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#20427 | License | MIT | Doc PR | ~ Changed `ProgressBar` to `final`, fixed tests. As explained below, this modification doesn't break BC because inheritance from `ProgressBar` was not possible anyway. See: symfony#20427 Commits ------- a2668f6 [Console] Disallow inheritance from ProgressBar
2 parents 902d9ed + a2668f6 commit 90df479

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Fabien Potencier <[email protected]>
2323
* @author Chris Jones <[email protected]>
2424
*/
25-
class ProgressBar
25+
final class ProgressBar
2626
{
2727
// options
2828
private $barWidth = 28;

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,35 +353,52 @@ public function testSetCurrentBeforeStarting()
353353

354354
public function testRedrawFrequency()
355355
{
356-
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream(), 6));
357-
$bar->expects($this->exactly(4))->method('display');
358-
356+
$bar = new ProgressBar($output = $this->getOutputStream(), 6);
359357
$bar->setRedrawFrequency(2);
360358
$bar->start();
361359
$bar->setProgress(1);
362360
$bar->advance(2);
363361
$bar->advance(2);
364362
$bar->advance(1);
363+
364+
rewind($output->getStream());
365+
$this->assertEquals(
366+
' 0/6 [>---------------------------] 0%'.
367+
$this->generateOutput(' 3/6 [==============>-------------] 50%').
368+
$this->generateOutput(' 5/6 [=======================>----] 83%').
369+
$this->generateOutput(' 6/6 [============================] 100%'),
370+
stream_get_contents($output->getStream())
371+
);
365372
}
366373

367374
public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
368375
{
369-
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));
370-
371-
$bar->expects($this->exactly(2))->method('display');
376+
$bar = new ProgressBar($output = $this->getOutputStream());
372377
$bar->setRedrawFrequency(0);
373378
$bar->start();
374379
$bar->advance();
380+
381+
rewind($output->getStream());
382+
$this->assertEquals(
383+
' 0 [>---------------------------]'.
384+
$this->generateOutput(' 1 [->--------------------------]'),
385+
stream_get_contents($output->getStream())
386+
);
375387
}
376388

377389
public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
378390
{
379-
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));
380-
381-
$bar->expects($this->exactly(2))->method('display');
391+
$bar = new ProgressBar($output = $this->getOutputStream());
382392
$bar->setRedrawFrequency(0.9);
383393
$bar->start();
384394
$bar->advance();
395+
396+
rewind($output->getStream());
397+
$this->assertEquals(
398+
' 0 [>---------------------------]'.
399+
$this->generateOutput(' 1 [->--------------------------]'),
400+
stream_get_contents($output->getStream())
401+
);
385402
}
386403

387404
public function testMultiByteSupport()

0 commit comments

Comments
 (0)