add myCalendar into
[awl.git] / vendor / symfony / yaml / Symfony / Component / Yaml / Tests / DumperTest.php
blobc51a257dc08f315c2211cc89c3b8ca00a9241de5
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Yaml\Tests;
14 use Symfony\Component\Yaml\Yaml;
15 use Symfony\Component\Yaml\Parser;
16 use Symfony\Component\Yaml\Dumper;
18 class DumperTest extends \PHPUnit_Framework_TestCase
20 protected $parser;
21 protected $dumper;
22 protected $path;
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'),
39 protected function setUp()
41 $this->parser = new Parser();
42 $this->dumper = new Dumper();
43 $this->path = __DIR__.'/Fixtures';
46 protected function tearDown()
48 $this->parser = null;
49 $this->dumper = null;
50 $this->path = null;
51 $this->array = null;
54 public function testSetIndentation()
56 $this->dumper->setIndentation(7);
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
76 EOF;
77 $this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
80 public function testSpecifications()
82 $files = $this->parser->parse(file_get_contents($this->path.'/index.yml'));
83 foreach ($files as $file) {
84 $yamls = file_get_contents($this->path.'/'.$file.'.yml');
86 // split YAMLs documents
87 foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) {
88 if (!$yaml) {
89 continue;
92 $test = $this->parser->parse($yaml);
93 if (isset($test['dump_skip']) && $test['dump_skip']) {
94 continue;
95 } elseif (isset($test['todo']) && $test['todo']) {
96 // TODO
97 } else {
98 $expected = eval('return '.trim($test['php']).';');
100 $this->assertEquals($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']);
106 public function testInlineLevel()
108 $expected = <<<EOF
109 { '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
110 EOF;
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');
114 $expected = <<<EOF
115 '': bar
116 foo: '#bar'
117 'foo''bar': { }
118 bar: [1, foo]
119 foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
121 EOF;
122 $this->assertEquals($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument');
124 $expected = <<<EOF
125 '': bar
126 foo: '#bar'
127 'foo''bar': { }
128 bar:
130 - foo
131 foobar:
132 foo: bar
133 bar: [1, foo]
134 foobar: { foo: bar, bar: [1, foo] }
136 EOF;
137 $this->assertEquals($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument');
139 $expected = <<<EOF
140 '': bar
141 foo: '#bar'
142 'foo''bar': { }
143 bar:
145 - foo
146 foobar:
147 foo: bar
148 bar:
150 - foo
151 foobar:
152 foo: bar
153 bar: [1, foo]
155 EOF;
156 $this->assertEquals($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument');
158 $expected = <<<EOF
159 '': bar
160 foo: '#bar'
161 'foo''bar': { }
162 bar:
164 - foo
165 foobar:
166 foo: bar
167 bar:
169 - foo
170 foobar:
171 foo: bar
172 bar:
174 - foo
176 EOF;
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');
181 public function testObjectSupportEnabled()
183 $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
185 $this->assertEquals('{ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
188 public function testObjectSupportDisabledButNoExceptions()
190 $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1));
192 $this->assertEquals('{ foo: null, bar: 1 }', $dump, '->dump() does not dump objects when disabled');
196 * @expectedException \Symfony\Component\Yaml\Exception\DumpException
198 public function testObjectSupportDisabledWithExceptions()
200 $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true, false);
204 class A
206 public $a = 'foo';