Skip to content

Commit

Permalink
Added unit tests to Dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude authored and fabpot committed Mar 20, 2013
1 parent 19955c5 commit 992a440
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions src/Symfony/Component/Yaml/Tests/DumperTest.php
Expand Up @@ -21,6 +21,21 @@ class DumperTest extends \PHPUnit_Framework_TestCase
protected $dumper;
protected $path;

protected $array = array(
'' => 'bar',
'foo' => '#bar',
'foo\'bar' => array(),
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
),
),
);

protected function setUp()
{
$this->parser = new Parser();
Expand All @@ -33,6 +48,33 @@ protected function tearDown()
$this->parser = null;
$this->dumper = null;
$this->path = null;
$this->array = null;
}

public function testSetIndentation()
{
$this->dumper->setIndentation(7);

$expected = <<<EOF
'': bar
foo: '#bar'
'foo''bar': { }
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
EOF;
$this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
}

public function testSpecifications()
Expand Down Expand Up @@ -63,27 +105,11 @@ public function testSpecifications()

public function testInlineLevel()
{
// inline level
$array = array(
'' => 'bar',
'foo' => '#bar',
'foo\'bar' => array(),
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
'foobar' => array(
'foo' => 'bar',
'bar' => array(1, 'foo'),
),
),
);

$expected = <<<EOF
{ '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
EOF;
$this->assertEquals($expected, $this->dumper->dump($array, -10), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($array, 0), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument');

$expected = <<<EOF
'': bar
Expand All @@ -93,7 +119,7 @@ public function testInlineLevel()
foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 1), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument');

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

$expected = <<<EOF
'': bar
Expand All @@ -127,7 +153,7 @@ public function testInlineLevel()
bar: [1, foo]
EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 3), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument');

$expected = <<<EOF
'': bar
Expand All @@ -148,8 +174,8 @@ public function testInlineLevel()
- foo
EOF;
$this->assertEquals($expected, $this->dumper->dump($array, 4), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($array, 10), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument');
$this->assertEquals($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument');
}

public function testObjectSupportEnabled()
Expand Down

0 comments on commit 992a440

Please sign in to comment.