8000 Merge branch '4.1' into 4.2 · symfony/symfony@b594ad6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b594ad6

Browse files
author
Robin Chalas
committed
Merge branch '4.1' into 4.2
* 4.1: Ensure final input of CommandTester works with default [Intl] handle null date and time types Do not ignore the choice groups for caching
2 parents 4f56732 + 2d84041 commit b594ad6

File tree

6 files changed

+76
-58
lines changed

6 files changed

+76
-58
lines changed

src/Symfony/Component/Console/Tester/TesterTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ private static function createStream(array $inputs)
162162
{
163163
$stream = fopen('php://memory', 'r+', false);
164164

165-
fwrite($stream, implode(PHP_EOL, $inputs));
165+
foreach ($inputs as $input) {
166+
fwrite($stream, $input.PHP_EOL);
167+
}
168+
166169
rewind($stream);
167170

168171
return $stream;

src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ public function testCommandWithInputs()
112112
$this->assertEquals(implode('', $questions), $tester->getDisplay(true));
113113
}
114114

115+
public function testCommandWithDefaultInputs()
116+
{
117+
$questions = array(
118+
'What\'s your name?',
119+
'How are you?',
120+
'Where do you come from?',
121+
);
122+
123+
$command = new Command('foo');
124+
$command->setHelperSet(new HelperSet(array(new QuestionHelper())));
125+
$command->setCode(function ($input, $output) use ($questions, $command) {
126+
$helper = $command->getHelper('question');
127+
$helper->ask($input, $output, new Question($questions[0], 'Bobby'));
128+
$helper->ask($input, $output, new Question($questions[1], 'Fine'));
129+
$helper->ask($input, $output, new Question($questions[2], 'France'));
130+
});
131+
132+
$tester = new CommandTester($command);
133+
$tester->setInputs(array('', '', ''));
134+
$tester->execute(array());
135+
136+
$this->assertEquals(0, $tester->getStatusCode());
137+
$this->assertEquals(implode('', $questions), $tester->getDisplay(true));
138+
}
139+
115140
/**
116141
* @expectedException \RuntimeException
117142
* @expectedMessage Aborted

src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,6 @@ public static function generateHash($value, $namespace = '')
6262
return hash('sha256', $namespace.':'.serialize($value));
6363
}
6464

65-
/**
66-
* Flattens an array into the given output variable.
67-
*
68-
* @param array $array The array to flatten
69-
* @param array $output The flattened output
70-
*
71-
* @internal
72-
*/
73-
private static function flatten(array $array, &$output)
74-
{
75-
if (null === $output) {
76-
$output = array();
77-
}
78-
79-
foreach ($array as $key => $value) {
80-
if (\is_array($value)) {
81-
self::flatten($value, $output);
82-
continue;
83-
}
84-
85-
$output[$key] = $value;
86-
}
87-
}
88-
8965
public function __construct(ChoiceListFactoryInterface $decoratedFactory)
9066
{
9167
$this->decoratedFactory = $decoratedFactory;
@@ -113,12 +89,7 @@ public function createListFromChoices($choices, $value = null)
11389
// The value is not validated on purpose. The decorated factory may
11490
// decide which values to accept and which not.
11591

116-
// We ignore the choice groups for caching. If two choice lists are
117-
// requested with the same choices, but a different grouping, the same
118-
// choice list is returned.
119-
self::flatten($choices, $flatChoices);
120-
121-
$hash = self::generateHash(array($flatChoices, $value), 'fromChoices');
92+
$hash = self::generateHash(array($choices, $value), 'fromChoices');
12293

12394
if (!isset($this->lists[$hash])) {
12495
$this->lists[$hash] = $this->decoratedFactory->createListFromChoices($choices, $value);

src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,24 @@ public function testCreateFromChoicesComparesTraversableChoicesAsArray()
6464
$this->assertSame($list, $this->factory->createListFromChoices($choices2));
6565
}
6666

67-
public function testCreateFromChoicesFlattensChoices()
67+
public function testCreateFromChoicesGroupedChoices()
6868
{
6969
$choices1 = array('key' => array('A' => 'a'));
7070
$choices2 = array('A' => 'a');
71-
$list = new \stdClass();
71+
$list1 = new \stdClass();
72+
$list2 = new \stdClass();
7273

73-
$this->decoratedFactory->expects($this->once())
74+
$this->decoratedFactory->expects($this->at(0))
7475
->method('createListFromChoices')
7576
->with($choices1)
76-
->will($this->returnValue($list));
77+
->will($this->returnValue($list1));
78+
$this->decoratedFactory->expects($this->at(1))
79+
->method('createListFromChoices')
80+
->with($choices2)
81+
->will($this->returnValue($list2));
7782

78-
$this->assertSame($list, $this->factory->createListFromChoices($choices1));
79-
$this->assertSame($list, $this->factory->createListFromChoices($choices2));
83+
$this->assertSame($list1, $this->factory->createListFromChoices($choices1));
84+
$this->assertSame($list2, $this->factory->createListFromChoices($choices2));
8085
}
8186

8287
/**

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ class IntlDateFormatter
118118
private $timeZoneId;
119119

120120
/**
121-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
122-
* @param int $datetype Type of date formatting, one of the format type constants
123-
* @param int $timetype Type of time formatting, one of the format type constants
124-
* @param mixed $timezone Timezone identifier
125-
* @param int $calendar Calendar to use for formatting or parsing. The only currently
126-
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
127-
* @param string $pattern Optional pattern to use when formatting
121+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
122+
* @param int|null $datetype Type of date formatting, one of the format type constants
123+
* @param int|null $timetype Type of time formatting, one of the format type constants
124+
* @param \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier
125+
* @param int $calendar Calendar to use for formatting or parsing. The only currently
126+
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
127+
* @param string|null $pattern Optional pattern to use when formatting
128128
*
129129
* @see http://www.php.net/manual/en/intldateformatter.create.php
130130
* @see http://userguide.icu-project.org/formatparse/datetime
@@ -142,8 +142,8 @@ public function __construct(?string $locale, int $datetype, int $timetype, $time
142142
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
143143
}
144144

145-
$this->datetype = $datetype;
146-
$this->timetype = $timetype;
145+
$this->datetype = null !== $datetype ? $datetype : self::FULL;
146+
$this->timetype = null !== $timetype ? $timetype : self::FULL;
147147

148148
$this->setPattern($pattern);
149149
$this->setTimeZone($timezone);
@@ -152,13 +152,13 @@ public function __construct(?string $locale, int $datetype, int $timetype, $time
152152
/**
153153
* Static constructor.
154154
*
155-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
156-
* @param int $datetype Type of date formatting, one of the format type constants
157-
* @param int $timetype Type of time formatting, one of the format type constants
158-
* @param string $timezone Timezone identifier
159-
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
160-
* One of the calendar constants
161-
* @param string $pattern Optional pattern to use when formatting
155+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
156+
* @param int|null $datetype Type of date formatting, one of the format type constants
157+
* @param int|null $timetype Type of time formatting, one of the format type constants
158+
* @param \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier
159+
* @param int $calendar Calendar to use for formatting or parsing; default is Gregorian
160+
* One of the calendar constants
161+
* @param string|null $pattern Optional pattern to use when formatting
162162
*
163163
* @return self
164164
*
@@ -485,7 +485,7 @@ public function setLenient($lenient)
485485
/**
486486
* Set the formatter's pattern.
487487
*
488-
* @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
488+
* @param string|null $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
489489
*
490490
* @return bool true on success or false on failure
491491
*
@@ -506,9 +506,9 @@ public function setPattern($pattern)
506506
/**
507507
* Set the formatter's timezone identifier.
508508
*
509-
* @param string $timeZoneId The time zone ID string of the time zone to use.
510-
* 7802 If NULL or the empty string, the default time zone for the
511-
* runtime is used.
509+
* @param string|null $timeZoneId The time zone ID string of the time zone to use.
510+
* If NULL or the empty string, the default time zone for the
511+
* runtime is used.
512512
*
513513
* @return bool true on success or false on failure
514514
*
@@ -552,7 +552,7 @@ public function setTimeZoneId($timeZoneId)
552552
/**
553553
* This method was added in PHP 5.5 as replacement for `setTimeZoneId()`.
554554
*
555-
* @param mixed $timeZone
555+
* @param \IntlTimeZone|\DateTimeZone|string|null $timeZone
556556
*
557557
* @return bool true on success or false on failure
558558
*

src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public function testConstructorDefaultTimeZone()
4646
);
4747
}
4848

49+
public function testConstructorWithoutDateType()
50+
{
51+
$formatter = new IntlDateFormatter('en', null, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN);
52+
53+
$this->assertSame('EEEE, LLLL d, y, h:mm a', $formatter->getPattern());
54+
}
55+
56+
public function testConstructorWithoutTimeType()
57+
{
58+
$formatter = new IntlDateFormatter('en', IntlDateFormatter::SHORT, null, 'UTC', IntlDateFormatter::GREGORIAN);
59+
60+
$this->assertSame('M/d/yy, h:mm:ss a zzzz', $formatter->getPattern());
61+
}
62+
4963
/**
5064
* @dataProvider formatProvider
5165
*/

0 commit comments

Comments
 (0)
0