8000 merged branch eddiejaoude/master (PR #7144) · symfony/symfony@48856b1 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 48856b1

Browse files
committed
merged branch eddiejaoude/master (PR #7144)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #7144). Commits ------- 448983c [YAML] Added unit tests to Dumper Discussion ---------- [YAML] Added unit tests to Dumper | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | [] | License | MIT | Doc PR | no --------------------------------------------------------------------------- by stof at 2013-02-21T11:28:55Z I don't like the fact that you are adding a getter for the only purpose of reaching 100% coverage (which could be achieved differently by checking that the dumper can indeed use 8 spaces when dumping) --------------------------------------------------------------------------- by eddiejaoude at 2013-02-21T11:33:03Z Ok, fair point, I will amend. --------------------------------------------------------------------------- by eddiejaoude at 2013-02-21T11:35:14Z I also thought of using reflection for the private property, as checking 8 space dump is less of a unit test as using multiple methods, thoughts? --------------------------------------------------------------------------- by eddiejaoude at 2013-02-21T13:42:30Z Another way to look at it, is if the property has a 'setter' why should it not have a 'getter' too? i.e. If the developer can 'set' it, why cant they 'get' it too. Just another thought, once the best way to move forward is confirmed, I will update my other tests accordingly & submit them. --------------------------------------------------------------------------- by Baachi at 2013-02-21T13:49:25Z Another solution would be, to extend the `Dumper` class and move the `getIndentation` to this class. This class should be located into the `tests/` folder. @stof What do you think? --------------------------------------------------------------------------- by stof at 2013-02-21T14:21:54Z @Baachi IMO, the unit test should ensure that we can actually change the indentation of the dumped code (which is what we want to do). We don't bother about being able to get the indentation (we don't even have a method for it currently), we want it to be applied. The Dumper is not a configuration object. It is an object doing some work. So testing that a new getter returns the value will not ensure that changing the indentation is working. --------------------------------------------------------------------------- by Baachi at 2013-02-21T15:07:23Z @stof Ah yes, I understand you. So my solution is wrong, @eddiejaoude should call `setIndentation` and check the dumped yaml` if the string has the right indentation. --------------------------------------------------------------------------- by eddiejaoude at 2013-02-22T07:35:08Z Ok, thanks for the clarification guys. I will get on the case shortly!
2 parents 19955c5 + 992a440 commit 48856b1

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

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

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ class DumperTest extends \PHPUnit_Framework_TestCase
2121
protected $dumper;
2222
protected $path;
2323

24+
protected $array = array(
25+
'' => 'bar',
26+
'foo' => '#bar',
27+
'foo\'bar' => array(),
28+
'bar' => array(1, 'foo'),
29+
'foobar' => array(
30+
'foo' => 'bar',
31+
'bar' => array(1, 'foo'),
32+
'foobar' => array(
33+
'foo' => 'bar',
34+
'bar' => array(1, 'foo'),
35+
),
36+
),
37+
);
38+
2439
protected function setUp()
2540
{
2641
$this->parser = new Parser();
@@ -33,6 +48,33 @@ protected function tearDown()
3348
$this->parser = null;
3449
$this->dumper = null;
3550
$this->path = null;
51+
$this->array = null;
52+
}
53+
54+
public function testSetIndentation()
55+
{
56+
$this->dumper->setIndentation(7);
57+
58+
$expected = <<<EOF
59+
'': bar
60+
foo: '#bar'
61+
'foo''bar': { }
62+
bar:
63+
- 1
64+
- foo
65+
foobar:
66+
foo: bar
67+
bar:
68+
- 1
69+
- foo
70+
foobar:
71+
foo: bar
72+
bar:
73+
- 1
74+
- foo
75+
76+
EOF;
77+
$this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
3678
}
3779

3880
public function testSpecifications()
@@ -63,27 +105,11 @@ public function testSpecifications()
63105

64106
public function testInlineLevel()
65107
{
66-
// inline level
67-
$array = array(
68-
'' => 'bar',
69-
'foo' => '#bar',
70-
'foo\'bar' => array(),
71-
'bar' => array(1, 'foo'),
72-
'foobar' => array(
73-
'foo' => 'bar',
74-
'bar' => array(1, 'foo'),
75-
'foobar' => array(
76-
'foo' => 'bar',
77-
'bar' => array(1, 'foo'),
78-
),
79-
),
80-
);
81-
82108
$expected = <<<EOF
83109
{ '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
84110
EOF;
85-
$this->assertEquals($expected, $this->dumper->dump($array, -10), '->dump() takes an inline level argument');
86-
$this->assertEquals($expected, $this->dumper->dump($array, 0), '->dump() takes an inline level argument');
111+
$this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument');
112+
$this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument');
87113

88114
$expected = <<<EOF
89115
'': bar
@@ -93,7 +119,7 @@ public function testInlineLevel()
93119
foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
94120
95121
EOF;
96-
$this->assertEquals($expected, $this->dumper->dump($array, 1), '->dump() takes an inline level argument');
122+
$this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument');
97123

98124
$expected = <<<EOF
99125
'': bar
@@ -108,7 +134,7 @@ public function testInlineLevel()
108134
foobar: { foo: bar, bar: [1, foo] }
109135
110136
EOF;
111-
$this->assertEquals($expected, $this->dumper->dump($array, 2), '->dump() takes an inline level argument');
137+
$this->assertEquals($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument');
112138

113139
$expected = <<<EOF
114140
'': bar
@@ -127,7 +153,7 @@ public function testInlineLevel()
127153
bar: [1, foo]
128154
129155
EOF;
130-
$this->assertEquals($expected, $this->dumper->dump($array, 3), '->dump() takes an inline level argument');
156+
$this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument');
131157

132158
$expected = <<<EOF
133159
'': bar
@@ -148,8 +174,8 @@ public function testInlineLevel()
148174
- foo
149175
150176
EOF;
151-
$this->assertEquals($expected, $this->dumper->dump($array, 4), '->dump() takes an inline level argument');
152-
$this->assertEquals($expected, $this->dumper->dump($array, 10), '->dump() takes an inline level argument');
177+
$this->assertEquals($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument');
178+
$this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument');
153179
}
154180

155181
public function testObjectSupportEnabled()

0 commit comments

Comments
 (0)
0