8000 [YAML] Added unit tests to Dumper by eddiejaoude · Pull Request #7144 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[YAML] Added unit tests to Dumper #7144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
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