8000 [Console] Disallow inheritance from ProgressBar by a-ast · Pull Request #20487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Disallow inheritance from ProgressBar #20487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Chris Jones <leeked@gmail.com>
*/
class ProgressBar
final class ProgressBar
{
// options
private $barWidth = 28;
Expand Down
35 changes: 26 additions & 9 deletions src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,35 +353,52 @@ public function testSetCurrentBeforeStarting()

public function testRedrawFrequency()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream(), 6));
$bar->expects($this->exactly(4))->method('display');

$bar = new ProgressBar($output = $this->getOutputStream(), 6);
$bar->setRedrawFrequency(2);
$bar->start();
$bar->setProgress(1);
$bar->advance(2);
$bar->advance(2);
$bar->advance(1);

rewind($output->getStream());
$this->assertEquals(
' 0/6 [>---------------------------] 0%'.
$this->generateOutput(' 3/6 [==============>-------------] 50%').
$this->generateOutput(' 5/6 [=======================>----] 83%').
$this->generateOutput(' 6/6 [============================] 100%'),
stream_get_contents($output->getStream())
);
}

public function testRedrawFrequencyIsAtLeastOneIfZeroGiven()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));

$bar->expects($this->exactly(2))->method('display');
$bar = new ProgressBar($output = $this->getOutputStream());
$bar->setRedrawFrequency(0);
$bar->start();
$bar->advance();

rewind($output->getStream());
$this->assertEquals(
' 0 [>---------------------------]'.
$this->generateOutput(' 1 [->--------------------------]'),
stream_get_contents($output->getStream())
);
}

public function testRedrawFrequencyIsAtLeastOneIfSmallerOneGiven()
{
$bar = $this->getMock('Symfony\Component\Console\Helper\ProgressBar', array('display'), array($this->getOutputStream()));

$bar->expects($this->exactly(2))->method('display');
$bar = new ProgressBar($output = $this->getOutputStream());
$bar->setRedrawFrequency(0.9);
$bar->start();
$bar->advance();

rewind($output->getStream());
$this->assertEquals(
' 0 [>---------------------------]'.
$this->generateOutput(' 1 [->--------------------------]'),
stream_get_contents($output->getStream())
);
}

public function testMultiByteSupport()
Expand Down
0