You are here

public function ProgressBarTest::testAnsiColorsAndEmojis in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Tests/Helper/ProgressBarTest.php \Symfony\Component\Console\Tests\Helper\ProgressBarTest::testAnsiColorsAndEmojis()

@requires extension mbstring

File

vendor/symfony/console/Tests/Helper/ProgressBarTest.php, line 509

Class

ProgressBarTest

Namespace

Symfony\Component\Console\Tests\Helper

Code

public function testAnsiColorsAndEmojis() {
  $bar = new ProgressBar($output = $this
    ->getOutputStream(), 15);
  ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
    static $i = 0;
    $mem = 100000 * $i;
    $colors = $i++ ? '41;37' : '44;37';
    return "\33[" . $colors . 'm ' . Helper::formatMemory($mem) . " \33[0m";
  });
  $bar
    ->setFormat(" \33[44;37m %title:-37s% \33[0m\n %current%/%max% %bar% %percent:3s%%\n ๐Ÿ  %remaining:-10s% %memory:37s%");
  $bar
    ->setBarCharacter($done = "\33[32mโ—\33[0m");
  $bar
    ->setEmptyBarCharacter($empty = "\33[31mโ—\33[0m");
  $bar
    ->setProgressCharacter($progress = "\33[32mโžค \33[0m");
  $bar
    ->setMessage('Starting the demo... fingers crossed', 'title');
  $bar
    ->start();
  $bar
    ->setMessage('Looks good to me...', 'title');
  $bar
    ->advance(4);
  $bar
    ->setMessage('Thanks, bye', 'title');
  $bar
    ->finish();
  rewind($output
    ->getStream());
  $this
    ->assertEquals($this
    ->generateOutput(" \33[44;37m Starting the demo... fingers crossed  \33[0m\n" . '  0/15 ' . $progress . str_repeat($empty, 26) . "   0%\n" . " ๐Ÿ  1 sec                          \33[44;37m 0 B \33[0m") . $this
    ->generateOutput(" \33[44;37m Looks good to me...                   \33[0m\n" . '  4/15 ' . str_repeat($done, 7) . $progress . str_repeat($empty, 19) . "  26%\n" . " ๐Ÿ  1 sec                       \33[41;37m 97 KiB \33[0m") . $this
    ->generateOutput(" \33[44;37m Thanks, bye                           \33[0m\n" . ' 15/15 ' . str_repeat($done, 28) . " 100%\n" . " ๐Ÿ  1 sec                      \33[41;37m 195 KiB \33[0m"), stream_get_contents($output
    ->getStream()));
}