Laravel version update
Laravel version update
This commit is contained in:
@@ -11,14 +11,15 @@
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ProgressBarTest extends \PHPUnit_Framework_TestCase
|
||||
class ProgressBarTest extends TestCase
|
||||
{
|
||||
public function testMultipleStart()
|
||||
{
|
||||
@@ -96,6 +97,77 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
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 =
|
||||
@@ -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()
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
$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(
|
||||
|
||||
" \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"
|
||||
).
|
||||
$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()
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user