diff options
author | Frédéric Guillot <fred@kanboard.net> | 2017-12-15 11:24:35 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2017-12-15 11:55:42 -0800 |
commit | a93b8e10f5954be0853eec693c13e84c4bd9e6f2 (patch) | |
tree | eda5de9494b819235616e8623bb3393e9cc373af /vendor/symfony/console/Tests/Helper/ProgressBarTest.php | |
parent | 2c72a283f2d51034f85f4e2ca8b194d304a3c433 (diff) |
Kanboard requires at least PHP 5.6 now
Diffstat (limited to 'vendor/symfony/console/Tests/Helper/ProgressBarTest.php')
-rw-r--r-- | vendor/symfony/console/Tests/Helper/ProgressBarTest.php | 240 |
1 files changed, 184 insertions, 56 deletions
diff --git a/vendor/symfony/console/Tests/Helper/ProgressBarTest.php b/vendor/symfony/console/Tests/Helper/ProgressBarTest.php index 261908b5..aca64914 100644 --- a/vendor/symfony/console/Tests/Helper/ProgressBarTest.php +++ b/vendor/symfony/console/Tests/Helper/ProgressBarTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Tests\Helper; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Output\StreamOutput; @@ -18,7 +19,7 @@ use Symfony\Component\Console\Output\StreamOutput; /** * @group time-sensitive */ -class ProgressBarTest extends \PHPUnit_Framework_TestCase +class ProgressBarTest extends TestCase { public function testMultipleStart() { @@ -29,7 +30,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'). + ' 0 [>---------------------------]'. $this->generateOutput(' 1 [->--------------------------]'). $this->generateOutput(' 0 [>---------------------------]'), stream_get_contents($output->getStream()) @@ -44,7 +45,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'). + ' 0 [>---------------------------]'. $this->generateOutput(' 1 [->--------------------------]'), stream_get_contents($output->getStream()) ); @@ -58,7 +59,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'). + ' 0 [>---------------------------]'. $this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream()) ); @@ -73,7 +74,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'). + ' 0 [>---------------------------]'. $this->generateOutput(' 3 [--->------------------------]'). $this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream()) @@ -89,17 +90,88 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 9/10 [=========================>--] 90%'). + ' 9/10 [=========================>--] 90%'. $this->generateOutput(' 10/10 [============================] 100%'). $this->generateOutput(' 11/11 [============================] 100%'), stream_get_contents($output->getStream()) ); } + public function testRegress() + { + $bar = new ProgressBar($output = $this->getOutputStream()); + $bar->start(); + $bar->advance(); + $bar->advance(); + $bar->advance(-1); + + rewind($output->getStream()); + $this->assertEquals( + ' 0 [>---------------------------]'. + $this->generateOutput(' 1 [->--------------------------]'). + $this->generateOutput(' 2 [-->-------------------------]'). + $this->generateOutput(' 1 [->--------------------------]'), + stream_get_contents($output->getStream()) + ); + } + + public function testRegressWithStep() + { + $bar = new ProgressBar($output = $this->getOutputStream()); + $bar->start(); + $bar->advance(4); + $bar->advance(4); + $bar->advance(-2); + + rewind($output->getStream()); + $this->assertEquals( + ' 0 [>---------------------------]'. + $this->generateOutput(' 4 [---->-----------------------]'). + $this->generateOutput(' 8 [-------->-------------------]'). + $this->generateOutput(' 6 [------>---------------------]'), + stream_get_contents($output->getStream()) + ); + } + + public function testRegressMultipleTimes() + { + $bar = new ProgressBar($output = $this->getOutputStream()); + $bar->start(); + $bar->advance(3); + $bar->advance(3); + $bar->advance(-1); + $bar->advance(-2); + + rewind($output->getStream()); + $this->assertEquals( + ' 0 [>---------------------------]'. + $this->generateOutput(' 3 [--->------------------------]'). + $this->generateOutput(' 6 [------>---------------------]'). + $this->generateOutput(' 5 [----->----------------------]'). + $this->generateOutput(' 3 [--->------------------------]'), + stream_get_contents($output->getStream()) + ); + } + + public function testRegressBelowMin() + { + $bar = new ProgressBar($output = $this->getOutputStream(), 10); + $bar->setProgress(1); + $bar->advance(-1); + $bar->advance(-1); + + rewind($output->getStream()); + $this->assertEquals( + ' 1/10 [==>-------------------------] 10%'. + $this->generateOutput(' 0/10 [>---------------------------] 0%'), + stream_get_contents($output->getStream()) + ); + } + public function testFormat() { $expected = - $this->generateOutput(' 0/10 [>---------------------------] 0%'). + ' 0/10 [>---------------------------] 0%'. $this->generateOutput(' 10/10 [============================] 100%'). $this->generateOutput(' 10/10 [============================] 100%') ; @@ -156,7 +228,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/10 [/ ] 0%'). + ' 0/10 [/ ] 0%'. $this->generateOutput(' 1/10 [_/ ] 10%'), stream_get_contents($output->getStream()) ); @@ -169,7 +241,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------] 0%'), + ' 0/50 [>---------------------------] 0%', stream_get_contents($output->getStream()) ); } @@ -193,7 +265,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 50/50 [============================] 100%'), + ' 50/50 [============================] 100%', stream_get_contents($output->getStream()) ); } @@ -208,7 +280,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------] 0%'). + ' 0/50 [>---------------------------] 0%'. $this->generateOutput(' 0/50 [>---------------------------] 0%'). $this->generateOutput(' 1/50 [>---------------------------] 2%'). $this->generateOutput(' 2/50 [=>--------------------------] 4%'), @@ -230,7 +302,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------] 0%'). + ' 0/50 [>---------------------------] 0%'. $this->generateOutput(' 0/50 [>---------------------------] 0%'). $this->generateOutput(' 1/50 [>---------------------------] 2%'). $this->generateOutput(' 2/50 [=>--------------------------]'), @@ -247,7 +319,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------]'). + ' 0/50 [>---------------------------]'. $this->generateOutput(' 1/50 [>---------------------------]'), stream_get_contents($output->getStream()) ); @@ -264,7 +336,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------] 0%'). + ' 0/50 [>---------------------------] 0%'. $this->generateOutput(' 0/50 [>---------------------------] 0%'). $this->generateOutput(' 1/50 [>---------------------------] 2%'). $this->generateOutput(' 15/50 [========>-------------------] 30%'). @@ -273,8 +345,6 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ); } - /** - */ public function testSetCurrentBeforeStarting() { $bar = new ProgressBar($this->getOutputStream()); @@ -282,49 +352,54 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $this->assertNotNull($bar->getStartTime()); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage You can't regress the progress bar - */ - public function testRegressProgress() - { - $bar = new ProgressBar($output = $this->getOutputStream(), 50); - $bar->start(); - $bar->setProgress(15); - $bar->setProgress(10); - } - 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() @@ -336,7 +411,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'). + ' 0 [>---------------------------]'. $this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream()) ); @@ -351,7 +426,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/50 [>---------------------------] 0%'). + ' 0/50 [>---------------------------] 0%'. $this->generateOutput(' 25/50 [==============>-------------] 50%'). $this->generateOutput(''), stream_get_contents($output->getStream()) @@ -368,7 +443,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/200 [>---------------------------] 0%'). + ' 0/200 [>---------------------------] 0%'. $this->generateOutput(' 0/200 [>---------------------------] 0%'). $this->generateOutput(' 199/200 [===========================>] 99%'). $this->generateOutput(' 200/200 [============================] 100%'), @@ -468,9 +543,9 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/2 [>---------------------------] 0%')."\n". - $this->generateOutput(' 0/3 [#---------------------------] 0%')."\n". - rtrim($this->generateOutput(' 0 [>---------------------------]')). + ' 0/2 [>---------------------------] 0%'."\n". + ' 0/3 [#---------------------------] 0%'."\n". + rtrim(' 0 [>---------------------------]'). "\033[2A". $this->generateOutput(' 1/2 [==============>-------------] 50%')."\n". @@ -508,7 +583,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - rtrim($this->generateOutput(' 0 [>---------------------------]')). + rtrim(' 0 [>---------------------------]'). rtrim($this->generateOutput(' 1 [->--------------------------]')). rtrim($this->generateOutput(' 2 [-->-------------------------]')). rtrim($this->generateOutput(' 3 [--->------------------------]')). @@ -517,6 +592,24 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ); } + public function testWithSmallScreen() + { + $output = $this->getOutputStream(); + + $bar = new ProgressBar($output); + putenv('COLUMNS=12'); + $bar->start(); + $bar->advance(); + putenv('COLUMNS=120'); + + rewind($output->getStream()); + $this->assertEquals( + ' 0 [>---]'. + $this->generateOutput(' 1 [->--]'), + stream_get_contents($output->getStream()) + ); + } + public function testAddingPlaceholderFormatter() { ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', function (ProgressBar $bar) { @@ -531,7 +624,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 3 [>---------------------------]'). + ' 3 [>---------------------------]'. $this->generateOutput(' 2 [=========>------------------]'). $this->generateOutput(' 0 [============================]'), stream_get_contents($output->getStream()) @@ -550,7 +643,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(">---------------------------\nfoobar"). + ">---------------------------\nfoobar". $this->generateOutput("=========>------------------\nfoobar"). "\x0D\x1B[2K\x1B[1A\x1B[2K". $this->generateOutput("============================\nfoobar"), @@ -560,6 +653,8 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAnsiColorsAndEmojis() { + putenv('COLUMNS=156'); + $bar = new ProgressBar($output = $this->getOutputStream(), 15); ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) { static $i = 0; @@ -575,23 +670,37 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $bar->setMessage('Starting the demo... fingers crossed', 'title'); $bar->start(); + + rewind($output->getStream()); + $this->assertEquals( + " \033[44;37m Starting the demo... fingers crossed \033[0m\n". + ' 0/15 '.$progress.str_repeat($empty, 26)." 0%\n". + " \xf0\x9f\x8f\x81 < 1 sec \033[44;37m 0 B \033[0m", + stream_get_contents($output->getStream()) + ); + ftruncate($output->getStream(), 0); + rewind($output->getStream()); + $bar->setMessage('Looks good to me...', 'title'); $bar->advance(4); - $bar->setMessage('Thanks, bye', 'title'); - $bar->finish(); rewind($output->getStream()); $this->assertEquals( $this->generateOutput( - " \033[44;37m Starting the demo... fingers crossed \033[0m\n". - ' 0/15 '.$progress.str_repeat($empty, 26)." 0%\n". - " \xf0\x9f\x8f\x81 < 1 sec \033[44;37m 0 B \033[0m" - ). - $this->generateOutput( " \033[44;37m Looks good to me... \033[0m\n". ' 4/15 '.str_repeat($done, 7).$progress.str_repeat($empty, 19)." 26%\n". " \xf0\x9f\x8f\x81 < 1 sec \033[41;37m 97 KiB \033[0m" - ). + ), + stream_get_contents($output->getStream()) + ); + ftruncate($output->getStream(), 0); + rewind($output->getStream()); + + $bar->setMessage('Thanks, bye', 'title'); + $bar->finish(); + + rewind($output->getStream()); + $this->assertEquals( $this->generateOutput( " \033[44;37m Thanks, bye \033[0m\n". ' 15/15 '.str_repeat($done, 28)." 100%\n". @@ -599,6 +708,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ), stream_get_contents($output->getStream()) ); + putenv('COLUMNS=120'); } public function testSetFormat() @@ -608,7 +718,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $bar->start(); rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0 [>---------------------------]'), + ' 0 [>---------------------------]', stream_get_contents($output->getStream()) ); @@ -617,7 +727,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $bar->start(); rewind($output->getStream()); $this->assertEquals( - $this->generateOutput(' 0/10 [>---------------------------] 0%'), + ' 0/10 [>---------------------------] 0%', stream_get_contents($output->getStream()) ); } @@ -661,4 +771,22 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase return "\x0D\x1B[2K".($count ? str_repeat("\x1B[1A\x1B[2K", $count) : '').$expected; } + + public function testBarWidthWithMultilineFormat() + { + putenv('COLUMNS=10'); + + $bar = new ProgressBar($output = $this->getOutputStream()); + $bar->setFormat("%bar%\n0123456789"); + + // before starting + $bar->setBarWidth(5); + $this->assertEquals(5, $bar->getBarWidth()); + + // after starting + $bar->start(); + rewind($output->getStream()); + $this->assertEquals(5, $bar->getBarWidth(), stream_get_contents($output->getStream())); + putenv('COLUMNS=120'); + } } |