From efe23371dce1157be6a24c6045543b3a23b708a4 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 19 May 2017 09:52:04 +0200 Subject: [PATCH] [Yaml] remove deprecated features --- src/Symfony/Component/Yaml/CHANGELOG.md | 21 +++ src/Symfony/Component/Yaml/Dumper.php | 30 ---- src/Symfony/Component/Yaml/Inline.php | 117 +++---------- src/Symfony/Component/Yaml/Parser.php | 53 +----- .../Component/Yaml/Tests/DumperTest.php | 66 ------- .../Fixtures/YtsSpecificationExamples.yml | 38 ---- .../Yaml/Tests/Fixtures/YtsTypeTransfers.yml | 42 ----- .../Fixtures/legacyBooleanMappingKeys.yml | 23 --- .../Tests/Fixtures/legacyNonStringKeys.yml | 2 - .../Tests/Fixtures/legacyNullMappingKey.yml | 9 - .../Component/Yaml/Tests/InlineTest.php | 65 ++----- .../Component/Yaml/Tests/ParserTest.php | 162 ++++-------------- src/Symfony/Component/Yaml/Yaml.php | 44 ----- 13 files changed, 89 insertions(+), 583 deletions(-) delete mode 100644 src/Symfony/Component/Yaml/Tests/Fixtures/legacyBooleanMappingKeys.yml delete mode 100644 src/Symfony/Component/Yaml/Tests/Fixtures/legacyNonStringKeys.yml delete mode 100644 src/Symfony/Component/Yaml/Tests/Fixtures/legacyNullMappingKey.yml diff --git a/src/Symfony/Component/Yaml/CHANGELOG.md b/src/Symfony/Component/Yaml/CHANGELOG.md index b44b93892a..e1c04c1042 100644 --- a/src/Symfony/Component/Yaml/CHANGELOG.md +++ b/src/Symfony/Component/Yaml/CHANGELOG.md @@ -1,6 +1,27 @@ CHANGELOG ========= +4.0.0 +----- + + * complex mappings will throw a `ParseException` + * support for the comma as a group separator for floats has been dropped, use + the underscore instead + * support for the `!!php/object` tag has been dropped, use the `!php/object` + tag instead + * duplicate mapping keys throw a `ParseException` + * non-string mapping keys throw a `ParseException`, use the `Yaml::PARSE_KEYS_AS_STRINGS` + flag to cast them to strings + * `%` at the beginning of an unquoted string throw a `ParseException` + * mappings with a colon (`:`) that is not followed by a whitespace throw a + `ParseException` + * the `Dumper::setIndentation()` method has been removed + * being able to pass boolean options to the `Yaml::parse()`, `Yaml::dump()`, + `Parser::parse()`, and `Dumper::dump()` methods to configure the behavior of + the parser and dumper is no longer supported, pass bitmask flags instead + * the constructor arguments of the `Parser` class have been removed + * the `Inline` class is internal and no longer part of the BC promise + 3.3.0 ----- diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index a38bce0142..4a6df6a892 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -37,18 +37,6 @@ class Dumper $this->indentation = $indentation; } - /** - * Sets the indentation. - * - * @param int $num The amount of spaces to use for indentation of nested nodes - */ - public function setIndentation($num) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED); - - $this->indentation = (int) $num; - } - /** * Dumps a PHP value to YAML. * @@ -61,24 +49,6 @@ class Dumper */ public function dump($input, $inline = 0, $indent = 0, $flags = 0) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 5) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(4)) { - $flags |= Yaml::DUMP_OBJECT; - } - } - $output = ''; $prefix = $indent ? str_repeat(' ', $indent) : ''; $dumpObjectAsInlineMap = true; diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 1004034486..ee2608e629 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -46,38 +46,6 @@ class Inline */ public static function parse($value, $flags = 0, $references = array()) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 3 && !is_array($references)) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED); - - if ($references) { - $flags |= Yaml::PARSE_OBJECT; - } - - if (func_num_args() >= 4) { - @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(3)) { - $flags |= Yaml::PARSE_OBJECT_FOR_MAP; - } - } - - if (func_num_args() >= 5) { - $references = func_get_arg(4); - } else { - $references = array(); - } - } - self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags); self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags); self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags); @@ -137,24 +105,6 @@ class Inline */ public static function dump($value, $flags = 0) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 3) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(2)) { - $flags |= Yaml::DUMP_OBJECT; - } - } - switch (true) { case is_resource($value): if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) { @@ -300,7 +250,7 @@ class Inline * * @internal */ - public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array(), $legacyOmittedKeySupport = false) + public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array()) { if (in_array($scalar[$i], array('"', "'"))) { // quoted scalar @@ -322,7 +272,7 @@ class Inline if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) { $output = substr($output, 0, $match[0][1]); } - } elseif (Parser::preg_match('/^(.'.($legacyOmittedKeySupport ? '+' : '*').'?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { + } elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { $output = $match[1]; $i += strlen($output); } else { @@ -330,14 +280,10 @@ class Inline } // a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >) - if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) { + if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0] || '%' === $output[0])) { throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0])); } - if ($output && '%' === $output[0]) { - @trigger_error(sprintf('Not quoting the scalar "%s" starting with the "%%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $output), E_USER_DEPRECATED); - } - if ($evaluate) { $output = self::evaluateScalar($output, $flags, $references); } @@ -479,26 +425,27 @@ class Inline } // key - $key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array(), true); + $offsetBeforeKeyParsing = $i; + $key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array()); - if (':' !== $key && false === $i = strpos($mapping, ':', $i)) { - break; + if ($offsetBeforeKeyParsing === $i) { + throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping); } - if (':' === $key) { - @trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED); + if (false === $i = strpos($mapping, ':', $i)) { + break; } if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags)) { $evaluatedKey = self::evaluateScalar($key, $flags, $references); if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey)) { - @trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED); + throw new ParseException('Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings.', self::$parsedLineNumber + 1, $mapping); } } - if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) { - @trigger_error('Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED); + if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) { + throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping); } while ($i < $len) { @@ -509,7 +456,6 @@ class Inline } $tag = self::parseTag($mapping, $i, $flags); - $duplicate = false; switch ($mapping[$i]) { case '[': // nested sequence @@ -518,8 +464,7 @@ class Inline // Parser cannot abort this mapping earlier, since lines // are processed sequentially. if (isset($output[$key])) { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED); - $duplicate = true; + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping); } break; case '{': @@ -529,8 +474,7 @@ class Inline // Parser cannot abort this mapping earlier, since lines // are processed sequentially. if (isset($output[$key])) { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED); - $duplicate = true; + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping); } break; default: @@ -539,19 +483,17 @@ class Inline // Parser cannot abort this mapping earlier, since lines // are processed sequentially. if (isset($output[$key])) { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED); - $duplicate = true; + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping); } --$i; } - if (!$duplicate) { - if (null !== $tag) { - $output[$key] = new TaggedValue($tag, $value); - } else { - $output[$key] = $value; - } + if (null !== $tag) { + $output[$key] = new TaggedValue($tag, $value); + } else { + $output[$key] = $value; } + ++$i; continue 2; @@ -620,18 +562,6 @@ class Inline throw new ParseException('Object support when parsing a YAML file has been disabled.'); } - return; - case 0 === strpos($scalar, '!!php/object:'): - if (self::$objectSupport) { - @trigger_error('The !!php/object tag to indicate dumped PHP objects is deprecated since version 3.1 and will be removed in 4.0. Use the !php/object tag instead.', E_USER_DEPRECATED); - - return unserialize(substr($scalar, 13)); - } - - if (self::$exceptionOnInvalidType) { - throw new ParseException('Object support when parsing a YAML file has been disabled.'); - } - return; case 0 === strpos($scalar, '!php/const:'): if (self::$constantSupport) { @@ -680,13 +610,8 @@ class Inline return -log(0); case '-.inf' === $scalarLower: return log(0); - case Parser::preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar): case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar): - if (false !== strpos($scalar, ',')) { - @trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED); - } - - return (float) str_replace(array(',', '_'), '', $scalar); + return (float) str_replace('_', '', $scalar); case Parser::preg_match(self::getTimestampRegex(), $scalar): if (Yaml::PARSE_DATETIME & $flags) { // When no timezone is provided in the parsed date, YAML spec says we must assume UTC. diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index dcedd899bc..d939facf23 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -33,21 +33,6 @@ class Parser private $skippedLineNumbers = array(); private $locallySkippedLineNumbers = array(); - public function __construct() - { - if (func_num_args() > 0) { - @trigger_error(sprintf('The constructor arguments $offset, $totalNumberOfLines, $skippedLineNumbers of %s are deprecated and will be removed in 4.0', self::class), E_USER_DEPRECATED); - - $this->offset = func_get_arg(0); - if (func_num_args() > 1) { - $this->totalNumberOfLines = func_get_arg(1); - } - if (func_num_args() > 2) { - $this->skippedLineNumbers = func_get_arg(2); - } - } - } - /** * Parses a YAML string to a PHP value. * @@ -60,32 +45,6 @@ class Parser */ public function parse($value, $flags = 0) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 3) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(2)) { - $flags |= Yaml::PARSE_OBJECT; - } - } - - if (func_num_args() >= 4) { - @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(3)) { - $flags |= Yaml::PARSE_OBJECT_FOR_MAP; - } - } - if (false === preg_match('//u', $value)) { throw new ParseException('The YAML value does not appear to be valid UTF-8.'); } @@ -178,7 +137,7 @@ class Parser } if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) { - @trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED); + throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } // array @@ -230,7 +189,7 @@ class Parser } if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key)) { - @trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED); + throw new ParseException('Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } // Convert float keys to strings, to avoid being converted to integers by PHP @@ -304,7 +263,7 @@ class Parser $data[$key] = null; } } else { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED); + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); } } else { // remember the parsed line number here in case we need it to provide some contexts in error messages below @@ -319,7 +278,7 @@ class Parser $data[$key] = $value; } } else { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $realCurrentLineNbKey + 1), E_USER_DEPRECATED); + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $realCurrentLineNbKey + 1, $this->currentLine); } } } else { @@ -329,7 +288,7 @@ class Parser if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } else { - @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED); + throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); } } if ($isRef) { @@ -342,7 +301,7 @@ class Parser } if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) { - @trigger_error('Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', E_USER_DEPRECATED); + throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } // 1-liner optionally followed by newline(s) diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 1c80bec650..b6648d8ce7 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -77,35 +77,6 @@ EOF; $this->assertEquals($expected, $dumper->dump($this->array, 4, 0)); } - /** - * @group legacy - */ - public function testSetIndentation() - { - $this->dumper->setIndentation(7); - - $expected = <<<'EOF' -'': bar -foo: '#bar' -'foo''bar': { } -bar: - - 1 - - foo -foobar: - foo: bar - bar: - - 1 - - foo - foobar: - foo: bar - bar: - - 1 - - foo - -EOF; - $this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0)); - } - public function testSpecifications() { $files = $this->parser->parse(file_get_contents($this->path.'/index.yml')); @@ -213,16 +184,6 @@ EOF; $this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects'); } - /** - * @group legacy - */ - public function testObjectSupportEnabledPassingTrue() - { - $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true); - - $this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects'); - } - public function testObjectSupportDisabledButNoExceptions() { $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1)); @@ -238,33 +199,6 @@ EOF; $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE); } - /** - * @group legacy - * @expectedException \Symfony\Component\Yaml\Exception\DumpException - */ - public function testObjectSupportDisabledWithExceptionsPassingTrue() - { - $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true); - } - - public function testEmptyArray() - { - $dump = $this->dumper->dump(array()); - $this->assertEquals('{ }', $dump); - - $dump = $this->dumper->dump(array(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); - $this->assertEquals('[]', $dump); - - $dump = $this->dumper->dump(array(), 9, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); - $this->assertEquals('[]', $dump); - - $dump = $this->dumper->dump(new \ArrayObject(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP); - $this->assertEquals('{ }', $dump); - - $dump = $this->dumper->dump(new \stdClass(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP); - $this->assertEquals('{ }', $dump); - } - /** * @dataProvider getEscapeSequences */ diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml index 45e27b7b74..6776d3e833 100644 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml @@ -518,16 +518,6 @@ php: | 'hexadecimal' => 0xC ) --- -test: Decimal Integer -deprecated: true -spec: 2.19 -yaml: | - decimal: +12,345 -php: | - array( - 'decimal' => 12345.0, - ) ---- # FIX: spec shows parens around -inf and NaN test: Floating point spec: 2.20 @@ -546,16 +536,6 @@ php: | 'float as whole number' => (float) 1 ) --- -test: Fixed Floating point -deprecated: true -spec: 2.20 -yaml: | - fixed: 1,230.15 -php: | - array( - 'fixed' => 1230.15, - ) ---- test: Timestamps todo: true spec: 2.22 @@ -1530,24 +1510,6 @@ php: | 'hexadecimal' => 12 ) --- -test: Decimal -deprecated: true -yaml: | - decimal: +12,345 -php: | - array( - 'decimal' => 12345.0, - ) ---- -test: Fixed Float -deprecated: true -yaml: | - fixed: 1,230.15 -php: | - array( - 'fixed' => 1230.15, - ) ---- test: Float yaml: | canonical: 1.23015e+3 diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml index 5b9df73be1..185e4ef58c 100644 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml @@ -182,34 +182,6 @@ php: | 'simple' => 12, ) --- -test: Positive Big Integer -deprecated: true -dump_skip: true -brief: > - An integer is a series of numbers, optionally - starting with a positive or negative sign. Integers - may also contain commas for readability. -yaml: | - one-thousand: 1,000 -php: | - array( - 'one-thousand' => 1000.0, - ) ---- -test: Negative Big Integer -deprecated: true -dump_skip: true -brief: > - An integer is a series of numbers, optionally - starting with a positive or negative sign. Integers - may also contain commas for readability. -yaml: | - negative one-thousand: -1,000 -php: | - array( - 'negative one-thousand' => -1000.0 - ) ---- test: Floats dump_skip: true brief: > @@ -225,20 +197,6 @@ php: | 'scientific notation' => 1000.09 ) --- -test: Larger Float -dump_skip: true -deprecated: true -brief: > - Floats are represented by numbers with decimals, - allowing for scientific notation, as well as - positive and negative infinity and "not a number." -yaml: | - larger float: 1,000.09 -php: | - array( - 'larger float' => 1000.09, - ) ---- test: Time todo: true brief: > diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyBooleanMappingKeys.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/legacyBooleanMappingKeys.yml deleted file mode 100644 index 5e8d091707..0000000000 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyBooleanMappingKeys.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- %YAML:1.0 -test: Miscellaneous -spec: 2.21 -yaml: | - true: true - false: false -php: | - array( - 1 => true, - 0 => false, - ) ---- -test: Boolean -yaml: | - false: used as key - logical: true - answer: false -php: | - array( - false => 'used as key', - 'logical' => true, - 'answer' => false - ) diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNonStringKeys.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNonStringKeys.yml deleted file mode 100644 index 4e28201856..0000000000 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNonStringKeys.yml +++ /dev/null @@ -1,2 +0,0 @@ -- legacyBooleanMappingKeys -- legacyNullMappingKey diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNullMappingKey.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNullMappingKey.yml deleted file mode 100644 index 551a6205e1..0000000000 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/legacyNullMappingKey.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- %YAML:1.0 -test: Miscellaneous -spec: 2.21 -yaml: | - null: ~ -php: | - array( - '' => null, - ) diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index a26ffbf9e4..56a3866232 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -74,17 +74,6 @@ class InlineTest extends TestCase Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } - /** - * @group legacy - * @dataProvider getTestsForParseWithMapObjects - */ - public function testParseWithMapObjectsPassingTrue($yaml, $value) - { - $actual = Inline::parse($yaml, false, false, true); - - $this->assertSame(serialize($value), serialize($actual)); - } - /** * @dataProvider getTestsForDump */ @@ -167,13 +156,12 @@ class InlineTest extends TestCase } /** - * @group legacy - * @expectedDeprecation Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0. - * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}") */ public function testParseMappingKeyWithColonNotFollowedBySpace() { - Inline::parse('{1:""}'); + Inline::parse('{foo:""}'); } /** @@ -208,15 +196,6 @@ class InlineTest extends TestCase $this->assertSame($expected, Inline::parse($yaml, 0, array('var' => 'var-value'))); } - /** - * @group legacy - * @dataProvider getDataForParseReferences - */ - public function testParseReferencesAsFifthArgument($yaml, $expected) - { - $this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value'))); - } - public function getDataForParseReferences() { return array( @@ -241,19 +220,6 @@ class InlineTest extends TestCase $this->assertSame(array($foo), Inline::parse('[*foo]', 0, array('foo' => $foo))); } - /** - * @group legacy - */ - public function testParseMapReferenceInSequenceAsFifthArgument() - { - $foo = array( - 'a' => 'Steve', - 'b' => 'Clark', - 'c' => 'Brian', - ); - $this->assertSame(array($foo), Inline::parse('[*foo]', false, false, false, array('foo' => $foo))); - } - /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException * @expectedExceptionMessage A reference must contain at least one character. @@ -299,17 +265,7 @@ class InlineTest extends TestCase public function getScalarIndicators() { - return array(array('|'), array('>')); - } - - /** - * @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. - * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 - */ - public function testParseUnquotedScalarStartingWithPercentCharacter() - { - Inline::parse('{ foo: %bar }'); + return array(array('|'), array('>'), array('%')); } /** @@ -695,12 +651,12 @@ class InlineTest extends TestCase } /** - * @group legacy - * @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Missing mapping key */ - public function testOmittedMappingKeyIsParsedAsColon() + public function testMappingKeysCannotBeOmitted() { - $this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}')); + Inline::parse('{: foo}'); } /** @@ -725,8 +681,9 @@ class InlineTest extends TestCase } /** - * @group legacy - * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings + * * @dataProvider getNotPhpCompatibleMappingKeyData */ public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected) diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index f64d7589d8..f52921d986 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -35,34 +35,9 @@ class ParserTest extends TestCase /** * @dataProvider getDataFormSpecifications */ - public function testSpecifications($expected, $yaml, $comment, $deprecated) + public function testSpecifications($expected, $yaml, $comment) { - $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() @@ -83,20 +58,6 @@ class ParserTest extends TestCase return $this->loadTestsFromFixtureFiles('nonStringKeys.yml'); } - /** - * @group legacy - * @dataProvider getLegacyNonStringMappingKeysData - */ - public function testLegacyNonStringMappingKeys($expected, $yaml, $comment) - { - $this->assertSame($expected, var_export($this->parser->parse($yaml), true), $comment); - } - - public function getLegacyNonStringMappingKeysData() - { - return $this->loadTestsFromFixtureFiles('legacyNonStringKeys.yml'); - } - public function testTabsInYaml() { // test tabs in YAML @@ -475,35 +436,13 @@ EOF; $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() + public function testObjectSupportDisabledButNoExceptions() { $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\Tests\Component\Yaml\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'); - } - /** - * @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 - */ - public function testObjectSupportDisabledButNoExceptions($input) - { $this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects'); } @@ -521,15 +460,6 @@ EOF; $this->assertEquals($expected, $this->parser->parse($yaml, $flags)); } - /** - * @group legacy - * @dataProvider getObjectForMapTests - */ - public function testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected) - { - $this->assertEquals($expected, $this->parser->parse($yaml, false, false, true)); - } - public function getObjectForMapTests() { $tests = array(); @@ -594,11 +524,15 @@ YAML; } /** - * @dataProvider invalidDumpedObjectProvider * @expectedException \Symfony\Component\Yaml\Exception\ParseException */ - public function testObjectsSupportDisabledWithExceptions($yaml) + public function testObjectsSupportDisabledWithExceptions() { + $yaml = <<<'EOF' +foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} +bar: 1 +EOF; + $this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } @@ -613,33 +547,6 @@ YAML; $this->assertSame($expected, $this->parser->parse($yaml)); } - /** - * @group legacy - * @dataProvider invalidDumpedObjectProvider - * @expectedException \Symfony\Component\Yaml\Exception\ParseException - */ - public function testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml) - { - $this->parser->parse($yaml, true); - } - - public function invalidDumpedObjectProvider() - { - $yamlTag = <<<'EOF' -foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} -bar: 1 -EOF; - $localTag = <<<'EOF' -foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} -bar: 1 -EOF; - - return array( - 'yaml-tag' => array($yamlTag), - 'local-tag' => array($localTag), - ); - } - /** * @requires extension iconv */ @@ -805,6 +712,9 @@ EOF } /** + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Duplicate key "child" detected + * * > It is an error for two equal keys to appear in the same mapping node. * > In such a case the YAML processor may continue, ignoring the second * > `key: value` pair and issuing an appropriate warning. This strategy @@ -813,7 +723,6 @@ EOF * * @see http://yaml.org/spec/1.2/spec.html#id2759572 * @see http://yaml.org/spec/1.1/#id932806 - * @group legacy */ public function testMappingDuplicateKeyBlock() { @@ -834,7 +743,8 @@ EOD; } /** - * @group legacy + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Duplicate key "child" detected */ public function testMappingDuplicateKeyFlow() { @@ -851,13 +761,13 @@ EOD; } /** - * @group legacy + * @expectedException \Symfony\Component\Yaml\Exception\ParseException * @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) { + $this->expectExceptionMessage(sprintf('Duplicate key "%s" detected at line %d', $duplicateKey, $lineNumber)); + Yaml::parse($input); } @@ -1080,8 +990,8 @@ EOF; } /** - * @group legacy - * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings */ public function testFloatKeys() { @@ -1091,19 +1001,12 @@ foo: 1.3: "baz" EOF; - $expected = array( - 'foo' => array( - '1.2' => 'bar', - '1.3' => 'baz', - ), - ); - - $this->assertEquals($expected, $this->parser->parse($yaml)); + $this->parser->parse($yaml); } /** - * @group legacy - * @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Non-string mapping keys are not supported. Pass the Yaml::PARSE_KEYS_AS_STRINGS flag to cast them to strings */ public function testBooleanKeys() { @@ -1112,12 +1015,7 @@ true: foo false: bar EOF; - $expected = array( - 1 => 'foo', - 0 => 'bar', - ); - - $this->assertEquals($expected, $this->parser->parse($yaml)); + $this->parser->parse($yaml); } public function testExplicitStringCastingOfFloatKeys() @@ -1653,8 +1551,8 @@ YAML } /** - * @group legacy - * @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Complex mappings are not supported at line 1 (near "? "1""). */ public function testComplexMappingThrowsParseException() { @@ -1668,8 +1566,8 @@ YAML; } /** - * @group legacy - * @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Complex mappings are not supported at line 2 (near "? "1""). */ public function testComplexMappingNestedInMappingThrowsParseException() { @@ -1684,8 +1582,8 @@ YAML; } /** - * @group legacy - * @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Complex mappings are not supported at line 1 (near "- ? "1""). */ public function testComplexMappingNestedInSequenceThrowsParseException() { @@ -1734,7 +1632,7 @@ INI; } else { eval('$expected = '.trim($test['php']).';'); - $tests[] = array(var_export($expected, true), $test['yaml'], $test['test'], isset($test['deprecated']) ? $test['deprecated'] : false); + $tests[] = array(var_export($expected, true), $test['yaml'], $test['test']); } } } diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index 84f749b560..168d0b7552 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -51,32 +51,6 @@ class Yaml */ public static function parse($input, $flags = 0) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = self::PARSE_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 3) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the PARSE_OBJECT flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(2)) { - $flags |= self::PARSE_OBJECT; - } - } - - if (func_num_args() >= 4) { - @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(3)) { - $flags |= self::PARSE_OBJECT_FOR_MAP; - } - } - $yaml = new Parser(); return $yaml->parse($input, $flags); @@ -97,24 +71,6 @@ class Yaml */ public static function dump($input, $inline = 2, $indent = 4, $flags = 0) { - if (is_bool($flags)) { - @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED); - - if ($flags) { - $flags = self::DUMP_EXCEPTION_ON_INVALID_TYPE; - } else { - $flags = 0; - } - } - - if (func_num_args() >= 5) { - @trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED); - - if (func_get_arg(4)) { - $flags |= self::DUMP_OBJECT; - } - } - $yaml = new Dumper($indent); return $yaml->dump($input, $inline, 0, $flags);