27 'foo\'bar' => array(),
28 'bar' => array(1,
'foo'),
31 'bar' => array(1,
'foo'),
34 'bar' => array(1,
'foo'),
41 $this->parser =
new Parser();
42 $this->dumper =
new Dumper();
43 $this->path = __DIR__.
'/Fixtures';
76 $this->assertEquals($expected,
$dumper->dump($this->array, 4, 0));
84 $this->dumper->setIndentation(7);
105 $this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
110 $files = $this->parser->parse(file_get_contents($this->path.
'/index.yml'));
111 foreach (
$files as $file) {
112 $yamls = file_get_contents($this->path.
'/'.$file.
'.yml');
115 foreach (preg_split(
'/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) {
120 $test = $this->parser->parse($yaml);
121 if (isset(
$test[
'dump_skip']) &&
$test[
'dump_skip']) {
123 } elseif (isset(
$test[
'todo']) &&
$test[
'todo']) {
126 eval(
'$expected = '.trim(
$test[
'php']).
';');
127 $this->assertSame($expected, $this->parser->parse($this->dumper->dump($expected, 10)),
$test[
'test']);
136 {
'': bar, foo:
'#bar',
'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
138 $this->assertEquals($expected, $this->dumper->dump($this->array, -10),
'->dump() takes an inline level argument');
139 $this->assertEquals($expected, $this->dumper->dump($this->array, 0),
'->dump() takes an inline level argument');
146 foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
149 $this->assertEquals($expected, $this->dumper->dump($this->array, 1),
'->dump() takes an inline level argument');
161 foobar: { foo: bar, bar: [1, foo] }
164 $this->assertEquals($expected, $this->dumper->dump($this->array, 2),
'->dump() takes an inline level argument');
183 $this->assertEquals($expected, $this->dumper->dump($this->array, 3),
'->dump() takes an inline level argument');
204 $this->assertEquals($expected, $this->dumper->dump($this->array, 4),
'->dump() takes an inline level argument');
205 $this->assertEquals($expected, $this->dumper->dump($this->array, 10),
'->dump() takes an inline level argument');
210 $dump = $this->dumper->dump(array(
'foo' =>
new A(),
'bar' => 1), 0, 0,
Yaml::DUMP_OBJECT);
212 $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');
220 $dump = $this->dumper->dump(array(
'foo' =>
new A(),
'bar' => 1), 0, 0,
false,
true);
222 $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');
227 $dump = $this->dumper->dump(array(
'foo' =>
new A(),
'bar' => 1));
229 $this->assertEquals(
'{ foo: null, bar: 1 }', $dump,
'->dump() does not dump objects when disabled');
246 $this->dumper->dump(array(
'foo' =>
new A(),
'bar' => 1), 0, 0,
true);
254 $this->assertEquals($expected, $this->dumper->dump(
$input));
260 'null' => array(
"\t\\0",
'"\t\\\\0"'),
261 'bell' => array(
"\t\\a",
'"\t\\\\a"'),
262 'backspace' => array(
"\t\\b",
'"\t\\\\b"'),
263 'horizontal-tab' => array(
"\t\\t",
'"\t\\\\t"'),
264 'line-feed' => array(
"\t\\n",
'"\t\\\\n"'),
265 'vertical-tab' => array(
"\t\\v",
'"\t\\\\v"'),
266 'form-feed' => array(
"\t\\f",
'"\t\\\\f"'),
267 'carriage-return' => array(
"\t\\r",
'"\t\\\\r"'),
268 'escape' => array(
"\t\\e",
'"\t\\\\e"'),
269 'space' => array(
"\t\\ ",
'"\t\\\\ "'),
270 'double-quote' => array(
"\t\\\"",
'"\t\\\\\\""'),
271 'slash' => array(
"\t\\/",
'"\t\\\\/"'),
272 'backslash' => array(
"\t\\\\",
'"\t\\\\\\\\"'),
273 'next-line' => array(
"\t\\N",
'"\t\\\\N"'),
274 'non-breaking-space' => array(
"\t\\�",
'"\t\\\\�"'),
275 'line-separator' => array(
"\t\\L",
'"\t\\\\L"'),
276 'paragraph-separator' => array(
"\t\\P",
'"\t\\\\P"'),
282 $binaryData = file_get_contents(__DIR__.
'/Fixtures/arrow.gif');
283 $expected =
'{ data: !!binary '.base64_encode($binaryData).
' }';
285 $this->assertSame($expected, $this->dumper->dump(array(
'data' => $binaryData)));
291 $this->assertSame(
'!!binary ZsM/cg==', $this->dumper->dump(
"f\xc3\x3fr"));
308 $bar = new \stdClass();
309 $bar->class =
'classBar';
310 $bar->args = array(
'bar');
311 $zar = new \stdClass();
312 $foo = new \stdClass();
315 $object = new \stdClass();
317 $tests[
'stdClass'] = array($object, $object);
319 $arrayObject = new \ArrayObject();
320 $arrayObject[
'foo'] =
'bar';
321 $arrayObject[
'baz'] =
'foobar';
322 $parsedArrayObject = new \stdClass();
323 $parsedArrayObject->foo =
'bar';
324 $parsedArrayObject->baz =
'foobar';
325 $tests[
'ArrayObject'] = array($arrayObject, $parsedArrayObject);
328 $tests[
'arbitrary-object'] = array($a, null);
337 'single_line' =>
'foo bar baz',
338 'multi_line' =>
"foo\nline with trailing spaces:\n \nbar\r\ninteger like line:\n123456789\nempty line:\n\nbaz",
339 'nested_inlined_multi_line_string' => array(
340 'inlined_multi_line' =>
"foo\nbar\r\nempty line:\n\nbaz",
testSetIndentation()
legacy
const DUMP_MULTI_LINE_LITERAL_BLOCK
testBinaryDataIsDumpedBase64Encoded()
testObjectSupportDisabledButNoExceptions()
testObjectSupportDisabledWithExceptions()
static parse($input, $flags=0)
Parses YAML into a PHP value.
testNonUtf8DataIsDumpedBase64Encoded()
testEscapedEscapeSequencesInQuotedScalar($input, $expected)
getEscapeSequences
testIndentationInConstructor()
testObjectSupportDisabledWithExceptionsPassingTrue()
legacy
Parser parses YAML strings to convert them to PHP arrays.
Dumper dumps PHP variables to YAML strings.
testDumpObjectAsMap($object, $expected)
objectAsMapProvider
testDumpMultiLineStringAsScalarBlock()
testNegativeIndentationThrowsException()
The indentation must be greater than zero
testObjectSupportEnabledPassingTrue()
legacy
testZeroIndentationThrowsException()
The indentation must be greater than zero
const PARSE_OBJECT_FOR_MAP
const DUMP_EXCEPTION_ON_INVALID_TYPE
testObjectSupportEnabled()
const EOF
How fgetc() reports an End Of File.