update v 1.0.7.5
This commit is contained in:
170
vendor/symfony/yaml/Tests/ParserTest.php
vendored
170
vendor/symfony/yaml/Tests/ParserTest.php
vendored
@@ -422,11 +422,17 @@ EOF;
|
||||
public function testObjectSupportEnabled()
|
||||
{
|
||||
$input = <<<EOF
|
||||
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testObjectSupportEnabledPassingTrue()
|
||||
{
|
||||
$input = <<<EOF
|
||||
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
@@ -434,6 +440,18 @@ EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testObjectSupportEnabledWithDeprecatedTag()
|
||||
{
|
||||
$input = <<<EOF
|
||||
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
|
||||
bar: 1
|
||||
EOF;
|
||||
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDumpedObjectProvider
|
||||
*/
|
||||
@@ -446,6 +464,15 @@ EOF;
|
||||
* @dataProvider getObjectForMapTests
|
||||
*/
|
||||
public function testObjectForMap($yaml, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->parser->parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getObjectForMapTests
|
||||
*/
|
||||
public function testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->parser->parse($yaml, false, false, true));
|
||||
}
|
||||
@@ -519,7 +546,17 @@ YAML;
|
||||
*/
|
||||
public function testObjectsSupportDisabledWithExceptions($yaml)
|
||||
{
|
||||
$this->parser->parse($yaml, true, false);
|
||||
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider invalidDumpedObjectProvider
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
public function testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml)
|
||||
{
|
||||
$this->parser->parse($yaml, true);
|
||||
}
|
||||
|
||||
public function invalidDumpedObjectProvider()
|
||||
@@ -596,7 +633,7 @@ EOF;
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage Multiple documents are not supported.
|
||||
* @expectedExceptionMessageRegExp /^Multiple documents are not supported.+/
|
||||
*/
|
||||
public function testMultipleDocumentsNotSupportedException()
|
||||
{
|
||||
@@ -628,6 +665,34 @@ EOF
|
||||
);
|
||||
}
|
||||
|
||||
public function testSequenceInMappingStartedBySingleDashLine()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
a:
|
||||
-
|
||||
b:
|
||||
-
|
||||
bar: baz
|
||||
- foo
|
||||
d: e
|
||||
EOT;
|
||||
$expected = array(
|
||||
'a' => array(
|
||||
array(
|
||||
'b' => array(
|
||||
array(
|
||||
'bar' => 'baz',
|
||||
),
|
||||
),
|
||||
),
|
||||
'foo',
|
||||
),
|
||||
'd' => 'e',
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
@@ -977,6 +1042,7 @@ EOT
|
||||
foo
|
||||
# bar
|
||||
baz
|
||||
|
||||
EOT
|
||||
,
|
||||
),
|
||||
@@ -1005,7 +1071,7 @@ EOT;
|
||||
$expected = array(
|
||||
'foo' => array(
|
||||
'bar' => array(
|
||||
'scalar-block' => 'line1 line2>',
|
||||
'scalar-block' => "line1 line2>\n",
|
||||
),
|
||||
'baz' => array(
|
||||
'foobar' => null,
|
||||
@@ -1083,6 +1149,100 @@ EOT
|
||||
$this->parser->parse($yaml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getBinaryData
|
||||
*/
|
||||
public function testParseBinaryData($data)
|
||||
{
|
||||
$this->assertSame(array('data' => 'Hello world'), $this->parser->parse($data));
|
||||
}
|
||||
|
||||
public function getBinaryData()
|
||||
{
|
||||
return array(
|
||||
'enclosed with double quotes' => array('data: !!binary "SGVsbG8gd29ybGQ="'),
|
||||
'enclosed with single quotes' => array("data: !!binary 'SGVsbG8gd29ybGQ='"),
|
||||
'containing spaces' => array('data: !!binary "SGVs bG8gd 29ybGQ="'),
|
||||
'in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVsbG8gd29ybGQ=
|
||||
EOT
|
||||
),
|
||||
'containing spaces in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVs bG8gd 29ybGQ=
|
||||
EOT
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidBinaryData
|
||||
*/
|
||||
public function testParseInvalidBinaryData($data, $expectedMessage)
|
||||
{
|
||||
$this->setExpectedExceptionRegExp('\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
|
||||
|
||||
$this->parser->parse($data);
|
||||
}
|
||||
|
||||
public function getInvalidBinaryData()
|
||||
{
|
||||
return array(
|
||||
'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\)/'),
|
||||
'invalid characters' => array('!!binary "SGVsbG8#d29ybGQ="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'too many equals characters' => array('data: !!binary "SGVsbG8gd29yb==="', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'misplaced equals character' => array('data: !!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'),
|
||||
'length not a multiple of four in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVsbG8d29ybGQ=
|
||||
EOT
|
||||
,
|
||||
'/The normalized base64 encoded data \(data without whitespace characters\) length must be a multiple of four \(\d+ bytes given\)/',
|
||||
),
|
||||
'invalid characters in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVsbG8#d29ybGQ=
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
'too many equals characters in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVsbG8gd29yb===
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
'misplaced equals character in block scalar' => array(
|
||||
<<<EOT
|
||||
data: !!binary |
|
||||
SGVsbG8gd29ybG=Q
|
||||
EOT
|
||||
,
|
||||
'/The base64 encoded data \(.*\) contains invalid characters/',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseDateAsMappingValue()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
date: 2002-12-14
|
||||
EOT;
|
||||
$expectedDate = new \DateTime();
|
||||
$expectedDate->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expectedDate->setDate(2002, 12, 14);
|
||||
$expectedDate->setTime(0, 0, 0);
|
||||
|
||||
$this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
|
||||
}
|
||||
}
|
||||
|
||||
class B
|
||||
|
Reference in New Issue
Block a user