the whole shebang
This commit is contained in:
176
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php
vendored
Normal file
176
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\DialogHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class DialogHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSelect()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
|
||||
$this->assertEquals('2', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, '2'));
|
||||
$this->assertEquals('1', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes));
|
||||
$this->assertEquals('1', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes));
|
||||
$this->assertEquals('1', $dialog->select($output = $this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', false));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertContains('Input "Fabien" is not a superhero!', stream_get_contents($output->getStream()));
|
||||
|
||||
try {
|
||||
$this->assertEquals('1', $dialog->select($output = $this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, 1));
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals('Value "Fabien" is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals(array('1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
|
||||
$this->assertEquals(array('0', '2'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
|
||||
$this->assertEquals(array('0', '2'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
|
||||
$this->assertEquals(array('0', '1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, '0,1', false, 'Input "%s" is not a superhero!', true));
|
||||
$this->assertEquals(array('0', '1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, ' 0 , 1 ', false, 'Input "%s" is not a superhero!', true));
|
||||
}
|
||||
|
||||
public function testAsk()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n8AM\n"));
|
||||
|
||||
$this->assertEquals('2PM', $dialog->ask($this->getOutputStream(), 'What time is it?', '2PM'));
|
||||
$this->assertEquals('8AM', $dialog->ask($output = $this->getOutputStream(), 'What time is it?', '2PM'));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('What time is it?', stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAskWithAutocomplete()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// Acm<NEWLINE>
|
||||
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
|
||||
// <NEWLINE>
|
||||
// <UP ARROW><UP ARROW><NEWLINE>
|
||||
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
|
||||
// <DOWN ARROW><NEWLINE>
|
||||
// S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
// F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
|
||||
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
|
||||
|
||||
$dialog = new DialogHelper();
|
||||
$dialog->setInputStream($inputStream);
|
||||
|
||||
$bundles = array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle');
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('FrameworkBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('SecurityBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('FooBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
|
||||
}
|
||||
|
||||
public function testAskHiddenResponse()
|
||||
{
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||
$this->markTestSkipped('This test is not supported on Windows');
|
||||
}
|
||||
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("8AM\n"));
|
||||
|
||||
$this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?'));
|
||||
}
|
||||
|
||||
public function testAskConfirmation()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n\n"));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?'));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("y\nyes\n"));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("n\nno\n"));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', true));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', true));
|
||||
}
|
||||
|
||||
public function testAskAndValidate()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question ='What color was the white horse of Henry IV?';
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
return $color;
|
||||
};
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\nblack\n"));
|
||||
$this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
$this->assertEquals('black', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
|
||||
try {
|
||||
$this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals($error, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+', false);
|
||||
fputs($stream, $input);
|
||||
rewind($stream);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
||||
protected function getOutputStream()
|
||||
{
|
||||
return new StreamOutput(fopen('php://memory', 'r+', false));
|
||||
}
|
||||
|
||||
private function hasSttyAvailable()
|
||||
{
|
||||
exec('stty 2>&1', $output, $exitcode);
|
||||
|
||||
return $exitcode === 0;
|
||||
}
|
||||
}
|
84
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php
vendored
Normal file
84
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
|
||||
class FormatterHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFormatSection()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<info>[cli]</info> Some text to display',
|
||||
$formatter->formatSection('cli', 'Some text to display'),
|
||||
'::formatSection() formats a message in a section'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlock()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> Some text to display </error>',
|
||||
$formatter->formatBlock('Some text to display', 'error'),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> Some text to display </error>'."\n" .
|
||||
'<error> foo bar </error>',
|
||||
$formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>'."\n" .
|
||||
'<error> Some text to display </error>'."\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('Some text to display', 'error', true),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlockWithDiacriticLetters()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('This test requires mbstring to work.');
|
||||
}
|
||||
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>'."\n" .
|
||||
'<error> Du texte à afficher </error>'."\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('Du texte à afficher', 'error', true),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlockLGEscaping()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>'."\n" .
|
||||
'<error> \<info>some info\</info> </error>'."\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('<info>some info</info>', 'error', true),
|
||||
'::formatBlock() escapes \'<\' chars'
|
||||
);
|
||||
}
|
||||
}
|
136
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
vendored
Normal file
136
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/HelperSetTest.php
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class HelperSetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::__construct
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$mock_helper = $this->getGenericMockHelper('fake_helper');
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $mock_helper));
|
||||
|
||||
$this->assertEquals($mock_helper, $helperset->get('fake_helper_alias'), '__construct sets given helper to helpers');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '__construct sets helper alias for given helper');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::set
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper', $helperset));
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->set() adds helper to helpers');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset));
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset));
|
||||
$this->assertTrue($helperset->has('fake_helper_01'), '->set() will set multiple helpers on consecutive calls');
|
||||
$this->assertTrue($helperset->has('fake_helper_02'), '->set() will set multiple helpers on consecutive calls');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->set($this->getGenericMockHelper('fake_helper', $helperset), 'fake_helper_alias');
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->set() adds helper alias when set');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '->set() adds helper alias when set');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::has
|
||||
*/
|
||||
public function testHas()
|
||||
{
|
||||
$helperset = new HelperSet(array('fake_helper_alias' => $this->getGenericMockHelper('fake_helper')));
|
||||
$this->assertTrue($helperset->has('fake_helper'), '->has() finds set helper');
|
||||
$this->assertTrue($helperset->has('fake_helper_alias'), '->has() finds set helper by alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::get
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$helper_01 = $this->getGenericMockHelper('fake_helper_01');
|
||||
$helper_02 = $this->getGenericMockHelper('fake_helper_02');
|
||||
$helperset = new HelperSet(array('fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02));
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01'), '->get() returns correct helper by name');
|
||||
$this->assertEquals($helper_01, $helperset->get('fake_helper_01_alias'), '->get() returns correct helper by alias');
|
||||
$this->assertEquals($helper_02, $helperset->get('fake_helper_02'), '->get() returns correct helper by name');
|
||||
$this->assertEquals($helper_02, $helperset->get('fake_helper_02_alias'), '->get() returns correct helper by alias');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
try {
|
||||
$helperset->get('foo');
|
||||
$this->fail('->get() throws \InvalidArgumentException when helper not found');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws \InvalidArgumentException when helper not found');
|
||||
$this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \InvalidArgumentException when helper not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::setCommand
|
||||
*/
|
||||
public function testSetCommand()
|
||||
{
|
||||
$cmd_01 = new Command('foo');
|
||||
$cmd_02 = new Command('bar');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd_01);
|
||||
$this->assertEquals($cmd_01, $helperset->getCommand(), '->setCommand() stores given command');
|
||||
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd_01);
|
||||
$helperset->setCommand($cmd_02);
|
||||
$this->assertEquals($cmd_02, $helperset->getCommand(), '->setCommand() overwrites stored command with consecutive calls');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Symfony\Component\Console\Helper\HelperSet::getCommand
|
||||
*/
|
||||
public function testGetCommand()
|
||||
{
|
||||
$cmd = new Command('foo');
|
||||
$helperset = new HelperSet();
|
||||
$helperset->setCommand($cmd);
|
||||
$this->assertEquals($cmd, $helperset->getCommand(), '->getCommand() retrieves stored command');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic mock for the helper interface. Optionally check for a call to setHelperSet with a specific
|
||||
* helperset instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param HelperSet $helperset allows a mock to verify a particular helperset set is being added to the Helper
|
||||
*/
|
||||
private function getGenericMockHelper($name, HelperSet $helperset = null)
|
||||
{
|
||||
$mock_helper = $this->getMock('\Symfony\Component\Console\Helper\HelperInterface');
|
||||
$mock_helper->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($name));
|
||||
|
||||
if ($helperset) {
|
||||
$mock_helper->expects($this->any())
|
||||
->method('setHelperSet')
|
||||
->with($this->equalTo($helperset));
|
||||
}
|
||||
|
||||
return $mock_helper;
|
||||
}
|
||||
}
|
185
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php
vendored
Normal file
185
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\ProgressHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class ProgressHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAdvance()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream());
|
||||
$progress->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 1 [->--------------------------]'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAdvanceWithStep()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream());
|
||||
$progress->advance(5);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAdvanceMultipleTimes()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream());
|
||||
$progress->advance(3);
|
||||
$progress->advance(2);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 3 [--->------------------------]').$this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testCustomizations()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->setBarWidth(10);
|
||||
$progress->setBarCharacter('_');
|
||||
$progress->setEmptyBarCharacter(' ');
|
||||
$progress->setProgressCharacter('/');
|
||||
$progress->setFormat(' %current%/%max% [%bar%] %percent%%');
|
||||
$progress->start($output = $this->getOutputStream(), 10);
|
||||
$progress->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 1/10 [_/ ] 10%'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testPercent()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream(), 50);
|
||||
$progress->display();
|
||||
$progress->advance();
|
||||
$progress->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 0/50 [>---------------------------] 0%').$this->generateOutput(' 1/50 [>---------------------------] 2%').$this->generateOutput(' 2/50 [=>--------------------------] 4%'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testOverwriteWithShorterLine()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->setFormat(' %current%/%max% [%bar%] %percent%%');
|
||||
$progress->start($output = $this->getOutputStream(), 50);
|
||||
$progress->display();
|
||||
$progress->advance();
|
||||
|
||||
// set shorter format
|
||||
$progress->setFormat(' %current%/%max% [%bar%]');
|
||||
$progress->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
$this->generateOutput(' 0/50 [>---------------------------] 0%') .
|
||||
$this->generateOutput(' 1/50 [>---------------------------] 2%') .
|
||||
$this->generateOutput(' 2/50 [=>--------------------------] '),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetCurrentProgress()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream(), 50);
|
||||
$progress->display();
|
||||
$progress->advance();
|
||||
$progress->setCurrent(15);
|
||||
$progress->setCurrent(25);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
$this->generateOutput(' 0/50 [>---------------------------] 0%') .
|
||||
$this->generateOutput(' 1/50 [>---------------------------] 2%') .
|
||||
$this->generateOutput(' 15/50 [========>-------------------] 30%') .
|
||||
$this->generateOutput(' 25/50 [==============>-------------] 50%'),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage You must start the progress bar
|
||||
*/
|
||||
public function testSetCurrentBeforeStarting()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->setCurrent(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage You can't regress the progress bar
|
||||
*/
|
||||
public function testRegressProgress()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream(), 50);
|
||||
$progress->setCurrent(15);
|
||||
$progress->setCurrent(10);
|
||||
}
|
||||
|
||||
public function testMultiByteSupport()
|
||||
{
|
||||
if (!function_exists('mb_strlen') || (false === $encoding = mb_detect_encoding('■'))) {
|
||||
$this->markTestSkipped('The mbstring extension is needed for multi-byte support');
|
||||
}
|
||||
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream());
|
||||
$progress->setBarCharacter('■');
|
||||
$progress->advance(3);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testPercentNotHundredBeforeComplete()
|
||||
{
|
||||
$progress = new ProgressHelper();
|
||||
$progress->start($output = $this->getOutputStream(), 200);
|
||||
$progress->display();
|
||||
$progress->advance(199);
|
||||
$progress->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%').$this->generateOutput(' 199/200 [===========================>] 99%').$this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
protected function getOutputStream()
|
||||
{
|
||||
return new StreamOutput(fopen('php://memory', 'r+', false));
|
||||
}
|
||||
|
||||
protected $lastMessagesLength;
|
||||
|
||||
protected function generateOutput($expected)
|
||||
{
|
||||
$expectedout = $expected;
|
||||
|
||||
if ($this->lastMessagesLength !== null) {
|
||||
$expectedout = str_pad($expected, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
$this->lastMessagesLength = strlen($expectedout);
|
||||
|
||||
return "\x0D".$expectedout;
|
||||
}
|
||||
}
|
215
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/TableHelperTest.php
vendored
Normal file
215
vendor/symfony/console/Symfony/Component/Console/Tests/Helper/TableHelperTest.php
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\TableHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class TableHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $stream;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->stream = fopen('php://memory', 'r+');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
fclose($this->stream);
|
||||
$this->stream = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testRenderProvider
|
||||
*/
|
||||
public function testRender($headers, $rows, $layout, $expected)
|
||||
{
|
||||
$table = new TableHelper();
|
||||
$table
|
||||
->setHeaders($headers)
|
||||
->setRows($rows)
|
||||
->setLayout($layout)
|
||||
;
|
||||
$table->render($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testRenderProvider
|
||||
*/
|
||||
public function testRenderAddRows($headers, $rows, $layout, $expected)
|
||||
{
|
||||
$table = new TableHelper();
|
||||
$table
|
||||
->setHeaders($headers)
|
||||
->addRows($rows)
|
||||
->setLayout($layout)
|
||||
;
|
||||
$table->render($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testRenderProvider
|
||||
*/
|
||||
public function testRenderAddRowsOneByOne($headers, $rows, $layout, $expected)
|
||||
{
|
||||
$table = new TableHelper();
|
||||
$table
|
||||
->setHeaders($headers)
|
||||
->setLayout($layout)
|
||||
;
|
||||
foreach ($rows as $row) {
|
||||
$table->addRow($row);
|
||||
}
|
||||
$table->render($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testRenderProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('ISBN', 'Title', 'Author'),
|
||||
array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
),
|
||||
TableHelper::LAYOUT_DEFAULT,
|
||||
<<<TABLE
|
||||
+---------------+--------------------------+------------------+
|
||||
| ISBN | Title | Author |
|
||||
+---------------+--------------------------+------------------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
|
||||
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
|
||||
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
|
||||
+---------------+--------------------------+------------------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array('ISBN', 'Title', 'Author'),
|
||||
array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
),
|
||||
TableHelper::LAYOUT_BORDERLESS,
|
||||
" =============== ========================== ================== \n ISBN Title Author \n =============== ========================== ================== \n 99921-58-10-7 Divine Comedy Dante Alighieri \n 9971-5-0210-0 A Tale of Two Cities Charles Dickens \n 960-425-059-0 The Lord of the Rings J. R. R. Tolkien \n 80-902734-1-6 And Then There Were None Agatha Christie \n =============== ========================== ================== \n"
|
||||
),
|
||||
array(
|
||||
array('ISBN', 'Title'),
|
||||
array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0'),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
),
|
||||
TableHelper::LAYOUT_DEFAULT,
|
||||
<<<TABLE
|
||||
+---------------+--------------------------+------------------+
|
||||
| ISBN | Title | |
|
||||
+---------------+--------------------------+------------------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||
| 9971-5-0210-0 | | |
|
||||
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
|
||||
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
|
||||
+---------------+--------------------------+------------------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0'),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
),
|
||||
TableHelper::LAYOUT_DEFAULT,
|
||||
<<<TABLE
|
||||
+---------------+--------------------------+------------------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||
| 9971-5-0210-0 | | |
|
||||
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
|
||||
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
|
||||
+---------------+--------------------------+------------------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array('ISBN', 'Title'),
|
||||
array(),
|
||||
TableHelper::LAYOUT_DEFAULT,
|
||||
<<<TABLE
|
||||
+------+-------+
|
||||
| ISBN | Title |
|
||||
+------+-------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
TableHelper::LAYOUT_DEFAULT,
|
||||
'',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRenderMultiByte()
|
||||
{
|
||||
if (!function_exists('mb_strlen')) {
|
||||
$this->markTestSkipped('The "mbstring" extension is not available');
|
||||
}
|
||||
|
||||
$table = new TableHelper();
|
||||
$table
|
||||
->setHeaders(array('■■'))
|
||||
->setRows(array(array(1234)))
|
||||
->setLayout(TableHelper::LAYOUT_DEFAULT)
|
||||
;
|
||||
$table->render($output = $this->getOutputStream());
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
+------+
|
||||
| ■■ |
|
||||
+------+
|
||||
| 1234 |
|
||||
+------+
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
protected function getOutputStream()
|
||||
{
|
||||
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, false);
|
||||
}
|
||||
|
||||
protected function getOutputContent(StreamOutput $output)
|
||||
{
|
||||
rewind($output->getStream());
|
||||
|
||||
return str_replace(PHP_EOL, "\n", stream_get_contents($output->getStream()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user