X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fsymfony%2Fyaml%2FTests%2FParserTest.php;h=4f0cf8866b935b68187389cbd79ae72259492b18;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=2c3a6e0b8f53f4b91bce129a47699952da409e09;hpb=eba34333e3c89f208d2f72fa91351ad019a71583;p=yaffs-website diff --git a/vendor/symfony/yaml/Tests/ParserTest.php b/vendor/symfony/yaml/Tests/ParserTest.php index 2c3a6e0b8..4f0cf8866 100644 --- a/vendor/symfony/yaml/Tests/ParserTest.php +++ b/vendor/symfony/yaml/Tests/ParserTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Yaml\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Parser; @@ -33,9 +34,34 @@ class ParserTest extends TestCase /** * @dataProvider getDataFormSpecifications */ - public function testSpecifications($file, $expected, $yaml, $comment) + public function testSpecifications($file, $expected, $yaml, $comment, $deprecated) { + $deprecations = array(); + + if ($deprecated) { + set_error_handler(function ($type, $msg) use (&$deprecations) { + if (E_USER_DEPRECATED !== $type) { + restore_error_handler(); + + if (class_exists('PHPUnit_Util_ErrorHandler')) { + return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); + } + + return call_user_func_array('PHPUnit\Util\ErrorHandler::handleError', func_get_args()); + } + + $deprecations[] = $msg; + }); + } + $this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment); + + if ($deprecated) { + restore_error_handler(); + + $this->assertCount(1, $deprecations); + $this->assertContains('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', $deprecations[0]); + } } public function getDataFormSpecifications() @@ -60,7 +86,7 @@ class ParserTest extends TestCase } else { eval('$expected = '.trim($test['php']).';'); - $tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']); + $tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test'], isset($test['deprecated']) ? $test['deprecated'] : false); } } } @@ -440,11 +466,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 @@ -452,6 +484,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 */ @@ -464,6 +508,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)); } @@ -537,7 +590,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() @@ -730,6 +793,7 @@ EOF * * @see http://yaml.org/spec/1.2/spec.html#id2759572 * @see http://yaml.org/spec/1.1/#id932806 + * @group legacy */ public function testMappingDuplicateKeyBlock() { @@ -749,6 +813,9 @@ EOD; $this->assertSame($expected, Yaml::parse($input)); } + /** + * @group legacy + */ public function testMappingDuplicateKeyFlow() { $input = <<<'EOD' @@ -763,6 +830,74 @@ EOD; $this->assertSame($expected, Yaml::parse($input)); } + /** + * @group legacy + * @dataProvider getParseExceptionOnDuplicateData + * @expectedDeprecation Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s. + * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 + */ + public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber) + { + Yaml::parse($input); + } + + public function getParseExceptionOnDuplicateData() + { + $tests = array(); + + $yaml = <<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 + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + */ + public function testParseInvalidBinaryData($data, $expectedMessage) + { + if (method_exists($this, 'expectException')) { + $this->expectExceptionMessageRegExp($expectedMessage); + } else { + $this->setExpectedExceptionRegExp(ParseException::class, $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)); + } + /** * @param $lineNumber * @param $yaml @@ -1221,6 +1454,32 @@ YAML ); } + public function testParseMultiLineQuotedString() + { + $yaml = <<assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml)); + } + + public function testParseMultiLineUnquotedString() + { + $yaml = <<assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml)); + } + public function testCanParseVeryLongValue() { $longStringWithSpaces = str_repeat('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ', 20000);