From c8a1b19f267611cf0b7d5c6cd68330fcf0ec3285 Mon Sep 17 00:00:00 2001 From: Andrey Astakhov Date: Sun, 4 Dec 2016 13:01:18 +0100 Subject: [PATCH 1/2] Made ProgressBar final. --- src/Symfony/Component/Console/Helper/ProgressBar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 8212bedbf8041..eb15068542eb6 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -22,7 +22,7 @@ * @author Fabien Potencier * @author Chris Jones */ -class ProgressBar +final class ProgressBar { // options private $barWidth = 28; From 3615994925aad4ef4420c6ff7c9f8acc575a6471 Mon Sep 17 00:00:00 2001 From: Andrey Astakhov Date: Sun, 4 Dec 2016 14:06:12 +0100 Subject: [PATCH 2/2] Changed implementation of ProgressBar tests without class mocking. --- .../Console/Tests/Helper/ProgressBarTest.php | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index 1f9f31a3ee857..f4d2fe03036c4 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -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()