X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fyaml%2FTests%2FInlineTest.php;h=f2c4ab6084702e7d370097fa3af6341291862714;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=8074123e6df75617f390b4b9d0229d1b05f5e7ca;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/vendor/symfony/yaml/Tests/InlineTest.php b/vendor/symfony/yaml/Tests/InlineTest.php index 8074123e6..f2c4ab608 100644 --- a/vendor/symfony/yaml/Tests/InlineTest.php +++ b/vendor/symfony/yaml/Tests/InlineTest.php @@ -18,20 +18,25 @@ use Symfony\Component\Yaml\Yaml; class InlineTest extends TestCase { + protected function setUp() + { + Inline::initialize(0, 0); + } + /** * @dataProvider getTestsForParse */ - public function testParse($yaml, $value) + public function testParse($yaml, $value, $flags = 0) { - $this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml)); + $this->assertSame($value, Inline::parse($yaml, $flags), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml)); } /** * @dataProvider getTestsForParseWithMapObjects */ - public function testParseWithMapObjects($yaml, $value) + public function testParseWithMapObjects($yaml, $value, $flags = Yaml::PARSE_OBJECT_FOR_MAP) { - $actual = Inline::parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP); + $actual = Inline::parse($yaml, $flags); $this->assertSame(serialize($value), serialize($actual)); } @@ -49,10 +54,11 @@ class InlineTest extends TestCase public function getTestsForParsePhpConstants() { return array( - array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT), - array('!php/const:PHP_INT_MAX', PHP_INT_MAX), - array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)), - array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)), + array('!php/const Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT), + array('!php/const PHP_INT_MAX', PHP_INT_MAX), + array('[!php/const PHP_INT_MAX]', array(PHP_INT_MAX)), + array('{ foo: !php/const PHP_INT_MAX }', array('foo' => PHP_INT_MAX)), + array('!php/const NULL', null), ); } @@ -62,16 +68,37 @@ class InlineTest extends TestCase */ public function testParsePhpConstantThrowsExceptionWhenUndefined() { - Inline::parse('!php/const:WRONG_CONSTANT', Yaml::PARSE_CONSTANT); + Inline::parse('!php/const WRONG_CONSTANT', Yaml::PARSE_CONSTANT); } /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessageRegExp #The string "!php/const:PHP_INT_MAX" could not be parsed as a constant.*# + * @expectedExceptionMessageRegExp #The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*# */ public function testParsePhpConstantThrowsExceptionOnInvalidType() { - Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); + Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); + } + + /** + * @group legacy + * @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1. + * @dataProvider getTestsForParseLegacyPhpConstants + */ + public function testDeprecatedConstantTag($yaml, $expectedValue) + { + $this->assertSame($expectedValue, Inline::parse($yaml, Yaml::PARSE_CONSTANT)); + } + + public function getTestsForParseLegacyPhpConstants() + { + return array( + array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT), + array('!php/const:PHP_INT_MAX', PHP_INT_MAX), + array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)), + array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)), + array('!php/const:NULL', null), + ); } /** @@ -88,11 +115,11 @@ class InlineTest extends TestCase /** * @dataProvider getTestsForDump */ - public function testDump($yaml, $value) + public function testDump($yaml, $value, $parseFlags = 0) { $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml)); - $this->assertSame($value, Inline::parse(Inline::dump($value)), 'check consistency'); + $this->assertSame($value, Inline::parse(Inline::dump($value), $parseFlags), 'check consistency'); } public function testDumpNumericValueWithLocale() @@ -168,7 +195,7 @@ class InlineTest extends TestCase /** * @group legacy - * @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0. + * @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since Symfony 3.2 and will throw a ParseException in 4.0 on line 1. * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 */ public function testParseMappingKeyWithColonNotFollowedBySpace() @@ -256,7 +283,7 @@ class InlineTest extends TestCase /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessage A reference must contain at least one character. + * @expectedExceptionMessage A reference must contain at least one character at line 1. */ public function testParseUnquotedAsterisk() { @@ -265,7 +292,7 @@ class InlineTest extends TestCase /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessage A reference must contain at least one character. + * @expectedExceptionMessage A reference must contain at least one character at line 1. */ public function testParseUnquotedAsteriskFollowedByAComment() { @@ -274,11 +301,16 @@ class InlineTest extends TestCase /** * @dataProvider getReservedIndicators - * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar. */ public function testParseUnquotedScalarStartingWithReservedIndicator($indicator) { + if (method_exists($this, 'expectExceptionMessage')) { + $this->expectException(ParseException::class); + $this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator)); + } else { + $this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator)); + } + Inline::parse(sprintf('{ foo: %sfoo }', $indicator)); } @@ -289,11 +321,16 @@ class InlineTest extends TestCase /** * @dataProvider getScalarIndicators - * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar. */ public function testParseUnquotedScalarStartingWithScalarIndicator($indicator) { + if (method_exists($this, 'expectExceptionMessage')) { + $this->expectException(ParseException::class); + $this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator)); + } else { + $this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator)); + } + Inline::parse(sprintf('{ foo: %sfoo }', $indicator)); } @@ -304,7 +341,7 @@ class InlineTest extends TestCase /** * @group legacy - * @expectedDeprecation Not quoting the scalar "%bar " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0. + * @expectedDeprecation Not quoting the scalar "%bar " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0 on line 1. * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 */ public function testParseUnquotedScalarStartingWithPercentCharacter() @@ -385,8 +422,8 @@ class InlineTest extends TestCase array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')), // mappings - array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), - array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), + array('{foo: bar,bar: foo,"false": false, "null": null,integer: 12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), + array('{ foo : bar, bar : foo, "false" : false, "null" : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')), array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')), array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')), @@ -456,8 +493,8 @@ class InlineTest extends TestCase array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')), // mappings - array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), - array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)), + array('{foo: bar,bar: foo,"false": false,"null": null,integer: 12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), Yaml::PARSE_OBJECT_FOR_MAP), + array('{ foo : bar, bar : foo, "false" : false, "null" : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), Yaml::PARSE_OBJECT_FOR_MAP), array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')), array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')), array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', 'bar"' => 'foo: bar')), @@ -681,7 +718,7 @@ class InlineTest extends TestCase /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException - * @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}. + * @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported} at line 1. */ public function testNotSupportedMissingValue() { @@ -698,19 +735,82 @@ class InlineTest extends TestCase $this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']); } + /** + * @group legacy + * @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0 on line 1. + */ public function testOmittedMappingKeyIsParsedAsColon() { $this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}')); } - public function testBooleanMappingKeysAreConvertedToStrings() + /** + * @dataProvider getTestsForNullValues + */ + public function testParseMissingMappingValueAsNull($yaml, $expected) { - $this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}')); - $this->assertSame(array('true' => 'foo'), Inline::parse('{true: foo}')); + $this->assertSame($expected, Inline::parse($yaml)); + } + + public function getTestsForNullValues() + { + return array( + 'null before closing curly brace' => array('{foo:}', array('foo' => null)), + 'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')), + ); } public function testTheEmptyStringIsAValidMappingKey() { $this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }')); } + + /** + * @group legacy + * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1. + * @dataProvider getNotPhpCompatibleMappingKeyData + */ + public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected) + { + $this->assertSame($expected, Inline::parse($yaml)); + } + + /** + * @group legacy + * @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead. + * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1. + * @dataProvider getNotPhpCompatibleMappingKeyData + */ + public function testExplicitStringCastingOfMappingKeys($yaml, $expected) + { + $this->assertSame($expected, Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS)); + } + + public function getNotPhpCompatibleMappingKeyData() + { + return array( + 'boolean-true' => array('{true: "foo"}', array('true' => 'foo')), + 'boolean-false' => array('{false: "foo"}', array('false' => 'foo')), + 'null' => array('{null: "foo"}', array('null' => 'foo')), + 'float' => array('{0.25: "foo"}', array('0.25' => 'foo')), + ); + } + + /** + * @group legacy + * @expectedDeprecation Support for the !str tag is deprecated since Symfony 3.4. Use the !!str tag instead on line 1. + */ + public function testDeprecatedStrTag() + { + $this->assertSame(array('foo' => 'bar'), Inline::parse('{ foo: !str bar }')); + } + + /** + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Unexpected end of line, expected one of ",}" at line 1 (near "{abc: 'def'"). + */ + public function testUnfinishedInlineMap() + { + Inline::parse("{abc: 'def'"); + } }