Skip to content

Commit 2d61fed

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [Form] [ChoiceType] Prefer placeholder to empty_value Add missing RFC comment ensure dump indentation to be greather than zero
2 parents b5ba64c + f5c746c commit 2d61fed

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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

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

Tests/YamlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,22 @@ public function testParseAndDump()
2222
$parsed = Yaml::parse($yml);
2323
$this->assertEquals($data, $parsed);
2424
}
25+
26+
/**
27+
* @expectedException \InvalidArgumentException
28+
* @expectedExceptionMessage The indentation must be greater than zero
29+
*/
30+
public function testZeroIndentationThrowsException()
31+
{
32+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0);
33+
}
34+
35+
/**
36+
* @expectedException \InvalidArgumentException
37+
* @expectedExceptionMessage The indentation must be greater than zero
38+
*/
39+
public function testNegativeIndentationThrowsException()
40+
{
41+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4);
42+
}
2543
}

Yaml.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public static function parse($input, $exceptionOnInvalidType = false, $objectSup
6161
*/
6262
public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
6363
{
64+
if ($indent < 1) {
65+
throw new \InvalidArgumentException('The indentation must be greater than zero.');
66+
}
67+
6468
$yaml = new Dumper();
6569
$yaml->setIndentation($indent);
6670

0 commit comments

Comments
 (0)