Merge branch '2.8' into 3.4
* 2.8: Add a missing English translation [Console] Fixes multiselect choice question in interactive mode with default values [Validator] Add a missing Polish translation Allow integers as default console option value Changed "epost-adress" to "e-postadress" Fix for race condition in console output stream write reverse transform RFC 3339 formatted dates
This commit is contained in:
commit
a5792bfe01
@ -47,13 +47,23 @@ class QuestionHelper extends Helper
|
||||
}
|
||||
|
||||
if (!$input->isInteractive()) {
|
||||
if ($question instanceof ChoiceQuestion) {
|
||||
$default = $question->getDefault();
|
||||
|
||||
if (null !== $default && $question instanceof ChoiceQuestion) {
|
||||
$choices = $question->getChoices();
|
||||
|
||||
return $choices[$question->getDefault()];
|
||||
if (!$question->isMultiselect()) {
|
||||
return isset($choices[$default]) ? $choices[$default] : $default;
|
||||
}
|
||||
|
||||
$default = explode(',', $default);
|
||||
foreach ($default as $k => $v) {
|
||||
$v = trim($v);
|
||||
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $question->getDefault();
|
||||
return $default;
|
||||
}
|
||||
|
||||
if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
|
||||
|
@ -33,11 +33,11 @@ class InputOption
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @param string $name The option name
|
||||
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param int|null $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
|
||||
* @param string $name The option name
|
||||
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param int|null $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
|
||||
*
|
||||
* @throws InvalidArgumentException If option mode is invalid or incompatible
|
||||
*/
|
||||
@ -149,7 +149,7 @@ class InputOption
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param string|string[]|bool|null $default The default value
|
||||
* @param string|string[]|int|bool|null $default The default value
|
||||
*
|
||||
* @throws LogicException When incorrect default value is given
|
||||
*/
|
||||
@ -173,7 +173,7 @@ class InputOption
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return string|string[]|bool|null The default value
|
||||
* @return string|string[]|int|bool|null The default value
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
|
@ -70,7 +70,11 @@ class StreamOutput extends Output
|
||||
*/
|
||||
protected function doWrite($message, $newline)
|
||||
{
|
||||
if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) {
|
||||
if ($newline) {
|
||||
$message .= PHP_EOL;
|
||||
}
|
||||
|
||||
if (false === @fwrite($this->stream, $message)) {
|
||||
// should never happen
|
||||
throw new RuntimeException('Unable to write output.');
|
||||
}
|
||||
|
@ -89,6 +89,63 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testAskChoiceNonInteractive()
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$questionHelper->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
|
||||
|
||||
$this->assertSame('Superman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
|
||||
$this->assertSame('Batman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$this->assertNull($questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
|
||||
$question->setValidator(null);
|
||||
$this->assertSame('Superman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertSame('Value "" is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
|
||||
$question->setMultiselect(true);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
|
||||
$question->setMultiselect(true);
|
||||
$question->setValidator(null);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, Batman');
|
||||
$question->setMultiselect(true);
|
||||
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, null);
|
||||
$question->setMultiselect(true);
|
||||
$this->assertNull($questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
|
||||
$question->setMultiselect(true);
|
||||
$questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertSame('Value "" is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testAsk()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
@ -81,7 +81,9 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
|
||||
// to maintain backwards compatibility we do not strictly validate the submitted date
|
||||
// see https://github.com/symfony/symfony/issues/28699
|
||||
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?/', $dateTimeLocal, $matches)) {
|
||||
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,10 @@ class DateTimeToHtml5LocalDateTimeTransformerTest extends TestCase
|
||||
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05'),
|
||||
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05'),
|
||||
array('Europe/Amsterdam', 'Europe/Amsterdam', '2013-08-21 10:30:00 Europe/Amsterdam', '2013-08-21T10:30:00'),
|
||||
array('UTC', 'UTC', '2018-09-15T10:00:00Z', '2018-09-15T10:00:00Z'),
|
||||
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+02:00', '2018-09-15T10:00:00+02:00'),
|
||||
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+0200', '2018-09-15T10:00:00+0200'),
|
||||
array('UTC', 'UTC', '2018-10-03T10:00:00.000Z', '2018-10-03T10:00:00.000Z'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -322,6 +322,10 @@
|
||||
<source>This is not a valid UUID.</source>
|
||||
<target>This is not a valid UUID.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="84">
|
||||
<source>This value should be a multiple of {{ compared_value }}.</source>
|
||||
<target>This value should be a multiple of {{ compared_value }}.</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
@ -322,6 +322,10 @@
|
||||
<source>This is not a valid UUID.</source>
|
||||
<target>To nie jest poprawne UUID.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="84">
|
||||
<source>This value should be a multiple of {{ compared_value }}.</source>
|
||||
<target>Ta wartość powinna być wielokrotnością {{ compared_value }}.</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
@ -52,7 +52,7 @@
|
||||
</trans-unit>
|
||||
<trans-unit id="13">
|
||||
<source>This value is not a valid email address.</source>
|
||||
<target>Värdet är inte en giltig epost-adress.</target>
|
||||
<target>Värdet är inte en giltig e-postadress.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="14">
|
||||
<source>The file could not be found.</source>
|
||||
|
Reference in New Issue
Block a user