composer update
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?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 PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ClassExistsMock;
|
||||
use Symfony\Component\Console\Helper\Dumper;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
class DumperNativeFallbackTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ClassExistsMock::register(Dumper::class);
|
||||
ClassExistsMock::withMockedClasses([
|
||||
CliDumper::class => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
ClassExistsMock::withMockedClasses([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideVariables
|
||||
*/
|
||||
public function testInvoke($variable, $primitiveString)
|
||||
{
|
||||
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
|
||||
|
||||
$this->assertSame($primitiveString, $dumper($variable));
|
||||
}
|
||||
|
||||
public function provideVariables()
|
||||
{
|
||||
return [
|
||||
[null, 'null'],
|
||||
[true, 'true'],
|
||||
[false, 'false'],
|
||||
[1, '1'],
|
||||
[-1.5, '-1.5'],
|
||||
['string', '"string"'],
|
||||
[[1, '2'], "Array\n(\n [0] => 1\n [1] => 2\n)"],
|
||||
[new \stdClass(), "stdClass Object\n(\n)"],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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 PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\Dumper;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
|
||||
class DumperTest extends TestCase
|
||||
{
|
||||
use VarDumperTestTrait;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
putenv('DUMP_LIGHT_ARRAY=1');
|
||||
putenv('DUMP_COMMA_SEPARATOR=1');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
putenv('DUMP_LIGHT_ARRAY');
|
||||
putenv('DUMP_COMMA_SEPARATOR');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideVariables
|
||||
*/
|
||||
public function testInvoke($variable)
|
||||
{
|
||||
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
|
||||
|
||||
$this->assertDumpMatchesFormat($dumper($variable), $variable);
|
||||
}
|
||||
|
||||
public function provideVariables()
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
[true],
|
||||
[false],
|
||||
[1],
|
||||
[-1.5],
|
||||
['string'],
|
||||
[[1, '2']],
|
||||
[new \stdClass()],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -880,6 +880,41 @@ class ProgressBarTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testIterate(): void
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals([1, 2], \iterator_to_array($bar->iterate([1, 2])));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0/2 [>---------------------------] 0%'.
|
||||
$this->generateOutput(' 1/2 [==============>-------------] 50%').
|
||||
$this->generateOutput(' 2/2 [============================] 100%').
|
||||
$this->generateOutput(' 2/2 [============================] 100%'),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testIterateUncountable(): void
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
|
||||
$this->assertEquals([1, 2], \iterator_to_array($bar->iterate((function () {
|
||||
yield 1;
|
||||
yield 2;
|
||||
})())));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0 [>---------------------------]'.
|
||||
$this->generateOutput(' 1 [->--------------------------]').
|
||||
$this->generateOutput(' 2 [-->-------------------------]').
|
||||
$this->generateOutput(' 2 [============================]'),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = true, $verbosity = StreamOutput::VERBOSITY_NORMAL)
|
||||
{
|
||||
return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, $decorated);
|
||||
|
||||
@@ -198,6 +198,49 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskWithAutocompleteCallback()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// Po<TAB>Cr<TAB>P<DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
$inputStream = $this->getInputStream("Pa\177\177o\tCr\tP\033[A\033[A\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('What\'s for dinner?');
|
||||
|
||||
// A simple test callback - return an array containing the words the
|
||||
// user has already completed, suffixed with all known words.
|
||||
//
|
||||
// Eg: If the user inputs "Potato C", the return will be:
|
||||
//
|
||||
// ["Potato Carrot ", "Potato Creme ", "Potato Curry ", ...]
|
||||
//
|
||||
// No effort is made to avoid irrelevant suggestions, as this is handled
|
||||
// by the autocomplete function.
|
||||
$callback = function ($input) {
|
||||
$knownWords = ['Carrot', 'Creme', 'Curry', 'Parsnip', 'Pie', 'Potato', 'Tart'];
|
||||
$inputWords = explode(' ', $input);
|
||||
array_pop($inputWords);
|
||||
$suggestionBase = $inputWords ? implode(' ', $inputWords).' ' : '';
|
||||
|
||||
return array_map(
|
||||
function ($word) use ($suggestionBase) {
|
||||
return $suggestionBase.$word.' ';
|
||||
},
|
||||
$knownWords
|
||||
);
|
||||
};
|
||||
|
||||
$question->setAutocompleterCallback($callback);
|
||||
|
||||
$this->assertSame('Potato Creme Pie', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskWithAutocompleteWithNonSequentialKeys()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
@@ -667,6 +710,37 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testTraversableMultiselectAutocomplete()
|
||||
{
|
||||
// <NEWLINE>
|
||||
// F<TAB><NEWLINE>
|
||||
// A<3x UP ARROW><TAB>,F<TAB><NEWLINE>
|
||||
// F00<BACKSPACE><BACKSPACE>o<TAB>,A<DOWN ARROW>,<SPACE>SecurityBundle<NEWLINE>
|
||||
// Acme<TAB>,<SPACE>As<TAB><29x BACKSPACE>S<TAB><NEWLINE>
|
||||
// Ac<TAB>,As<TAB><3x BACKSPACE>d<TAB><NEWLINE>
|
||||
$inputStream = $this->getInputStream("\nF\t\nA\033[A\033[A\033[A\t,F\t\nF00\177\177o\t,A\033[B\t, SecurityBundle\nSecurityBundle\nAcme\t, As\t\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177\177S\t\nAc\t,As\t\177\177\177d\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet([new FormatterHelper()]);
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion(
|
||||
'Please select a bundle (defaults to AcmeDemoBundle and AsseticBundle)',
|
||||
['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'],
|
||||
'0,1'
|
||||
);
|
||||
|
||||
// This tests that autocomplete works for all multiselect choices entered by the user
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['AsseticBundle', 'FooBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['FooBundle', 'AsseticBundle', 'SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['SecurityBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+', false);
|
||||
|
||||
Reference in New Issue
Block a user