composer update

This commit is contained in:
2019-06-23 10:14:30 +00:00
parent a56db5ea2b
commit ec4506ebf4
790 changed files with 35767 additions and 7663 deletions

View File

@@ -73,8 +73,8 @@ class ApplicationTest extends TestCase
require_once self::$fixturesPath.'/FooSubnamespaced1Command.php';
require_once self::$fixturesPath.'/FooSubnamespaced2Command.php';
require_once self::$fixturesPath.'/FooWithoutAliasCommand.php';
require_once self::$fixturesPath.'/TestTiti.php';
require_once self::$fixturesPath.'/TestToto.php';
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering.php';
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering2.php';
}
protected function normalizeLineBreaks($text)
@@ -165,6 +165,28 @@ class ApplicationTest extends TestCase
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
}
public function testRegisterAmbiguous()
{
$code = function (InputInterface $input, OutputInterface $output) {
$output->writeln('It works!');
};
$application = new Application();
$application->setAutoExit(false);
$application
->register('test-foo')
->setAliases(['test'])
->setCode($code);
$application
->register('test-bar')
->setCode($code);
$tester = new ApplicationTester($application);
$tester->run(['test']);
$this->assertContains('It works!', $tester->getDisplay(true));
}
public function testAdd()
{
$application = new Application();
@@ -304,9 +326,9 @@ class ApplicationTest extends TestCase
public function testFindNonAmbiguous()
{
$application = new Application();
$application->add(new \TestTiti());
$application->add(new \TestToto());
$this->assertEquals('test-toto', $application->find('test')->getName());
$application->add(new \TestAmbiguousCommandRegistering());
$application->add(new \TestAmbiguousCommandRegistering2());
$this->assertEquals('test-ambiguous', $application->find('test')->getName());
}
/**

View File

@@ -188,7 +188,7 @@ class CommandTest extends TestCase
public function testSetAliasesNull()
{
$command = new \TestCommand();
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$command->setAliases(null);
}

View File

@@ -4,19 +4,19 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TestToto extends Command
class TestAmbiguousCommandRegistering extends Command
{
protected function configure()
{
$this
->setName('test-toto')
->setDescription('The test-toto command')
->setName('test-ambiguous')
->setDescription('The test-ambiguous command')
->setAliases(['test'])
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-toto');
$output->write('test-ambiguous');
}
}

View File

@@ -4,18 +4,18 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TestTiti extends Command
class TestAmbiguousCommandRegistering2 extends Command
{
protected function configure()
{
$this
->setName('test-titi')
->setDescription('The test:titi command')
->setName('test-ambiguous2')
->setDescription('The test-ambiguous2 command')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-titi');
$output->write('test-ambiguous2');
}
}

View File

@@ -41,7 +41,7 @@ class OutputFormatterStyleTest extends TestCase
$style->setForeground('default');
$this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$style->setForeground('undefined-color');
}
@@ -58,7 +58,7 @@ class OutputFormatterStyleTest extends TestCase
$style->setBackground('default');
$this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$style->setBackground('undefined-color');
}
@@ -97,4 +97,19 @@ class OutputFormatterStyleTest extends TestCase
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
}
}
public function testHref()
{
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
putenv('TERMINAL_EMULATOR');
$style = new OutputFormatterStyle();
try {
$style->setHref('idea://open/?file=/path/SomeFile.php&line=12');
$this->assertSame("\e]8;;idea://open/?file=/path/SomeFile.php&line=12\e\\some URL\e]8;;\e\\", $style->apply('some URL'));
} finally {
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
}
}
}

View File

@@ -228,7 +228,7 @@ class OutputFormatterTest extends TestCase
);
}
public function testNotDecoratedFormatter()
public function testFormatterHasStyles()
{
$formatter = new OutputFormatter(false);
@@ -236,40 +236,35 @@ class OutputFormatterTest extends TestCase
$this->assertTrue($formatter->hasStyle('info'));
$this->assertTrue($formatter->hasStyle('comment'));
$this->assertTrue($formatter->hasStyle('question'));
}
$this->assertEquals(
'some error', $formatter->format('<error>some error</error>')
);
$this->assertEquals(
'some info', $formatter->format('<info>some info</info>')
);
$this->assertEquals(
'some comment', $formatter->format('<comment>some comment</comment>')
);
$this->assertEquals(
'some question', $formatter->format('<question>some question</question>')
);
$this->assertEquals(
'some text with inline style', $formatter->format('<fg=red>some text with inline style</>')
);
/**
* @dataProvider provideDecoratedAndNonDecoratedOutput
*/
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
{
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
putenv('TERMINAL_EMULATOR='.$terminalEmulator);
$formatter->setDecorated(true);
try {
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
} finally {
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
}
}
$this->assertEquals(
"\033[37;41msome error\033[39;49m", $formatter->format('<error>some error</error>')
);
$this->assertEquals(
"\033[32msome info\033[39m", $formatter->format('<info>some info</info>')
);
$this->assertEquals(
"\033[33msome comment\033[39m", $formatter->format('<comment>some comment</comment>')
);
$this->assertEquals(
"\033[30;46msome question\033[39;49m", $formatter->format('<question>some question</question>')
);
$this->assertEquals(
"\033[31msome text with inline style\033[39m", $formatter->format('<fg=red>some text with inline style</>')
);
public function provideDecoratedAndNonDecoratedOutput()
{
return [
['<error>some error</error>', 'some error', "\033[37;41msome error\033[39;49m"],
['<info>some info</info>', 'some info', "\033[32msome info\033[39m"],
['<comment>some comment</comment>', 'some comment', "\033[33msome comment\033[39m"],
['<question>some question</question>', 'some question', "\033[30;46msome question\033[39;49m"],
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
];
}
public function testContentWithLineBreaks()

View File

@@ -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)"],
];
}
}

View File

@@ -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()],
];
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -0,0 +1,304 @@
<?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\Question;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Question\Question;
class QuestionTest extends TestCase
{
private $question;
protected function setUp()
{
parent::setUp();
$this->question = new Question('Test question');
}
public function providerTrueFalse()
{
return [[true], [false]];
}
public function testGetQuestion()
{
self::assertSame('Test question', $this->question->getQuestion());
}
public function testGetDefault()
{
$question = new Question('Test question', 'Default value');
self::assertSame('Default value', $question->getDefault());
}
public function testGetDefaultDefault()
{
self::assertNull($this->question->getDefault());
}
/**
* @dataProvider providerTrueFalse
*/
public function testIsSetHidden(bool $hidden)
{
$this->question->setHidden($hidden);
self::assertSame($hidden, $this->question->isHidden());
}
public function testIsHiddenDefault()
{
self::assertFalse($this->question->isHidden());
}
public function testSetHiddenWithAutocompleterCallback()
{
$this->question->setAutocompleterCallback(
function (string $input): array { return []; }
);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage(
'A hidden question cannot use the autocompleter.'
);
$this->question->setHidden(true);
}
public function testSetHiddenWithNoAutocompleterCallback()
{
$this->question->setAutocompleterCallback(
function (string $input): array { return []; }
);
$this->question->setAutocompleterCallback(null);
$exception = null;
try {
$this->question->setHidden(true);
} catch (\Exception $exception) {
// Do nothing
}
$this->assertNull($exception);
}
/**
* @dataProvider providerTrueFalse
*/
public function testIsSetHiddenFallback(bool $hidden)
{
$this->question->setHiddenFallback($hidden);
self::assertSame($hidden, $this->question->isHiddenFallback());
}
public function testIsHiddenFallbackDefault()
{
self::assertTrue($this->question->isHiddenFallback());
}
public function providerGetSetAutocompleterValues()
{
return [
'array' => [
['a', 'b', 'c', 'd'],
['a', 'b', 'c', 'd'],
],
'associative array' => [
['a' => 'c', 'b' => 'd'],
['a', 'b', 'c', 'd'],
],
'iterator' => [
new \ArrayIterator(['a', 'b', 'c', 'd']),
['a', 'b', 'c', 'd'],
],
'null' => [null, null],
];
}
/**
* @dataProvider providerGetSetAutocompleterValues
*/
public function testGetSetAutocompleterValues($values, $expectValues)
{
$this->question->setAutocompleterValues($values);
self::assertSame(
$expectValues,
$this->question->getAutocompleterValues()
);
}
public function providerSetAutocompleterValuesInvalid()
{
return [
['Potato'],
[new \stdclass()],
[false],
];
}
/**
* @dataProvider providerSetAutocompleterValuesInvalid
*/
public function testSetAutocompleterValuesInvalid($values)
{
self::expectException(InvalidArgumentException::class);
self::expectExceptionMessage(
'Autocompleter values can be either an array, "null" or a "Traversable" object.'
);
$this->question->setAutocompleterValues($values);
}
public function testSetAutocompleterValuesWithTraversable()
{
$question1 = new Question('Test question 1');
$iterator1 = $this->getMockForAbstractClass(\IteratorAggregate::class);
$iterator1
->expects($this->once())
->method('getIterator')
->willReturn(new \ArrayIterator(['Potato']));
$question1->setAutocompleterValues($iterator1);
$question2 = new Question('Test question 2');
$iterator2 = $this->getMockForAbstractClass(\IteratorAggregate::class);
$iterator2
->expects($this->once())
->method('getIterator')
->willReturn(new \ArrayIterator(['Carrot']));
$question2->setAutocompleterValues($iterator2);
// Call multiple times to verify that Traversable result is cached, and
// that there is no crosstalk between cached copies.
self::assertSame(['Potato'], $question1->getAutocompleterValues());
self::assertSame(['Carrot'], $question2->getAutocompleterValues());
self::assertSame(['Potato'], $question1->getAutocompleterValues());
self::assertSame(['Carrot'], $question2->getAutocompleterValues());
}
public function testGetAutocompleterValuesDefault()
{
self::assertNull($this->question->getAutocompleterValues());
}
public function testGetSetAutocompleterCallback()
{
$callback = function (string $input): array { return []; };
$this->question->setAutocompleterCallback($callback);
self::assertSame($callback, $this->question->getAutocompleterCallback());
}
public function testGetAutocompleterCallbackDefault()
{
self::assertNull($this->question->getAutocompleterCallback());
}
public function testSetAutocompleterCallbackWhenHidden()
{
$this->question->setHidden(true);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage(
'A hidden question cannot use the autocompleter.'
);
$this->question->setAutocompleterCallback(
function (string $input): array { return []; }
);
}
public function testSetAutocompleterCallbackWhenNotHidden()
{
$this->question->setHidden(true);
$this->question->setHidden(false);
$exception = null;
try {
$this->question->setAutocompleterCallback(
function (string $input): array { return []; }
);
} catch (\Exception $exception) {
// Do nothing
}
$this->assertNull($exception);
}
public function providerGetSetValidator()
{
return [
[function ($input) { return $input; }],
[null],
];
}
/**
* @dataProvider providerGetSetValidator
*/
public function testGetSetValidator($callback)
{
$this->question->setValidator($callback);
self::assertSame($callback, $this->question->getValidator());
}
public function testGetValidatorDefault()
{
self::assertNull($this->question->getValidator());
}
public function providerGetSetMaxAttempts()
{
return [[1], [5], [null]];
}
/**
* @dataProvider providerGetSetMaxAttempts
*/
public function testGetSetMaxAttempts($attempts)
{
$this->question->setMaxAttempts($attempts);
self::assertSame($attempts, $this->question->getMaxAttempts());
}
public function providerSetMaxAttemptsInvalid()
{
return [['Potato'], [0], [-1]];
}
/**
* @dataProvider providerSetMaxAttemptsInvalid
*/
public function testSetMaxAttemptsInvalid($attempts)
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('Maximum number of attempts must be a positive value.');
$this->question->setMaxAttempts($attempts);
}
public function testGetMaxAttemptsDefault()
{
self::assertNull($this->question->getMaxAttempts());
}
public function testGetSetNormalizer()
{
$normalizer = function ($input) { return $input; };
$this->question->setNormalizer($normalizer);
self::assertSame($normalizer, $this->question->getNormalizer());
}
public function testGetNormalizerDefault()
{
self::assertNull($this->question->getNormalizer());
}
}