23 $this->parser =
new Parser();
36 $this->assertEquals($expected, var_export($this->parser->parse($yaml),
true),
$comment);
42 $path = __DIR__.
'/Fixtures';
47 $yamls = file_get_contents(
$path.
'/'.$file.
'.yml');
50 foreach (preg_split(
'/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) {
59 eval(
'$expected = '.trim(
$test[
'php']).
';');
61 $tests[] =
array($file, var_export($expected,
true),
$test[
'yaml'],
$test[
'test']);
79 foreach ($yamls as $yaml) {
81 $content = $this->parser->parse($yaml);
83 $this->fail(
'YAML files must not contain tabs');
85 $this->assertInstanceOf(
'\Exception', $e,
'YAML files must not contain tabs');
86 $this->assertEquals(
'A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml,
"\t").
'").', $e->getMessage(),
'YAML files must not contain tabs');
99 $this->assertEquals(
'foo', $this->parser->parse($yaml));
119 $tests[
'Literal block chomping strip with single trailing newline'] =
array($expected, $yaml);
136 $tests[
'Literal block chomping strip with multiple trailing newlines'] =
array($expected, $yaml);
144 $tests[
'Literal block chomping strip with multiple trailing newlines after a 1-liner'] =
array($expected, $yaml);
158 $tests[
'Literal block chomping strip without trailing newline'] =
array($expected, $yaml);
170 'foo' =>
"one\ntwo\n",
171 'bar' =>
"one\ntwo\n",
173 $tests[
'Literal block chomping clip with single trailing newline'] =
array($expected, $yaml);
187 'foo' =>
"one\ntwo\n",
188 'bar' =>
"one\ntwo\n",
190 $tests[
'Literal block chomping clip with multiple trailing newlines'] =
array($expected, $yaml);
201 'foo' =>
"one\ntwo\n",
204 $tests[
'Literal block chomping clip without trailing newline'] =
array($expected, $yaml);
216 'foo' =>
"one\ntwo\n",
217 'bar' =>
"one\ntwo\n",
219 $tests[
'Literal block chomping keep with single trailing newline'] =
array($expected, $yaml);
233 'foo' =>
"one\ntwo\n\n",
234 'bar' =>
"one\ntwo\n\n",
236 $tests[
'Literal block chomping keep with multiple trailing newlines'] =
array($expected, $yaml);
247 'foo' =>
"one\ntwo\n",
250 $tests[
'Literal block chomping keep without trailing newline'] =
array($expected, $yaml);
265 $tests[
'Folded block chomping strip with single trailing newline'] =
array($expected, $yaml);
282 $tests[
'Folded block chomping strip with multiple trailing newlines'] =
array($expected, $yaml);
296 $tests[
'Folded block chomping strip without trailing newline'] =
array($expected, $yaml);
308 'foo' =>
"one two\n",
309 'bar' =>
"one two\n",
311 $tests[
'Folded block chomping clip with single trailing newline'] =
array($expected, $yaml);
325 'foo' =>
"one two\n",
326 'bar' =>
"one two\n",
328 $tests[
'Folded block chomping clip with multiple trailing newlines'] =
array($expected, $yaml);
339 'foo' =>
"one two\n",
342 $tests[
'Folded block chomping clip without trailing newline'] =
array($expected, $yaml);
354 'foo' =>
"one two\n",
355 'bar' =>
"one two\n",
357 $tests[
'Folded block chomping keep with single trailing newline'] =
array($expected, $yaml);
371 'foo' =>
"one two\n\n",
372 'bar' =>
"one two\n\n",
374 $tests[
'Folded block chomping keep with multiple trailing newlines'] =
array($expected, $yaml);
385 'foo' =>
"one two\n",
388 $tests[
'Folded block chomping keep without trailing newline'] =
array($expected, $yaml);
398 $this->assertSame($expected, $this->parser->parse($yaml));
419 $this->assertSame($expected, $this->parser->parse($yaml));
425 foo: !
php/
object:O:30:
"Symfony\Component\Yaml\Tests\B":1:{
s:1:
"b";
s:3:
"foo";}
428 $this->assertEquals(
array(
'foo' =>
new B(),
'bar' => 1), $this->parser->parse($input,
Yaml::PARSE_OBJECT),
'->parse() is able to parse objects');
437 foo: !
php/
object:O:30:
"Symfony\Component\Yaml\Tests\B":1:{
s:1:
"b";
s:3:
"foo";}
440 $this->assertEquals(
array(
'foo' =>
new B(),
'bar' => 1), $this->parser->parse($input,
false,
true),
'->parse() is able to parse objects');
449 foo: !!
php/
object:O:30:
"Symfony\Component\Yaml\Tests\B":1:{
s:1:
"b";
s:3:
"foo";}
452 $this->assertEquals(
array(
'foo' =>
new B(),
'bar' => 1), $this->parser->parse($input,
Yaml::PARSE_OBJECT),
'->parse() is able to parse objects');
460 $this->assertEquals(
array(
'foo' => null,
'bar' => 1), $this->parser->parse($input),
'->parse() does not parse objects');
477 $this->assertEquals($expected, $this->parser->parse($yaml,
false,
false,
true));
488 $expected = new \stdClass();
489 $expected->foo = new \stdClass();
490 $expected->foo->fiz =
array(
'cat');
491 $tests[
'mapping'] =
array($yaml, $expected);
493 $yaml =
'{ "foo": "bar", "fiz": "cat" }';
494 $expected = new \stdClass();
495 $expected->foo =
'bar';
496 $expected->fiz =
'cat';
497 $tests[
'inline-mapping'] =
array($yaml, $expected);
499 $yaml =
"foo: bar\nbaz: foobar";
500 $expected = new \stdClass();
501 $expected->foo =
'bar';
502 $expected->baz =
'foobar';
503 $tests[
'object-for-map-is-applied-after-parsing'] =
array($yaml, $expected);
510 $expected = new \stdClass();
511 $expected->array =
array();
512 $expected->array[0] = new \stdClass();
513 $expected->array[0]->key =
'one';
514 $expected->array[1] = new \stdClass();
515 $expected->array[1]->key =
'two';
516 $tests[
'nest-map-and-sequence'] =
array($yaml, $expected);
523 $expected = new \stdClass();
524 $expected->map = new \stdClass();
525 $expected->map->{1} =
'one';
526 $expected->map->{2} =
'two';
527 $tests[
'numeric-keys'] =
array($yaml, $expected);
534 $expected = new \stdClass();
535 $expected->map = new \stdClass();
536 $expected->map->{0} =
'one';
537 $expected->map->{1} =
'two';
538 $tests[
'zero-indexed-numeric-keys'] =
array($yaml, $expected);
559 $this->parser->parse($yaml,
true);
565 foo: !!
php/
object:O:30:
"Symfony\Tests\Component\Yaml\B":1:{
s:1:
"b";
s:3:
"foo";}
569 foo: !
php/
object:O:30:
"Symfony\Tests\Component\Yaml\B":1:{
s:1:
"b";
s:3:
"foo";}
574 'yaml-tag' =>
array($yamlTag),
575 'local-tag' =>
array($localTag),
585 iconv(
'UTF-8',
'ISO-8859-1',
"foo: 'äöüß'"),
586 iconv(
'UTF-8',
'ISO-8859-15',
"euro: '€'"),
587 iconv(
'UTF-8',
'CP1252',
"cp1252: '©ÉÇáñ'"),
590 foreach ($yamls as $yaml) {
592 $this->parser->parse($yaml);
594 $this->fail(
'charsets other than UTF-8 are rejected.');
596 $this->assertInstanceOf(
'Symfony\Component\Yaml\Exception\ParseException', $e,
'charsets other than UTF-8 are rejected.');
615 $this->parser->parse($yaml);
631 $this->parser->parse($yaml);
641 # Ranking
of 1998 home runs
693 $this->assertSame($expected, $this->parser->parse($yaml));
712 $this->assertSame($expected, $this->parser->parse($yaml));
774 parent: { child: first, child: duplicate }
775 parent: { child: duplicate, child: duplicate }
796 $this->assertEquals(
array(
798 'app.foo_service' =>
array(
801 'app/bar_service' =>
array(
822 $this->assertEquals(
array(
'content' => <<<
'EOT' 850 $this->assertEquals(
array(
array(
'content' => <<<
'EOT' 880 'title' =>
'some title',
881 'content' => <<<
'EOT' 911 $this->assertEquals(
array(
912 'var' =>
'var-value',
913 'scalar' =>
'var-value',
914 'list' =>
array(
'var-value'),
916 'map_in_list' =>
array(
array(
'key' =>
'var-value')),
917 'embedded_mapping' =>
array(
array(
'key' =>
'var-value')),
918 'map' =>
array(
'key' =>
'var-value'),
919 'list_in_map' =>
array(
'key' =>
array(
'var-value')),
920 'map_in_map' =>
array(
'foo' =>
array(
'bar' =>
'var-value')),
925 list_in_list: [[ *var ]]
926 map_in_list: [ { key: *var } ]
927 embedded_mapping: [ key: *var ]
929 list_in_map: { key: [*var] }
930 map_in_map: { foo: { bar: *var } }
943 $this->assertEquals(
array(
'foo' => 1,
'bar' => 2), $this->parser->parse($yaml));
961 $this->assertEquals($expected, $this->parser->parse($yaml));
974 $this->parser->parse($yaml);
981 bar: foobar # Note:
a comment after
a colon
984 $this->assertSame(
array(
'foo' =>
array(
'bar' =>
'foobar')), $this->parser->parse($yaml));
992 $this->assertSame($expectedParserResult, $this->parser->parse($yaml));
1017 'title' =>
'some title',
1018 'content' => <<<
'EOT' 1033 $tests[] =
array($yaml, $expected);
1058 'collection' =>
array(
1078 $tests[] =
array($yaml, $expected);
1093 'scalar-block' =>
"line1 line2>\n",
1100 $tests[] =
array($yaml, $expected);
1116 $tests[] =
array($yaml, $expected);
1129 <li>may be
a good example</li>
1137 <ul> <li>
a list</li> <li>may be
a good example</li> </ul>
1141 $this->parser->parse($yaml)
1153 <li>may be
a good example</li>
1163 <li>may be
a good example</li>
1168 $this->parser->parse($yaml)
1177 $this->assertSame(
array(
'data' =>
'Hello world'), $this->parser->parse(
$data));
1183 'enclosed with double quotes' =>
array(
'data: !!binary "SGVsbG8gd29ybGQ="'),
1184 'enclosed with single quotes' =>
array(
"data: !!binary 'SGVsbG8gd29ybGQ='"),
1185 'containing spaces' =>
array(
'data: !!binary "SGVs bG8gd 29ybGQ="'),
1186 'in block scalar' =>
array(
1192 'containing spaces in block scalar' =>
array(
1206 $this->setExpectedExceptionRegExp(
'\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
1208 $this->parser->parse(
$data);
1214 'length not a multiple of four' =>
array(
'data: !!binary "SGVsbG8d29ybGQ="',
'/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/'),
1215 'invalid characters' =>
array(
'!!binary "SGVsbG8#d29ybGQ="',
'/The base64 encoded data \(.*\) contains invalid characters/'),
1216 'too many equals characters' =>
array(
'data: !!binary "SGVsbG8gd29yb==="',
'/The base64 encoded data \(.*\) contains invalid characters/'),
1217 'misplaced equals character' =>
array(
'data: !!binary "SGVsbG8gd29ybG=Q"',
'/The base64 encoded data \(.*\) contains invalid characters/'),
1218 'length not a multiple of four in block scalar' =>
array(
1224 '/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/',
1226 'invalid characters in block scalar' =>
array(
1232 '/The base64 encoded data \(.*\) contains invalid characters/',
1234 'too many equals characters in block scalar' =>
array(
1240 '/The base64 encoded data \(.*\) contains invalid characters/',
1242 'misplaced equals character in block scalar' =>
array(
1248 '/The base64 encoded data \(.*\) contains invalid characters/',
1258 $expectedDate = new \DateTime();
1259 $expectedDate->setTimeZone(
new \DateTimeZone(
'UTC'));
1260 $expectedDate->setDate(2002, 12, 14);
1261 $expectedDate->setTime(0, 0, 0);
1273 $this->setExpectedException(
1274 '\Symfony\Component\Yaml\Exception\ParseException',
1275 sprintf(
'Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)
1278 $this->parser->parse($yaml);
testBlockLiteralWithLeadingNewlines()
Regression test for issue #7989.
testParseBinaryData($data)
getBinaryData
testNestedFoldedStringBlockWithComments()
testUnindentedCollectionException()
const PARSE_EXCEPTION_ON_INVALID_TYPE
testShortcutKeyUnindentedCollectionException()
testObjectSupportEnabledWithDeprecatedTag()
legacy
testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected)
legacy getObjectForMapTests
testSequenceInMappingStartedBySingleDashLine()
invalidDumpedObjectProvider()
testObjectSupportEnabledPassingTrue()
legacy
testColonInMappingValueException()
A colon cannot be used in an unquoted mapping value
testObjectsSupportDisabledWithExceptions($yaml)
invalidDumpedObjectProvider
testSequenceFollowedByCommentEmbeddedInMapping()
testScalarInSequence()
missing colon
testMultipleDocumentsNotSupportedException()
/^Multiple documents are not supported.
testObjectSupportDisabledButNoExceptions($input)
invalidDumpedObjectProvider
testParseInvalidBinaryData($data, $expectedMessage)
getInvalidBinaryData
testMappingDuplicateKeyBlock()
It is an error for two equal keys to appear in the same mapping node.
testReferenceResolvingInInlineStrings()
getDataFormSpecifications()
static parse($input, $flags=0)
Parses YAML into a PHP value.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml)
legacy invalidDumpedObjectProvider
testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
getCommentLikeStringInScalarBlockData()
Add a drawing to the header
parserThrowsExceptionWithCorrectLineNumberProvider()
Parser parses YAML strings to convert them to PHP arrays.
testObjectSupportEnabled()
Create styles array
The data for the language used.
testNonUtf8Exception()
extension iconv
testBlankLinesAreParsedAsNewLinesInFoldedBlocks()
testMappingDuplicateKeyFlow()
testParseDateAsMappingValue()
testFoldedStringBlockWithComments()
testEndOfTheDocumentMarker()
Create new PHPExcel object
obj_idprivate
testSpecifications($file, $expected, $yaml, $comment)
getDataFormSpecifications
testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks()
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
testCommentAtTheRootIndent()
testStringBlockWithComments()
testColonInMappingValueExceptionNotTriggeredByColonInComment()
const PARSE_OBJECT_FOR_MAP
testBlockChomping($expected, $yaml)
getBlockChompingTests
testObjectForMap($yaml, $expected)
getObjectForMapTests
testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult)
getCommentLikeStringInScalarBlockData
const EOF
How fgetc() reports an End Of File.