8000 Merge branch '3.4' into 4.1 · ajgarlag/symfony@5bd2403 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bd2403

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Console] fix test using deprecated code [travis] build libsodium only if it's not already enabled Add a test case for stringifying of Process arguments 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 Setting missing default paths under BC layer Changed "epost-adress" to "e-postadress" Fix for race condition in console output stream write reverse transform RFC 3339 formatted dates
2 parents 7e0a369 + 2caee94 commit 5bd2403

File tree

11 files changed

+109
-19
lines changed

11 files changed

+109
-19
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ before_install:
151151
wget http://ftp.debian.org/debian/pool/main/libr/librabbitmq/librabbitmq1_0.5.2-2_amd64.deb
152152
sudo dpkg -i librabbitmq1_0.5.2-2_amd64.deb librabbitmq-dev_0.5.2-2_amd64.deb
153153
154-
# install libsodium
155-
sudo add-apt-repository ppa:ondrej/php -y
156-
sudo apt-get update -q
157-
sudo apt-get install libsodium-dev -y
154+
if ! php --ri sodium > /dev/null; then
155+
# install libsodium
156+
sudo add-apt-repository ppa:ondrej/php -y
157+
sudo apt-get update -q
158+
sudo apt-get install libsodium-dev -y
159+
tfold ext.libsodium tpecl libsodium sodium.so $INI
160+
fi
158161
159162
tfold ext.apcu tpecl apcu-5.1.6 apcu.so $INI
160-
tfold ext.libsodium tpecl libsodium sodium.so $INI
161163
tfold ext.mongodb tpecl mongodb-1.5.0 mongodb.so $INI
162164
tfold ext.amqp tpecl amqp-1.9.3 amqp.so $INI
163165
done

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4747
}
4848

4949
if (!$input->isInteractive()) {
50-
if ($question instanceof ChoiceQuestion) {
50+
$default = $question->getDefault();
51+
52+
if (null !== $default && $question instanceof ChoiceQuestion) {
5153
$choices = $question->getChoices();
5254

53-
return $choices[$question->getDefault()];
55+
if (!$question->isMultiselect()) {
56+
return isset($choices[$default]) ? $choices[$default] : $default;
57+
}
58+
59+
$default = explode(',', $default);
60+
foreach ($default as $k => $v) {
61+
$v = trim($v);
62+
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
63+
}
5464
}
5565

56-
return $question->getDefault();
66+
return $default;
5767
}
5868

5969
if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {

src/Symfony/Component/Console/Input/InputOption.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class InputOption
3333
private $description;
3434

3535
/**
36-
* @param string $name The option name
37-
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38-
* @param int|null $mode The option mode: One of the VALUE_* constants
39-
* @param string $description A description text
40-
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
36+
* @param string $name The option name
37+
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38+
* @param int|null $mode The option mode: One of the VALUE_* constants
39+
* @param string $description A description text
40+
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
4141
*
4242
* @throws InvalidArgumentException If option mode is invalid or incompatible
4343
*/
@@ -149,7 +149,7 @@ public function isArray()
149149
/**
150150
* Sets the default value.
151151
*
152-
* @param string|string[]|bool|null $default The default value
152+
* @param string|string[]|int|bool|null $default The default value
153153
*
154154
* @throws LogicException When incorrect default value is given
155155
*/
@@ -173,7 +173,7 @@ public function setDefault($default = null)
173173
/**
174174
* Returns the default value.
175175
*
176-
* @return string|string[]|bool|null The default value
176+
* @return string|string[]|int|bool|null The default value
177177
*/
178178
public function getDefault()
179179
{

src/Symfony/Component/Console/Output/StreamOutput.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public function getStream()
7070
*/
7171
protected function doWrite($message, $newline)
7272
{
73-
if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) {
73+
if ($newline) {
74+
$message .= PHP_EOL;
75+
}
76+
77+
if (false === @fwrite($this->stream, $message)) {
7478
// should never happen
7579
throw new RuntimeException('Unable to write output.');
7680
}

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,63 @@ public function testAskChoice()
8989
$this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
9090
}
9191

92+
public function testAskChoiceNonInteractive()
93+
{
94+
$questionHelper = new QuestionHelper();
95+
96+
$helperSet = new HelperSet(array(new FormatterHelper()));
97+
$questionHelper->setHelperSet($helperSet);
98+
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");
99+
100+
$heroes = array('Superman', 'Batman', 'Spiderman');
101+
102+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
103+
104+
$this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
105+
106+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
107+
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
108+
109+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
110+
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
111+
112+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
113+
$question->setValidator(null);
114+
$this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
115+
116+
try {
117+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
118+
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
119+
} catch (\InvalidArgumentException $e) {
120+
$this->assertSame('Value "" is invalid', $e->getMessage());
121+
}
122+
123+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
124+
$question->setMultiselect(true);
125+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
126+
127+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
128+
$question->setMultiselect(true);
129+
$question->setValidator(null);
130+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
131+
132+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, Batman');
133+
$question->setMultiselect(true);
134+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
135+
136+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, null);
137+
$question->setMultiselect(true);
138+
$this->assertNull($questionH 10000 elper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
139+
140+
try {
141+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
142+
$question->setMultiselect(true);
143+
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
144+
} catch (\InvalidArgumentException $e) {
145+
$this->assertSame('Value "" is invalid', $e->getMessage());
146+
}
147+
}
148+
92149
public function testAsk()
93150
{
94151
$dialog = new QuestionHelper();

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public function reverseTransform($dateTimeLocal)
8181
return;
8282
}
8383

84-
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
84+
// to maintain backwards compatibility we do not strictly validate the submitted date
85+
// see https://github.com/symfony/symfony/issues/28699
86+
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?/', $dateTimeLocal, $matches)) {
8587
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
8688
}
8789

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function reverseTransformProvider()
5151
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05'),
5252
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05'),
5353
array('Europe/Amsterdam', 'Europe/Amsterdam', '2013-08-21 10:30:00 Europe/Amsterdam', '2013-08-21T10:30:00'),
54+
array('UTC', 'UTC', '2018-09-15T10:00:00Z', '2018-09-15T10:00:00Z'),
55+
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+02:00', '2018-09-15T10:00:00+02:00'),
56+
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+0200', '2018-09-15T10:00:00+0200'),
57+
array('UTC', 'UTC', '2018-10-03T10:00:00.000Z', '2018-10-03T10:00:00.000Z'),
5458
);
5559
}
5660

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ public function testEscapeArgument($arg)
14361436
$p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg));
14371437
$p->run();
14381438

1439-
$this->assertSame($arg, $p->getOutput());
1439+
$this->assertSame((string) $arg, $p->getOutput());
14401440
}
14411441

14421442
public function testRawCommandLine()
@@ -1466,6 +1466,9 @@ public function provideEscapeArgument()
14661466
yield array("a!b\tc");
14671467
yield array('a\\\\"\\"');
14681468
yield array('éÉèÈàÀöä');
1469+
yield array(null);
1470+
yield array(1);
1471+
yield array(1.1);
14691472
}
14701473

14711474
public function testEnvArgument()

src/Symfony/Component/Validator/Resources/translations/validators.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@
322322
<source>This is not a valid UUID.</source>
323323
<target>This is not a valid UUID.</target>
324324
</trans-unit>
325+
<trans-unit id="84">
326+
<source>This value should be a multiple of {{ compared_value }}.</source>
327+
<target>This value should be a multiple of {{ compared_value }}.</target>
328+
</trans-unit>
325329
</body>
326330
</file>
327331
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@
322322
<source>This is not a valid UUID.</source>
323323
<target>To nie jest poprawne UUID.</target>
324324
</trans-unit>
325+
<trans-unit id="84">
326+
<source>This value should be a multiple of {{ compared_value }}.</source>
327+
<target>Ta wartość powinna być wielokrotnością {{ compared_value }}.</target>
328+
</trans-unit>
325329
</body>
326330
</file>
327331
</xliff>

0 commit comments

Comments
 (0)
0