25 $this->assertSame($value,
Inline::parse($yaml), sprintf(
'::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
35 $this->assertSame(serialize($value), serialize($actual));
46 $this->assertSame(serialize($value), serialize($actual));
54 $this->assertEquals($yaml,
Inline::dump($value), sprintf(
'::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
61 $locale = setlocale(LC_NUMERIC, 0);
62 if (
false === $locale) {
63 $this->markTestSkipped(
'Your platform does not support locales.');
67 $requiredLocales =
array(
'fr_FR.UTF-8',
'fr_FR.UTF8',
'fr_FR.utf-8',
'fr_FR.utf8',
'French_France.1252');
68 if (
false === setlocale(LC_NUMERIC, $requiredLocales)) {
69 $this->markTestSkipped(
'Could not set any of required locales: '.implode(
', ', $requiredLocales));
73 $this->assertContains(
'fr', strtolower(setlocale(LC_NUMERIC, 0)));
75 setlocale(LC_NUMERIC, $locale);
108 $value =
"'don't do somthin' like that'";
117 $value =
'"don"t do somthin" like that"';
126 $value =
'{ "foo " bar": "bar" }';
148 $value =
"'don''t do somthin'' like that'";
149 $expect =
"don't do somthin' like that";
168 $this->assertSame($expected,
Inline::parse($yaml,
false,
false,
false,
array(
'var' =>
'var-value')));
174 'scalar' =>
array(
'*var',
'var-value'),
175 'list' =>
array(
'[ *var ]',
array(
'var-value')),
177 'map-in-list' =>
array(
'[ { key: *var } ]',
array(
array(
'key' =>
'var-value'))),
178 'embedded-mapping-in-list' =>
array(
'[ key: *var ]',
array(
array(
'key' =>
'var-value'))),
179 'map' =>
array(
'{ key: *var }',
array(
'key' =>
'var-value')),
180 'list-in-map' =>
array(
'{ key: [*var] }',
array(
'key' =>
array(
'var-value'))),
181 'map-in-map' =>
array(
'{ foo: { bar: *var } }',
array(
'foo' =>
array(
'bar' =>
'var-value'))),
263 ErrorAssert::assertDeprecationsAreTriggered(
'Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.',
function () {
291 array(
'false',
false),
295 array(
'"quoted string"',
'quoted string'),
296 array(
"'quoted string'",
'quoted string'),
297 array(
'12.30e+02', 12.30
e+02),
298 array(
'0x4D2', 0x4D2),
299 array(
'02333', 02333),
300 array(
'.Inf', -log(0)),
301 array(
'-.Inf', log(0)),
302 array(
"'686e444'",
'686e444'),
303 array(
'686e444', 646e444),
304 array(
'123456789123456789123456789123456789',
'123456789123456789123456789123456789'),
305 array(
'"foo\r\nbar"',
"foo\r\nbar"),
306 array(
"'foo#bar'",
'foo#bar'),
307 array(
"'foo # bar'",
'foo # bar'),
308 array(
"'#cfcfcf'",
'#cfcfcf'),
309 array(
'::form_base.html.twig',
'::form_base.html.twig'),
314 array(
"'yes'",
'yes'),
317 array(
"'off'",
'off'),
319 array(
'2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)),
320 array(
'2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
321 array(
'2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
322 array(
'1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
323 array(
'1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
325 array(
'"a \\"string\\" with \'quoted strings inside\'"',
'a "string" with \'quoted strings inside\''),
326 array(
"'a \"string\" with ''quoted strings inside'''",
'a "string" with \'quoted strings inside\''),
330 array(
'[foo, http://urls.are/no/mappings, false, null, 12]',
array(
'foo',
'http://urls.are/no/mappings',
false, null, 12)),
331 array(
'[ foo , bar , false , null , 12 ]',
array(
'foo',
'bar',
false, null, 12)),
332 array(
'[\'foo,bar\', \'foo bar\']',
array(
'foo,bar',
'foo bar')),
335 array(
'{foo:bar,bar:foo,false:false,null:null,integer:12}',
array(
'foo' =>
'bar',
'bar' =>
'foo',
'false' =>
false,
'null' => null,
'integer' => 12)),
336 array(
'{ foo : bar, bar : foo, false : false, null : null, integer : 12 }',
array(
'foo' =>
'bar',
'bar' =>
'foo',
'false' =>
false,
'null' => null,
'integer' => 12)),
337 array(
'{foo: \'bar\', bar: \'foo: bar\'}',
array(
'foo' =>
'bar',
'bar' =>
'foo: bar')),
338 array(
'{\'foo\': \'bar\', "bar": \'foo: bar\'}',
array(
'foo' =>
'bar',
'bar' =>
'foo: bar')),
339 array(
'{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}',
array(
'foo\'' =>
'bar',
'bar"' =>
'foo: bar')),
340 array(
'{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}',
array(
'foo: ' =>
'bar',
'bar: ' =>
'foo: bar')),
352 array(
'[foo, [bar, [foo, [bar, foo]], foo]]',
array(
'foo',
array(
'bar',
array(
'foo',
array(
'bar',
'foo')),
'foo'))),
354 array(
'[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]',
array(
'foo',
array(
'bar' =>
'foo',
'foo' =>
array(
'foo',
array(
'bar' =>
'foo'))),
array(
'foo',
array(
'bar' =>
'foo')))),
357 array(
'[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']',
array(
'foo',
'@foo.baz',
array(
'%foo%' =>
'foo is %foo%',
'bar' =>
'%foo%'),
true,
'@service_container')),
366 array(
'false',
false),
370 array(
'"quoted string"',
'quoted string'),
371 array(
"'quoted string'",
'quoted string'),
372 array(
'12.30e+02', 12.30
e+02),
373 array(
'0x4D2', 0x4D2),
374 array(
'02333', 02333),
375 array(
'.Inf', -log(0)),
376 array(
'-.Inf', log(0)),
377 array(
"'686e444'",
'686e444'),
378 array(
'686e444', 646e444),
379 array(
'123456789123456789123456789123456789',
'123456789123456789123456789123456789'),
380 array(
'"foo\r\nbar"',
"foo\r\nbar"),
381 array(
"'foo#bar'",
'foo#bar'),
382 array(
"'foo # bar'",
'foo # bar'),
383 array(
"'#cfcfcf'",
'#cfcfcf'),
384 array(
'::form_base.html.twig',
'::form_base.html.twig'),
386 array(
'2007-10-30', gmmktime(0, 0, 0, 10, 30, 2007)),
387 array(
'2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
388 array(
'2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
389 array(
'1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
390 array(
'1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
392 array(
'"a \\"string\\" with \'quoted strings inside\'"',
'a "string" with \'quoted strings inside\''),
393 array(
"'a \"string\" with ''quoted strings inside'''",
'a "string" with \'quoted strings inside\''),
397 array(
'[foo, http://urls.are/no/mappings, false, null, 12]',
array(
'foo',
'http://urls.are/no/mappings',
false, null, 12)),
398 array(
'[ foo , bar , false , null , 12 ]',
array(
'foo',
'bar',
false, null, 12)),
399 array(
'[\'foo,bar\', \'foo bar\']',
array(
'foo,bar',
'foo bar')),
402 array(
'{foo:bar,bar:foo,false:false,null:null,integer:12}', (
object)
array(
'foo' =>
'bar',
'bar' =>
'foo',
'false' =>
false,
'null' => null,
'integer' => 12)),
403 array(
'{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (
object)
array(
'foo' =>
'bar',
'bar' =>
'foo',
'false' =>
false,
'null' => null,
'integer' => 12)),
404 array(
'{foo: \'bar\', bar: \'foo: bar\'}', (
object)
array(
'foo' =>
'bar',
'bar' =>
'foo: bar')),
405 array(
'{\'foo\': \'bar\', "bar": \'foo: bar\'}', (
object)
array(
'foo' =>
'bar',
'bar' =>
'foo: bar')),
406 array(
'{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (
object)
array(
'foo\'' =>
'bar',
'bar"' =>
'foo: bar')),
407 array(
'{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (
object)
array(
'foo: ' =>
'bar',
'bar: ' =>
'foo: bar')),
411 array(
'[foo, {bar: foo}]',
array(
'foo', (
object)
array(
'bar' =>
'foo'))),
412 array(
'{ foo: {bar: foo} }', (
object)
array(
'foo' => (
object)
array(
'bar' =>
'foo'))),
413 array(
'{ foo: [bar, foo] }', (
object)
array(
'foo' =>
array(
'bar',
'foo'))),
419 array(
'[foo, [bar, [foo, [bar, foo]], foo]]',
array(
'foo',
array(
'bar',
array(
'foo',
array(
'bar',
'foo')),
'foo'))),
421 array(
'[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]',
array(
'foo', (
object)
array(
'bar' =>
'foo',
'foo' =>
array(
'foo', (
object)
array(
'bar' =>
'foo'))),
array(
'foo', (
object)
array(
'bar' =>
'foo')))),
423 array(
'[foo, bar: { foo: bar }]',
array(
'foo',
'1' => (
object)
array(
'bar' => (
object)
array(
'foo' =>
'bar')))),
424 array(
'[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']',
array(
'foo',
'@foo.baz', (
object)
array(
'%foo%' =>
'foo is %foo%',
'bar' =>
'%foo%'),
true,
'@service_container')),
426 array(
'{}',
new \stdClass()),
427 array(
'{ foo : bar, bar : {} }', (
object)
array(
'foo' =>
'bar',
'bar' =>
new \stdClass())),
428 array(
'{ foo : [], bar : {} }', (
object)
array(
'foo' =>
array(),
'bar' =>
new \stdClass())),
429 array(
'{foo: \'bar\', bar: {} }', (
object)
array(
'foo' =>
'bar',
'bar' =>
new \stdClass())),
430 array(
'{\'foo\': \'bar\', "bar": {}}', (
object)
array(
'foo' =>
'bar',
'bar' =>
new \stdClass())),
431 array(
'{\'foo\': \'bar\', "bar": \'{}\'}', (
object)
array(
'foo' =>
'bar',
'bar' =>
'{}')),
433 array(
'[foo, [{}, {}]]',
array(
'foo',
array(
new \stdClass(),
new \stdClass()))),
435 array(
'[foo, [[{}, {}], {}]]',
array(
'foo',
array(
array(
new \stdClass(),
new \stdClass()),
new \stdClass()))),
436 array(
'[foo, {bar: {}}]',
array(
'foo',
'1' => (
object)
array(
'bar' =>
new \stdClass()))),
444 array(
'false',
false),
447 array(
"'quoted string'",
'quoted string'),
448 array(
'!!float 1230', 12.30
e+02),
449 array(
'1234', 0x4D2),
450 array(
'1243', 02333),
451 array(
'.Inf', -log(0)),
452 array(
'-.Inf', log(0)),
453 array(
"'686e444'",
'686e444'),
454 array(
'"foo\r\nbar"',
"foo\r\nbar"),
455 array(
"'foo#bar'",
'foo#bar'),
456 array(
"'foo # bar'",
'foo # bar'),
457 array(
"'#cfcfcf'",
'#cfcfcf'),
459 array(
"'a \"string\" with ''quoted strings inside'''",
'a "string" with \'quoted strings inside\''),
461 array(
"'-dash'",
'-dash'),
467 array(
"'yes'",
'yes'),
470 array(
"'off'",
'off'),
473 array(
'[foo, bar, false, null, 12]',
array(
'foo',
'bar',
false, null, 12)),
474 array(
'[\'foo,bar\', \'foo bar\']',
array(
'foo,bar',
'foo bar')),
477 array(
'{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }',
array(
'foo' =>
'bar',
'bar' =>
'foo',
'false' =>
false,
'null' => null,
'integer' => 12)),
478 array(
'{ foo: bar, bar: \'foo: bar\' }',
array(
'foo' =>
'bar',
'bar' =>
'foo: bar')),
483 array(
'[foo, [bar, [foo, [bar, foo]], foo]]',
array(
'foo',
array(
'bar',
array(
'foo',
array(
'bar',
'foo')),
'foo'))),
489 array(
'[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]',
array(
'foo',
array(
'bar' =>
'foo',
'foo' =>
array(
'foo',
array(
'bar' =>
'foo'))),
array(
'foo',
array(
'bar' =>
'foo')))),
491 array(
'[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']',
array(
'foo',
'@foo.baz',
array(
'%foo%' =>
'foo is %foo%',
'bar' =>
'%foo%'),
true,
'@service_container')),
493 array(
'{ foo: { bar: { 1: 2, baz: 3 } } }',
array(
'foo' =>
array(
'bar' =>
array(1 => 2,
'baz' => 3)))),
502 $this->assertSame(gmmktime($hour, $minute, $second, $month, $day, $year),
Inline::parse($yaml));
510 $expected = new \DateTime($yaml);
511 $expected->setTimeZone(
new \DateTimeZone(
'UTC'));
512 $expected->setDate($year, $month, $day);
513 $expected->setTime($hour, $minute, $second);
521 'canonical' =>
array(
'2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43),
522 'ISO-8601' =>
array(
'2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43),
523 'spaced' =>
array(
'2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43),
524 'date' =>
array(
'2001-12-15', 2001, 12, 15, 0, 0, 0),
533 $expected = new \DateTime($yaml);
534 $expected->setTimeZone(
new \DateTimeZone(
'UTC'));
535 $expected->setDate($year, $month, $day);
536 $expected->setTime($hour, $minute, $second);
538 $expectedNested =
array(
'nested' =>
array($expected));
539 $yamlNested =
"{nested: [$yaml]}";
556 $dateTime = new \DateTime(
'2001-12-15 21:59:43',
new \DateTimeZone(
'UTC'));
557 $tests[
'date-time-utc'] =
array($dateTime,
'2001-12-15T21:59:43+00:00');
559 $dateTime = new \DateTimeImmutable(
'2001-07-15 21:59:43',
new \DateTimeZone(
'Europe/Berlin'));
560 $tests[
'immutable-date-time-europe-berlin'] =
array($dateTime,
'2001-07-15T21:59:43+02:00');
576 'enclosed with double quotes' =>
array(
'!!binary "SGVsbG8gd29ybGQ="'),
577 'enclosed with single quotes' =>
array(
"!!binary 'SGVsbG8gd29ybGQ='"),
578 'containing spaces' =>
array(
'!!binary "SGVs bG8gd 29ybGQ="'),
587 $this->setExpectedExceptionRegExp(
'\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
595 'length not a multiple of four' =>
array(
'!!binary "SGVsbG8d29ybGQ="',
'/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/'),
596 'invalid characters' =>
array(
'!!binary "SGVsbG8#d29ybGQ="',
'/The base64 encoded data \(.*\) contains invalid characters/'),
597 'too many equals characters' =>
array(
'!!binary "SGVsbG8gd29yb==="',
'/The base64 encoded data \(.*\) contains invalid characters/'),
598 'misplaced equals character' =>
array(
'!!binary "SGVsbG8gd29ybG=Q"',
'/The base64 encoded data \(.*\) contains invalid characters/'),
testParseUnquotedScalarStartingWithScalarIndicator($indicator)
getScalarIndicators Symfony cannot start a plain scalar; you need to quote the scalar.
testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month, $day, $hour, $minute, $second)
getTimestampTests
testParse($yaml, $value)
getTestsForParse
testDumpDateTime($dateTime, $expected)
getDateTimeDumpTests
testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException()
testParseScalarWithNonEscapedBlackslashAtTheEndShouldThrowException()
testParseReferences($yaml, $expected)
getDataForParseReferences
testParseInvalidMappingKeyShouldThrowException()
testParseInvalidMappingShouldThrowException()
testParseScalarWithNonEscapedBlackslashShouldThrowException()
Found unknown escape character "\V".
testParseWithMapObjectsPassingTrue($yaml, $value)
legacy getTestsForParseWithMapObjects
testParseUnquotedAsteriskFollowedByAComment()
A reference must contain at least one character.
testParseScalarWithCorrectlyQuotedStringShouldReturnString()
static isHash(array $value)
Check if given array is hash or just normal indexed array.
testParseScalarWithIncorrectlyQuotedStringShouldThrowException()
testParseMapReferenceInSequence()
testParseBinaryData($data)
getBinaryData
static dump($value, $flags=0)
Dumps a given PHP variable to a YAML string.
testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
testParseInvalidSequenceShouldThrowException()
testParseMapReferenceInSequenceAsFifthArgument()
legacy
getTestsForParseWithMapObjects()
getDataForParseReferences()
testDumpNumericValueWithLocale()
static parseScalar($scalar, $flags=0, $delimiters=null, $stringDelimiters=array('"', "'"), &$i = 0, $evaluate = true, $references = array())
Parses a scalar to a YAML string.
testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
getTimestampTests
testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
getTimestampTests
testIsHash($array, $expected)
getDataForIsHash
testParseUnquotedScalarStartingWithReservedIndicator($indicator)
getReservedIndicators Symfony cannot start a plain scalar; you need to quote the scalar...
Create styles array
The data for the language used.
testParseWithMapObjects($yaml, $value)
getTestsForParseWithMapObjects
testParseReferencesAsFifthArgument($yaml, $expected)
legacy getDataForParseReferences
static parse($value, $flags=0, $references=array())
Converts a YAML string to a PHP array.
testParseInvalidBinaryData($data, $expectedMessage)
getInvalidBinaryData
testDump($yaml, $value)
getTestsForDump
const PARSE_OBJECT_FOR_MAP
testParseUnquotedScalarStartingWithPercentCharacter()
legacy function Symfony::assertDeprecationsAreTriggered throws in 4.0
testParseUnquotedAsterisk()
A reference must contain at least one character.