Skip to content

Commit fdabbaa

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Form] [ChoiceType] Prefer placeholder to empty_value Add missing RFC comment ensure dump indentation to be greather than zero
2 parents 96aaf4f + 54bca3f commit fdabbaa

File tree

7 files changed

+179
-5
lines changed

7 files changed

+179
-5
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ public function configureOptions(OptionsResolver $resolver)
353353
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
354354
@trigger_error(sprintf('The form option "empty_value" of the "%s" form type (%s) is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', $that->getName(), __CLASS__), E_USER_DEPRECATED);
355355

356-
$placeholder = $options['empty_value'];
356+
if (null === $placeholder || '' === $placeholder) {
357+
$placeholder = $options['empty_value'];
358+
}
357359
}
358360

359361
if ($options['multiple']) {

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ public function testPassPlaceholderToView($multiple, $expanded, $required, $plac
18191819
));
18201820
$view = $form->createView();
18211821

1822-
$this->assertEquals($viewValue, $view->vars['placeholder']);
1822+
$this->assertSame($viewValue, $view->vars['placeholder']);
18231823
$this->assertFalse($view->vars['placeholder_in_choices']);
18241824
}
18251825

@@ -1839,9 +1839,9 @@ public function testPassEmptyValueBC($multiple, $expanded, $required, $placehold
18391839
));
18401840
$view = $form->createView();
18411841

1842-
$this->assertEquals($viewValue, $view->vars['placeholder']);
1842+
$this->assertSame($viewValue, $view->vars['placeholder']);
18431843
$this->assertFalse($view->vars['placeholder_in_choices']);
1844-
$this->assertEquals($viewValue, $view->vars['empty_value']);
1844+
$this->assertSame($viewValue, $view->vars['empty_value']);
18451845
$this->assertFalse($view->vars['empty_value_in_choices']);
18461846
}
18471847

@@ -1908,6 +1908,134 @@ public function getOptionsWithPlaceholder()
19081908
);
19091909
}
19101910

1911+
/**
1912+
* @dataProvider getOptionsWithPlaceholderAndEmptyValue
1913+
* @group legacy
1914+
*/
1915+
public function testPlaceholderOptionWithEmptyValueOption($multiple, $expanded, $required, $placeholder, $emptyValue, $viewValue)
1916+
{
1917+
$form = $this->factory->create('choice', null, array(
1918+
'multiple' => $multiple,
1919+
'expanded' => $expanded,
1920+
'required' => $required,
1921+
'placeholder' => $placeholder,
1922+
'empty_value' => $emptyValue,
1923+
'choices' => $this->choices,
1924+
));
1925+
$view = $form->createView();
1926+
1927+
$this->assertSame($viewValue, $view->vars['placeholder']);
1928+
$this->assertFalse($view->vars['placeholder_in_choices']);
1929+
}
1930+
1931+
public function getOptionsWithPlaceholderAndEmptyValue()
1932+
{
1933+
return array(
1934+
// single non-expanded, not required
1935+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, false, null),
1936+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, null, null),
1937+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, '', null),
1938+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, 'bar', null),
1939+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, false, null, false, null),
1940+
'An unset empty_value is automaticaly made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, false, false, null, null, ''),
1941+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, '', ''),
1942+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, 'bar', 'bar'),
1943+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, false, false, '', false, null),
1944+
'An unset empty_value is automatically made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, false, false, '', null, null),
1945+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, false, '', '', ''),
1946+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, false, '', 'bar', 'bar'),
1947+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, false, 'foo', false, 'foo'),
1948+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, false, 'foo', null, 'foo'),
1949+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, false, 'foo', '', 'foo'),
1950+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, false, 'foo', 'bar', 'foo'),
1951+
// single non-expanded, required
1952+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, false, null),
1953+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, null, null),
1954+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, '', null),
1955+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, 'bar', null),
1956+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, true, null, false, null),
1957+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, null, null, null),
1958+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, '', ''),
1959+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, 'bar', 'bar'),
1960+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, false, true, '', false, null),
1961+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, '', null, null),
1962+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, true, '', '', ''),
1963+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, true, '', 'bar', 'bar'),
1964+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, true, 'foo', false, 'foo'),
1965+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, true, 'foo', null, 'foo'),
1966+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, true, 'foo', '', 'foo'),
1967+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, true, 'foo', 'bar', 'foo'),
1968+
// single expanded, not required
1969+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, false, null),
1970+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, null, null),
1971+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, '', null),
1972+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, 'bar', null),
1973+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, false, null, false, null),
1974+
'An unset empty_value is automaticaly made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, true, false, null, null, null),
1975+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, null, '', 'None'),
1976+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, false, null, 'bar', 'bar'),
1977+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, true, false, '', false, null),
1978+
'An unset empty_value is automatically made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, true, false, '', null, null),
1979+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, '', '', 'None'),
1980+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, false, '', 'bar', 'bar'),
1981+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, false, 'foo', false, 'foo'),
1982+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, false, 'foo', null, 'foo'),
1983+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, false, 'foo', '', 'foo'),
1984+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, false, 'foo', 'bar', 'foo'),
1985+
// single expanded, required
1986+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, false, null),
1987+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, null, null),
1988+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, '', null),
1989+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, 'bar', null),
1990+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, true, null, false, null),
1991+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, null, null, null),
1992+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, null, '', 'None'),
1993+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, true, null, 'bar', 'bar'),
1994+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, true, true, '', false, null),
1995+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, '', null, null),
1996+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, '', '', 'None'),
1997+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, true, '', 'bar', 'bar'),
1998+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, true, 'foo', false, 'foo'),
1999+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, true, 'foo', null, 'foo'),
2000+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, true, 'foo', '', 'foo'),
2001+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, true, 'foo', 'bar', 'foo'),
2002+
// multiple expanded, not required
2003+
array(true, true, false, false, false, null),
2004+
array(true, true, false, false, null, null),
2005+
array(true, true, false, false, '', null),
2006+
array(true, true, false, false, 'bar', null),
2007+
array(true, true, false, null, false, null),
2008+
array(true, true, false, null, null, null),
2009+
array(true, true, false, null, '', null),
2010+
array(true, true, false, null, 'bar', null),
2011+
array(true, true, false, '', false, null),
2012+
array(true, true, false, '', null, null),
2013+
array(true, true, false, '', '', null),
2014+
array(true, true, false, '', 'bar', null),
2015+
array(true, true, false, 'foo', false, null),
2016+
array(true, true, false, 'foo', null, null),
2017+
array(true, true, false, 'foo', '', null),
2018+
array(true, true, false, 'foo', 'bar', null),
2019+
// multiple expanded, required
2020+
array(true, true, true, false, false, null),
2021+
array(true, true, true, false, null, null),
2022+
array(true, true, true, false, '', null),
2023+
array(true, true, true, false, 'bar', null),
2024+
array(true, true, true, null, false, null),
2025+
array(true, true, true, null, null, null),
2026+
array(true, true, true, null, '', null),
2027+
array(true, true, true, null, 'bar', null),
2028+
array(true, true, true, '', false, null),
2029+
array(true, true, true, '', null, null),
2030+
array(true, true, true, '', '', null),
2031+
array(true, true, true, '', 'bar', null),
2032+
array(true, true, true, 'foo', false, null),
2033+
array(true, true, true, 'foo', null, null),
2034+
array(true, true, true, 'foo', '', null),
2035+
array(true, true, true, 'foo', 'bar', null),
2036+
);
2037+
}
2038+
19112039
public function testPassChoicesToView()
19122040
{
19132041
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Response
170170
428 => 'Precondition Required', // RFC6585
171171
429 => 'Too Many Requests', // RFC6585
172172
431 => 'Request Header Fields Too Large', // RFC6585
173-
451 => 'Unavailable For Legal Reasons',
173+
451 => 'Unavailable For Legal Reasons', // RFC7725
174174
500 => 'Internal Server Error',
175175
501 => 'Not Implemented',
176176
502 => 'Bad Gateway',

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class Dumper
3232
*/
3333
public function setIndentation($num)
3434
{
35+
if ($num < 1) {
36+
throw new \InvalidArgumentException('The indentation must be greater than zero.');
37+
}
38+
3539
$this->indentation = (int) $num;
3640
}
3741

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ public function getEscapeSequences()
228228
'paragraph-separator' => array("\t\\P", '"\t\\\\P"'),
229229
);
230230
}
231+
232+
/**
233+
* @expectedException \InvalidArgumentException
234+
* @expectedExceptionMessage The indentation must be greater than zero
235+
*/
236+
public function testZeroIndentationThrowsException()
237+
{
238+
$this->dumper->setIndentation(0);
239+
}
240+
241+
/**
242+
* @expectedException \InvalidArgumentException
243+
* @expectedExceptionMessage The indentation must be greater than zero
244+
*/
245+
public function testNegativeIndentationThrowsException()
246+
{
247+
$this->dumper->setIndentation(-4);
248+
}
231249
}
232250

233251
class A

src/Symfony/Component/Yaml/Tests/YamlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,22 @@ public function testLegacyParseFromFile()
3434
$parsedByContents = Yaml::parse($contents);
3535
$this->assertEquals($parsedByFilename, $parsedByContents);
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The indentation must be greater than zero
41+
*/
42+
public function testZeroIndentationThrowsException()
43+
{
44+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0);
45+
}
46+
47+
/**
48+
* @expectedException \InvalidArgumentException
49+
* @expectedExceptionMessage The indentation must be greater than zero
50+
*/
51+
public function testNegativeIndentationThrowsException()
52+
{
53+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4);
54+
}
3755
}

src/Symfony/Component/Yaml/Yaml.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public static function parse($input, $exceptionOnInvalidType = false, $objectSup
8888
*/
8989
public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
9090
{
91+
if ($indent < 1) {
92+
throw new \InvalidArgumentException('The indentation must be greater than zero.');
93+
}
94+
9195
$yaml = new Dumper();
9296
$yaml->setIndentation($indent);
9397

0 commit comments

Comments
 (0)