From 351423dd34cb45ce01d37628aecbfdaa154dfcad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 01/14] Allow Symfony ^8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2ceac946..8f31f2e4 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "symfony/console": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4" From d7e10e65a6401f75c8f2b70ae9345838016d2962 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 17:50:55 +0200 Subject: [PATCH 02/14] Bump Symfony 8 to PHP >= 8.4 --- composer.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 8f31f2e4..bddc41d3 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,12 @@ } ], "require": { - "php": ">=8.2", + "php": ">=8.4", "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "symfony/console": "^6.4|^7.0|^8.0" - }, - "conflict": { - "symfony/console": "<6.4" + "symfony/console": "^7.4|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" }, From 11c4807e059985b96fa509510c8e9a1ae044f72c Mon Sep 17 00:00:00 2001 From: HypeMC Date: Mon, 9 Jun 2025 17:40:54 +0200 Subject: [PATCH 03/14] [Console] Simplify using invokable commands when the component is used standalone --- Resources/bin/yaml-lint | 9 +++++++-- Tests/Command/LintCommandTest.php | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Resources/bin/yaml-lint b/Resources/bin/yaml-lint index 143869e0..eca04976 100755 --- a/Resources/bin/yaml-lint +++ b/Resources/bin/yaml-lint @@ -42,8 +42,13 @@ if (!class_exists(Application::class)) { exit(1); } -(new Application())->add($command = new LintCommand()) - ->getApplication() +$command = new LintCommand(); +if (method_exists($app = new Application(), 'addCommand')) { + $app->addCommand($command); +} else { + $app->add($command); +} +$app ->setDefaultCommand($command->getName(), true) ->run() ; diff --git a/Tests/Command/LintCommandTest.php b/Tests/Command/LintCommandTest.php index a501f48d..856f82ca 100644 --- a/Tests/Command/LintCommandTest.php +++ b/Tests/Command/LintCommandTest.php @@ -180,7 +180,12 @@ private function createFile($content): string protected function createCommand(): Command { $application = new Application(); - $application->add(new LintCommand()); + $command = new LintCommand(); + if (method_exists($application, 'addCommand')) { + $application->addCommand($command); + } else { + $application->add($command); + } return $application->find('lint:yaml'); } From 0a91a695676044fca580ad4b16a715f5d73408f3 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Fri, 13 Jun 2025 02:20:31 +0200 Subject: [PATCH 04/14] [Console][FrameworkBundle] Remove deprecated `Application::add()` methods --- Resources/bin/yaml-lint | 9 ++------- Tests/Command/LintCommandTest.php | 7 +------ composer.json | 3 +++ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Resources/bin/yaml-lint b/Resources/bin/yaml-lint index eca04976..19bf58e1 100755 --- a/Resources/bin/yaml-lint +++ b/Resources/bin/yaml-lint @@ -42,13 +42,8 @@ if (!class_exists(Application::class)) { exit(1); } -$command = new LintCommand(); -if (method_exists($app = new Application(), 'addCommand')) { - $app->addCommand($command); -} else { - $app->add($command); -} -$app +(new Application())->addCommand($command = new LintCommand()) + ->getApplication() ->setDefaultCommand($command->getName(), true) ->run() ; diff --git a/Tests/Command/LintCommandTest.php b/Tests/Command/LintCommandTest.php index 856f82ca..9aa76876 100644 --- a/Tests/Command/LintCommandTest.php +++ b/Tests/Command/LintCommandTest.php @@ -180,12 +180,7 @@ private function createFile($content): string protected function createCommand(): Command { $application = new Application(); - $command = new LintCommand(); - if (method_exists($application, 'addCommand')) { - $application->addCommand($command); - } else { - $application->add($command); - } + $application->addCommand(new LintCommand()); return $application->find('lint:yaml'); } diff --git a/composer.json b/composer.json index bddc41d3..1164b7de 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,9 @@ "require-dev": { "symfony/console": "^7.4|^8.0" }, + "conflict": { + "symfony/console": "<7.4" + }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" }, "exclude-from-classmap": [ From 9a57423cd845620fe5e161c589ef5dd62242332d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 20 Jun 2025 14:56:25 +0200 Subject: [PATCH 05/14] raise a parse error for duplicate keys --- CHANGELOG.md | 5 +++++ Parser.php | 6 +++--- Tests/ParserTest.php | 7 +------ composer.json | 1 - 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 364bf66d..054d262e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + + * Remove support for parsing duplicate mapping keys whose value is `null` + 7.3 --- diff --git a/Parser.php b/Parser.php index be589082..a8b741bc 100644 --- a/Parser.php +++ b/Parser.php @@ -301,7 +301,7 @@ private function doParse(string $value, int $flags): mixed // But overwriting is allowed when a merge node is used in current block. if ($allowOverwrite || !isset($data[$key])) { if (!$allowOverwrite && \array_key_exists($key, $data)) { - trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1); + throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); } if (null !== $subTag) { @@ -326,7 +326,7 @@ private function doParse(string $value, int $flags): mixed $data += $value; } elseif ($allowOverwrite || !isset($data[$key])) { if (!$allowOverwrite && \array_key_exists($key, $data)) { - trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1); + throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); } // Spec: Keys MUST be unique; first one wins. @@ -346,7 +346,7 @@ private function doParse(string $value, int $flags): mixed // But overwriting is allowed when a merge node is used in current block. if ($allowOverwrite || !isset($data[$key])) { if (!$allowOverwrite && \array_key_exists($key, $data)) { - trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1); + throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); } $data[$key] = $value; diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index 836ec23f..d127c4a4 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -20,8 +20,6 @@ class ParserTest extends TestCase { - use ExpectUserDeprecationMessageTrait; - private ?Parser $parser; protected function setUp(): void @@ -1059,12 +1057,9 @@ public static function getParseExceptionOnDuplicateData() return $tests; } - /** - * @group legacy - */ public function testNullAsDuplicatedData() { - $this->expectUserDeprecationMessage('Since symfony/yaml 7.2: Duplicate key "child" detected on line 4 whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.'); + $this->expectException(ParseException::class); $yaml = <<=8.4", - "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "^1.8" }, "require-dev": { From 2dce389812df04fac08a1dd2769ed8dffb36debd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Jul 2025 11:08:29 +0200 Subject: [PATCH 06/14] Various CS fixes --- Inline.php | 2 +- Tests/DumperTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Inline.php b/Inline.php index 3a0889a5..1c9fa609 100644 --- a/Inline.php +++ b/Inline.php @@ -243,7 +243,7 @@ private static function dumpArray(array $value, int $flags): string private static function dumpHashArray(array|\ArrayObject|\stdClass $value, int $flags): string { $output = []; - $keyFlags = $flags &~ Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES; + $keyFlags = $flags & ~Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES; foreach ($value as $key => $val) { if (\is_int($key) && Yaml::DUMP_NUMERIC_KEY_AS_STRING & $flags) { $key = (string) $key; diff --git a/Tests/DumperTest.php b/Tests/DumperTest.php index e937336c..8eac4aee 100644 --- a/Tests/DumperTest.php +++ b/Tests/DumperTest.php @@ -946,7 +946,7 @@ public static function getForceQuotesOnValuesData(): iterable ]; yield 'backslash' => [ - ['foo' => "back\\slash"], + ['foo' => 'back\\slash'], '{ foo: "back\\\\slash" }', ]; From 1489d1b10e9800d3bd819b527023d96c719f3fc8 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Sat, 12 Jul 2025 15:55:19 +0200 Subject: [PATCH 07/14] optimize `in_array` calls --- Command/LintCommand.php | 2 +- Escaper.php | 2 +- Parser.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Command/LintCommand.php b/Command/LintCommand.php index 0fab77c5..4cee8c14 100644 --- a/Command/LintCommand.php +++ b/Command/LintCommand.php @@ -224,7 +224,7 @@ private function getFiles(string $fileOrDirectory): iterable } foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) { - if (!\in_array($file->getExtension(), ['yml', 'yaml'])) { + if (!\in_array($file->getExtension(), ['yml', 'yaml'], true)) { continue; } diff --git a/Escaper.php b/Escaper.php index 8cc492c5..921d62ff 100644 --- a/Escaper.php +++ b/Escaper.php @@ -76,7 +76,7 @@ public static function requiresSingleQuoting(string $value): bool { // Determines if a PHP value is entirely composed of a value that would // require single quoting in YAML. - if (\in_array(strtolower($value), ['null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'])) { + if (\in_array(strtolower($value), ['null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'], true)) { return true; } diff --git a/Parser.php b/Parser.php index be589082..fe54a1f2 100644 --- a/Parser.php +++ b/Parser.php @@ -198,7 +198,7 @@ private function doParse(string $value, int $flags): mixed } } elseif ( self::preg_match('#^(?P(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{!].*?)) *\:(( |\t)++(?P.+))?$#u', rtrim($this->currentLine), $values) - && (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"])) + && (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"], true)) ) { if ($context && 'sequence' == $context) { throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename); From 9d349597c27ce57842c4686079497be88382c68e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 22 Jul 2025 10:26:05 +0200 Subject: [PATCH 08/14] clean up remaining ExpectUserDeprecationMessageTrait usages --- Tests/ParserTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index d127c4a4..9c4e69b2 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Yaml\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Tag\TaggedValue; From d125114d2483880d7eed5647c545a46c49ed6425 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 24 Jul 2025 14:45:41 +0200 Subject: [PATCH 09/14] Fix typos --- Tests/Fixtures/YtsSpecificationExamples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Fixtures/YtsSpecificationExamples.yml b/Tests/Fixtures/YtsSpecificationExamples.yml index 2acc4998..ad128429 100644 --- a/Tests/Fixtures/YtsSpecificationExamples.yml +++ b/Tests/Fixtures/YtsSpecificationExamples.yml @@ -365,7 +365,7 @@ syck: | --- -test: Literal perserves newlines +test: Literal preserves newlines todo: true spec: 2.13 yaml: | From 55c352ae835db53d1c2b558e638c440b0ce71b02 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Oct 2024 11:06:51 +0200 Subject: [PATCH 10/14] run tests using PHPUnit 11.5 --- Tests/ParserTest.php | 10 ++++------ phpunit.xml.dist | 11 ++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index 836ec23f..eb46c69f 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -11,8 +11,9 @@ namespace Symfony\Component\Yaml\Tests; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Tag\TaggedValue; @@ -20,8 +21,6 @@ class ParserTest extends TestCase { - use ExpectUserDeprecationMessageTrait; - private ?Parser $parser; protected function setUp(): void @@ -1059,9 +1058,8 @@ public static function getParseExceptionOnDuplicateData() return $tests; } - /** - * @group legacy - */ + #[IgnoreDeprecations] + #[Group('legacy')] public function testNullAsDuplicatedData() { $this->expectUserDeprecationMessage('Since symfony/yaml 7.2: Duplicate key "child" detected on line 4 whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.'); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3dc41d45..e1f4cbc8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + + From 87c204a5a095099c283274d495cf7c63fcc1d2c9 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 31 Jul 2025 14:36:46 +0200 Subject: [PATCH 11/14] replace PHPUnit annotations with attributes --- Tests/Command/LintCommandTest.php | 5 +- Tests/DumperTest.php | 25 +++----- Tests/InlineTest.php | 101 ++++++++---------------------- Tests/ParserTest.php | 82 +++++++----------------- 4 files changed, 57 insertions(+), 156 deletions(-) diff --git a/Tests/Command/LintCommandTest.php b/Tests/Command/LintCommandTest.php index 856f82ca..5b586ba0 100644 --- a/Tests/Command/LintCommandTest.php +++ b/Tests/Command/LintCommandTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Yaml\Tests\Command; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -152,9 +153,7 @@ public function testLintFileNotReadable() $tester->execute(['filename' => $filename], ['decorated' => false]); } - /** - * @dataProvider provideCompletionSuggestions - */ + #[DataProvider('provideCompletionSuggestions')] public function testComplete(array $input, array $expectedSuggestions) { $tester = new CommandCompletionTester($this->createCommand()); diff --git a/Tests/DumperTest.php b/Tests/DumperTest.php index 8eac4aee..099df864 100644 --- a/Tests/DumperTest.php +++ b/Tests/DumperTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Yaml\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Exception\DumpException; @@ -273,9 +274,7 @@ public function testDumpNullAsEmptyAtRoot() $this->assertSame('null', $this->dumper->dump(null, 2, flags: Yaml::DUMP_NULL_AS_EMPTY)); } - /** - * @dataProvider getEscapeSequences - */ + #[DataProvider('getEscapeSequences')] public function testEscapedEscapeSequencesInQuotedScalar($input, $expected) { $this->assertSame($expected, $this->dumper->dump($input)); @@ -322,9 +321,7 @@ public function testNonUtf8DataIsDumpedBase64Encoded() $this->assertSame('!!binary ZsM/cg==', $this->dumper->dump("f\xc3\x3fr")); } - /** - * @dataProvider objectAsMapProvider - */ + #[DataProvider('objectAsMapProvider')] public function testDumpObjectAsMap($object, $expected) { $yaml = $this->dumper->dump($object, 0, 0, Yaml::DUMP_OBJECT_AS_MAP); @@ -910,9 +907,7 @@ public function testDumpNullAsTilde() $this->assertSame('{ foo: ~ }', $this->dumper->dump(['foo' => null], 0, 0, Yaml::DUMP_NULL_AS_TILDE)); } - /** - * @dataProvider getForceQuotesOnValuesData - */ + #[DataProvider('getForceQuotesOnValuesData')] public function testCanForceQuotesOnValues(array $input, string $expected) { $this->assertSame($expected, $this->dumper->dump($input, 0, 0, Yaml::DUMP_FORCE_DOUBLE_QUOTES_ON_VALUES)); @@ -991,9 +986,7 @@ public static function getForceQuotesOnValuesData(): iterable ]; } - /** - * @dataProvider getNumericKeyData - */ + #[DataProvider('getNumericKeyData')] public function testDumpInlineNumericKeyAsString(array $input, bool $inline, int $flags, string $expected) { $this->assertSame($expected, $this->dumper->dump($input, $inline ? 0 : 4, 0, $flags)); @@ -1096,9 +1089,7 @@ public function testDumpIdeographicSpaces() ], 2)); } - /** - * @dataProvider getDateTimeData - */ + #[DataProvider('getDateTimeData')] public function testDumpDateTime(array $input, string $expected) { $this->assertSame($expected, rtrim($this->dumper->dump($input, 1))); @@ -1302,9 +1293,7 @@ public static function getDumpCompactNestedMapping() ]; } - /** - * @dataProvider getDumpCompactNestedMapping - */ + #[DataProvider('getDumpCompactNestedMapping')] public function testDumpCompactNestedMapping(array $data, string $expected, int $indentation, int $inline = 10) { $dumper = new Dumper($indentation); diff --git a/Tests/InlineTest.php b/Tests/InlineTest.php index 7d787afe..dc1c2195 100644 --- a/Tests/InlineTest.php +++ b/Tests/InlineTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Yaml\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Inline; @@ -26,17 +27,13 @@ protected function setUp(): void Inline::initialize(0, 0); } - /** - * @dataProvider getTestsForParse - */ + #[DataProvider('getTestsForParse')] public function testParse(string $yaml, $value, $flags = 0) { $this->assertSame($value, Inline::parse($yaml, $flags), \sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml)); } - /** - * @dataProvider getTestsForParseWithMapObjects - */ + #[DataProvider('getTestsForParseWithMapObjects')] public function testParseWithMapObjects($yaml, $value, $flags = Yaml::PARSE_OBJECT_FOR_MAP) { $actual = Inline::parse($yaml, $flags); @@ -44,9 +41,7 @@ public function testParseWithMapObjects($yaml, $value, $flags = Yaml::PARSE_OBJE $this->assertSame(serialize($value), serialize($actual)); } - /** - * @dataProvider getTestsForParsePhpConstants - */ + #[DataProvider('getTestsForParsePhpConstants')] public function testParsePhpConstants($yaml, $value) { $actual = Inline::parse($yaml, Yaml::PARSE_CONSTANT); @@ -119,9 +114,7 @@ public function testParsePhpEnumThrowsExceptionOnInvalidType() Inline::parse('!php/enum SomeEnum::Foo', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } - /** - * @dataProvider getTestsForDump - */ + #[DataProvider('getTestsForDump')] 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)); @@ -223,9 +216,7 @@ public function testParseScalarWithCorrectlyQuotedStringShouldReturnString() $this->assertSame($expect, Inline::parseScalar($value)); } - /** - * @dataProvider getDataForParseReferences - */ + #[DataProvider('getDataForParseReferences')] public function testParseReferences($yaml, $expected) { $references = ['var' => 'var-value']; @@ -271,9 +262,7 @@ public function testParseUnquotedAsteriskFollowedByAComment() Inline::parse('{ foo: * #foo }'); } - /** - * @dataProvider getReservedIndicators - */ + #[DataProvider('getReservedIndicators')] public function testParseUnquotedScalarStartingWithReservedIndicator($indicator) { $this->expectException(ParseException::class); @@ -287,9 +276,7 @@ public static function getReservedIndicators() return [['@'], ['`']]; } - /** - * @dataProvider getScalarIndicators - */ + #[DataProvider('getScalarIndicators')] public function testParseUnquotedScalarStartingWithScalarIndicator($indicator) { $this->expectException(ParseException::class); @@ -303,9 +290,7 @@ public static function getScalarIndicators() return [['|'], ['>'], ['%']]; } - /** - * @dataProvider getDataForIsHash - */ + #[DataProvider('getDataForIsHash')] public function testIsHash($array, $expected) { $this->assertSame($expected, Inline::isHash($array)); @@ -570,18 +555,14 @@ public static function getTestsForDump() ]; } - /** - * @dataProvider getTimestampTests - */ + #[DataProvider('getTimestampTests')] public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond) { $expectedDate = (new \DateTimeImmutable($yaml, new \DateTimeZone('UTC')))->format('U'); $this->assertSame($microsecond ? (float) "$expectedDate.$microsecond" : (int) $expectedDate, Inline::parse($yaml)); } - /** - * @dataProvider getTimestampTests - */ + #[DataProvider('getTimestampTests')] public function testParseTimestampAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone) { $expected = (new \DateTimeImmutable($yaml)) @@ -604,9 +585,7 @@ public static function getTimestampTests(): array ]; } - /** - * @dataProvider getTimestampTests - */ + #[DataProvider('getTimestampTests')] public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond) { $expected = (new \DateTimeImmutable($yaml)) @@ -628,17 +607,13 @@ public function testParseInvalidDate() Inline::parse('2024-50-50', Yaml::PARSE_DATETIME); } - /** - * @dataProvider getDateTimeDumpTests - */ + #[DataProvider('getDateTimeDumpTests')] public function testDumpDateTime($dateTime, $expected) { $this->assertSame($expected, Inline::dump($dateTime)); } - /** - * @dataProvider getNumericKeyData - */ + #[DataProvider('getNumericKeyData')] public function testDumpNumericKeyAsString(array|int $input, int $flags, string $expected) { $this->assertSame($expected, Inline::dump($input, $flags)); @@ -761,9 +736,7 @@ public static function getDateTimeDumpTests() return $tests; } - /** - * @dataProvider getBinaryData - */ + #[DataProvider('getBinaryData')] public function testParseBinaryData($data) { $this->assertSame('Hello world', Inline::parse($data)); @@ -778,9 +751,7 @@ public static function getBinaryData() ]; } - /** - * @dataProvider getInvalidBinaryData - */ + #[DataProvider('getInvalidBinaryData')] public function testParseInvalidBinaryData($data, $expectedMessage) { $this->expectException(ParseException::class); @@ -823,9 +794,7 @@ public function testMappingKeysCannotBeOmitted() Inline::parse('{: foo}'); } - /** - * @dataProvider getTestsForNullValues - */ + #[DataProvider('getTestsForNullValues')] public function testParseMissingMappingValueAsNull($yaml, $expected) { $this->assertSame($expected, Inline::parse($yaml)); @@ -844,9 +813,7 @@ public function testTheEmptyStringIsAValidMappingKey() $this->assertSame(['' => 'foo'], Inline::parse('{ "": foo }')); } - /** - * @dataProvider getNotPhpCompatibleMappingKeyData - */ + #[DataProvider('getNotPhpCompatibleMappingKeyData')] public function testImplicitStringCastingOfMappingKeysThrowsException(string $yaml) { $this->expectException(ParseException::class); @@ -925,9 +892,7 @@ public function testUnfinishedInlineMap() Inline::parse("{abc: 'def'"); } - /** - * @dataProvider getTestsForOctalNumbers - */ + #[DataProvider('getTestsForOctalNumbers')] public function testParseOctalNumbers($expected, $yaml) { self::assertSame($expected, Inline::parse($yaml)); @@ -942,9 +907,7 @@ public static function getTestsForOctalNumbers() ]; } - /** - * @dataProvider getTestsForOctalNumbersYaml11Notation - */ + #[DataProvider('getTestsForOctalNumbersYaml11Notation')] public function testParseOctalNumbersYaml11Notation(string $expected, string $yaml) { self::assertSame($expected, Inline::parse($yaml)); @@ -961,9 +924,7 @@ public static function getTestsForOctalNumbersYaml11Notation() ]; } - /** - * @dataProvider phpObjectTagWithEmptyValueProvider - */ + #[DataProvider('phpObjectTagWithEmptyValueProvider')] public function testPhpObjectWithEmptyValue(string $value) { $this->expectException(ParseException::class); @@ -984,9 +945,7 @@ public static function phpObjectTagWithEmptyValueProvider() ]; } - /** - * @dataProvider phpConstTagWithEmptyValueProvider - */ + #[DataProvider('phpConstTagWithEmptyValueProvider')] public function testPhpConstTagWithEmptyValue(string $value) { $this->expectException(ParseException::class); @@ -995,9 +954,7 @@ public function testPhpConstTagWithEmptyValue(string $value) Inline::parse($value, Yaml::PARSE_CONSTANT); } - /** - * @dataProvider phpConstTagWithEmptyValueProvider - */ + #[DataProvider('phpConstTagWithEmptyValueProvider')] public function testPhpEnumTagWithEmptyValue(string $value) { $this->expectException(ParseException::class); @@ -1031,9 +988,7 @@ public function testParseUnquotedStringContainingHashTagNotPrefixedBySpace() self::assertSame('foo#nocomment', Inline::parse('foo#nocomment')); } - /** - * @dataProvider unquotedExclamationMarkThrowsProvider - */ + #[DataProvider('unquotedExclamationMarkThrowsProvider')] public function testUnquotedExclamationMarkThrows(string $value) { $this->expectException(ParseException::class); @@ -1065,9 +1020,7 @@ public static function unquotedExclamationMarkThrowsProvider() ]; } - /** - * @dataProvider quotedExclamationMarkProvider - */ + #[DataProvider('quotedExclamationMarkProvider')] public function testQuotedExclamationMark($expected, string $value) { $this->assertSame($expected, Inline::parse($value)); @@ -1096,9 +1049,7 @@ public static function quotedExclamationMarkProvider() ]; } - /** - * @dataProvider ideographicSpaceProvider - */ + #[DataProvider('ideographicSpaceProvider')] public function testParseIdeographicSpace(string $yaml, string $expected) { $this->assertSame($expected, Inline::parse($yaml)); diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index eb46c69f..d729362c 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -11,8 +11,10 @@ namespace Symfony\Component\Yaml\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\IgnoreDeprecations; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Parser; @@ -144,9 +146,7 @@ public function testTaggedTextAsListItem() $this->parser->parse($yml, Yaml::PARSE_CUSTOM_TAGS); } - /** - * @dataProvider getDataFormSpecifications - */ + #[DataProvider('getDataFormSpecifications')] public function testSpecifications($expected, $yaml, $comment) { $this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment); @@ -162,9 +162,7 @@ public static function getNonStringMappingKeysData() return self::loadTestsFromFixtureFiles('nonStringKeys.yml'); } - /** - * @dataProvider invalidIndentation - */ + #[DataProvider('invalidIndentation')] public function testTabsAsIndentationInYaml(string $given, string $expectedMessage) { $this->expectException(ParseException::class); @@ -208,9 +206,7 @@ public function testParserIsStateless() $this->parser->parse("abc:\n\tabc"); } - /** - * @dataProvider validTokenSeparators - */ + #[DataProvider('validTokenSeparators')] public function testValidTokenSeparation(string $given, array $expected) { $actual = $this->parser->parse($given); @@ -557,9 +553,7 @@ public static function getBlockChompingTests() return $tests; } - /** - * @dataProvider getBlockChompingTests - */ + #[DataProvider('getBlockChompingTests')] public function testBlockChomping($expected, $yaml) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -604,9 +598,7 @@ public function testObjectSupportDisabledButNoExceptions() $this->assertSameData(['foo' => null, 'bar' => 1], $this->parser->parse($input), '->parse() does not parse objects'); } - /** - * @dataProvider getObjectForMapTests - */ + #[DataProvider('getObjectForMapTests')] public function testObjectForMap($yaml, $expected) { $flags = Yaml::PARSE_OBJECT_FOR_MAP; @@ -714,9 +706,7 @@ public function testCanParseContentWithTrailingSpaces() $this->assertSame($expected, $this->parser->parse($yaml)); } - /** - * @requires extension iconv - */ + #[RequiresPhpExtension('iconv')] public function testNonUtf8Exception() { $yamls = [ @@ -891,9 +881,7 @@ public static function getParseExceptionNotAffectedMultiLineStringLastResortPars return $tests; } - /** - * @dataProvider getParseExceptionNotAffectedMultiLineStringLastResortParsing - */ + #[DataProvider('getParseExceptionNotAffectedMultiLineStringLastResortParsing')] public function testParseExceptionNotAffectedByMultiLineStringLastResortParsing($yaml) { $this->expectException(ParseException::class); @@ -990,9 +978,7 @@ public function testMappingDuplicateKeyFlow() Yaml::parse($input); } - /** - * @dataProvider getParseExceptionOnDuplicateData - */ + #[DataProvider('getParseExceptionOnDuplicateData')] public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber) { $this->expectException(ParseException::class); @@ -1317,9 +1303,7 @@ public function testColonInMappingValueExceptionNotTriggeredByColonInComment() $this->assertSame(['foo' => ['bar' => 'foobar']], $this->parser->parse($yaml)); } - /** - * @dataProvider getCommentLikeStringInScalarBlockData - */ + #[DataProvider('getCommentLikeStringInScalarBlockData')] public function testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult) { $this->assertSame($expectedParserResult, $this->parser->parse($yaml)); @@ -1502,9 +1486,7 @@ public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks() ); } - /** - * @dataProvider getBinaryData - */ + #[DataProvider('getBinaryData')] public function testParseBinaryData($data) { $this->assertSame(['data' => 'Hello world'], $this->parser->parse($data)); @@ -1531,9 +1513,7 @@ public static function getBinaryData() ]; } - /** - * @dataProvider getInvalidBinaryData - */ + #[DataProvider('getInvalidBinaryData')] public function testParseInvalidBinaryData($data, $expectedMessage) { $this->expectException(ParseException::class); @@ -1606,9 +1586,7 @@ public function testParseDateAsMappingValue() $this->assertSameData(['date' => $expectedDate], $this->parser->parse($yaml, Yaml::PARSE_DATETIME)); } - /** - * @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider - */ + #[DataProvider('parserThrowsExceptionWithCorrectLineNumberProvider')] public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml) { $this->expectException(ParseException::class); @@ -1753,9 +1731,7 @@ public function testBackslashInQuotedMultiLineString() $this->assertSame($expected, $this->parser->parse($yaml)); } - /** - * @dataProvider wrappedUnquotedStringsProvider - */ + #[DataProvider('wrappedUnquotedStringsProvider')] public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -1794,9 +1770,7 @@ public function testParseMultiLineUnquotedString() $this->assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml)); } - /** - * @dataProvider unquotedStringWithTrailingComment - */ + #[DataProvider('unquotedStringWithTrailingComment')] public function testParseMultiLineUnquotedStringWithTrailingComment(string $yaml, array $expected) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -1857,9 +1831,7 @@ public static function unquotedStringWithTrailingComment() ]; } - /** - * @dataProvider escapedQuotationCharactersInQuotedStrings - */ + #[DataProvider('escapedQuotationCharactersInQuotedStrings')] public function testParseQuotedStringContainingEscapedQuotationCharacters(string $yaml, array $expected) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -1915,9 +1887,7 @@ public function testParseMultiLineString() $this->assertSame("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz")); } - /** - * @dataProvider multiLineDataProvider - */ + #[DataProvider('multiLineDataProvider')] public function testParseMultiLineMappingValue($yaml, $expected, $parseError) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -1982,9 +1952,7 @@ public static function multiLineDataProvider() return $tests; } - /** - * @dataProvider inlineNotationSpanningMultipleLinesProvider - */ + #[DataProvider('inlineNotationSpanningMultipleLinesProvider')] public function testInlineNotationSpanningMultipleLines($expected, string $yaml) { $this->assertSame($expected, $this->parser->parse($yaml)); @@ -2408,9 +2376,7 @@ public function testInvalidInlineSequenceContainingStringWithEscapedQuotationCha $this->parser->parse('["\\"]'); } - /** - * @dataProvider taggedValuesProvider - */ + #[DataProvider('taggedValuesProvider')] public function testCustomTagSupport($expected, $yaml) { $this->assertSameData($expected, $this->parser->parse($yaml, Yaml::PARSE_CUSTOM_TAGS)); @@ -2839,9 +2805,7 @@ public function testEvalRefException() $this->parser->parse($yaml); } - /** - * @dataProvider circularReferenceProvider - */ + #[DataProvider('circularReferenceProvider')] public function testDetectCircularReferences($yaml) { $this->expectException(ParseException::class); @@ -2919,9 +2883,7 @@ public function testBlockScalarArray() $this->assertSame($expected, $this->parser->parse($yaml)); } - /** - * @dataProvider indentedMappingData - */ + #[DataProvider('indentedMappingData')] public function testParseIndentedMappings($yaml, $expected) { $this->assertSame($expected, $this->parser->parse($yaml)); From 0e259b257611dffe54fbaad90325d90b5d522e91 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 6 Aug 2025 19:46:26 +0200 Subject: [PATCH 12/14] [Yaml] Fix code style --- Tests/Fixtures/FooBackedEnum.php | 9 +++++++++ Tests/Fixtures/FooUnitEnum.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Tests/Fixtures/FooBackedEnum.php b/Tests/Fixtures/FooBackedEnum.php index 91acf5fe..72f95b80 100644 --- a/Tests/Fixtures/FooBackedEnum.php +++ b/Tests/Fixtures/FooBackedEnum.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Yaml\Tests\Fixtures; enum FooBackedEnum: string diff --git a/Tests/Fixtures/FooUnitEnum.php b/Tests/Fixtures/FooUnitEnum.php index 59092e27..4a26488e 100644 --- a/Tests/Fixtures/FooUnitEnum.php +++ b/Tests/Fixtures/FooUnitEnum.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Yaml\Tests\Fixtures; enum FooUnitEnum From ef9893f0c5fc0686cff79cb50844140ffcb860b7 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 10 Aug 2025 00:28:14 +0200 Subject: [PATCH 13/14] chore: heredoc indentation as of PHP 7.3 https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc --- Command/LintCommand.php | 26 +- Inline.php | 26 +- Tests/Command/LintCommandTest.php | 24 +- Tests/DumperTest.php | 586 ++++----- Tests/InlineTest.php | 8 +- Tests/ParserTest.php | 1944 ++++++++++++++--------------- 6 files changed, 1307 insertions(+), 1307 deletions(-) diff --git a/Command/LintCommand.php b/Command/LintCommand.php index 4cee8c14..2088d2f1 100644 --- a/Command/LintCommand.php +++ b/Command/LintCommand.php @@ -58,30 +58,30 @@ protected function configure(): void ->addOption('exclude', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to exclude') ->addOption('parse-tags', null, InputOption::VALUE_NEGATABLE, 'Parse custom tags', null) ->setHelp(<<%command.name% command lints a YAML file and outputs to STDOUT -the first encountered syntax error. + The %command.name% command lints a YAML file and outputs to STDOUT + the first encountered syntax error. -You can validates YAML contents passed from STDIN: + You can validates YAML contents passed from STDIN: - cat filename | php %command.full_name% - + cat filename | php %command.full_name% - -You can also validate the syntax of a file: + You can also validate the syntax of a file: - php %command.full_name% filename + php %command.full_name% filename -Or of a whole directory: + Or of a whole directory: - php %command.full_name% dirname + php %command.full_name% dirname -The --format option specifies the format of the command output: + The --format option specifies the format of the command output: - php %command.full_name% dirname --format=json + php %command.full_name% dirname --format=json -You can also exclude one or more specific files: + You can also exclude one or more specific files: - php %command.full_name% dirname --exclude="dirname/foo.yaml" --exclude="dirname/bar.yaml" + php %command.full_name% dirname --exclude="dirname/foo.yaml" --exclude="dirname/bar.yaml" -EOF + EOF ) ; } diff --git a/Inline.php b/Inline.php index 1c9fa609..f98ce301 100644 --- a/Inline.php +++ b/Inline.php @@ -829,19 +829,19 @@ private static function isBinaryString(string $value): bool private static function getTimestampRegex(): string { return <<[0-9][0-9][0-9][0-9]) - -(?P[0-9][0-9]?) - -(?P[0-9][0-9]?) - (?:(?:[Tt]|[ \t]+) - (?P[0-9][0-9]?) - :(?P[0-9][0-9]) - :(?P[0-9][0-9]) - (?:\.(?P[0-9]*))? - (?:[ \t]*(?PZ|(?P[-+])(?P[0-9][0-9]?) - (?::(?P[0-9][0-9]))?))?)? - $~x -EOF; + ~^ + (?P[0-9][0-9][0-9][0-9]) + -(?P[0-9][0-9]?) + -(?P[0-9][0-9]?) + (?:(?:[Tt]|[ \t]+) + (?P[0-9][0-9]?) + :(?P[0-9][0-9]) + :(?P[0-9][0-9]) + (?:\.(?P[0-9]*))? + (?:[ \t]*(?PZ|(?P[-+])(?P[0-9][0-9]?) + (?::(?P[0-9][0-9]))?))?)? + $~x + EOF; } /** diff --git a/Tests/Command/LintCommandTest.php b/Tests/Command/LintCommandTest.php index 5b586ba0..cb8a8887 100644 --- a/Tests/Command/LintCommandTest.php +++ b/Tests/Command/LintCommandTest.php @@ -69,9 +69,9 @@ public function testLintIncorrectFile() public function testLintIncorrectFileWithGithubFormat() { $incorrectContent = <<createCommandTester(); $filename = $this->createFile($incorrectContent); @@ -90,9 +90,9 @@ public function testLintAutodetectsGithubActionEnvironment() putenv('GITHUB_ACTIONS=1'); $incorrectContent = <<createCommandTester(); $filename = $this->createFile($incorrectContent); @@ -107,8 +107,8 @@ public function testLintAutodetectsGithubActionEnvironment() public function testConstantAsKey() { $yaml = <<createCommandTester()->execute(['filename' => $this->createFile($yaml)], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]); $this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success'); } @@ -116,8 +116,8 @@ public function testConstantAsKey() public function testCustomTags() { $yaml = <<createCommandTester()->execute(['filename' => $this->createFile($yaml), '--parse-tags' => true], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]); $this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success'); } @@ -125,8 +125,8 @@ public function testCustomTags() public function testCustomTagsError() { $yaml = <<createCommandTester()->execute(['filename' => $this->createFile($yaml)], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]); $this->assertSame(1, $ret, 'lint:yaml exits with code 1 in case of error'); } diff --git a/Tests/DumperTest.php b/Tests/DumperTest.php index 099df864..f3886475 100644 --- a/Tests/DumperTest.php +++ b/Tests/DumperTest.php @@ -60,26 +60,26 @@ public function testIndentationInConstructor() { $dumper = new Dumper(7); $expected = <<<'EOF' -'': bar -foo: '#bar' -"foo'bar": { } -bar: - - 1 - - foo - - - a: A -foobar: - foo: bar - bar: - - 1 - - foo - foobar: - foo: bar - bar: - - 1 - - foo - -EOF; + '': bar + foo: '#bar' + "foo'bar": { } + bar: + - 1 + - foo + - + a: A + foobar: + foo: bar + bar: + - 1 + - foo + foobar: + foo: bar + bar: + - 1 + - foo + + EOF; $this->assertSame($expected, $dumper->dump($this->array, 4, 0)); $this->assertSameData($this->array, $this->parser->parse($expected)); } @@ -115,83 +115,83 @@ public function testSpecifications() public function testInlineLevel() { $expected = <<<'EOF' -{ '': bar, foo: '#bar', "foo'bar": { }, bar: [1, foo, { a: A }], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } -EOF; + { '': bar, foo: '#bar', "foo'bar": { }, bar: [1, foo, { a: A }], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } + EOF; $this->assertSame($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument'); $this->assertSame($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument'); $this->assertSameData($this->array, $this->parser->parse($expected)); $expected = <<<'EOF' -'': bar -foo: '#bar' -"foo'bar": { } -bar: [1, foo, { a: A }] -foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } + '': bar + foo: '#bar' + "foo'bar": { } + bar: [1, foo, { a: A }] + foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } -EOF; + EOF; $this->assertSame($expected, $this->dumper->dump($this->array, 1), '->dump() takes an inline level argument'); $this->assertSameData($this->array, $this->parser->parse($expected)); $expected = <<<'EOF' -'': bar -foo: '#bar' -"foo'bar": { } -bar: - - 1 - - foo - - { a: A } -foobar: - foo: bar - bar: [1, foo] - foobar: { foo: bar, bar: [1, foo] } - -EOF; + '': bar + foo: '#bar' + "foo'bar": { } + bar: + - 1 + - foo + - { a: A } + foobar: + foo: bar + bar: [1, foo] + foobar: { foo: bar, bar: [1, foo] } + + EOF; $this->assertSame($expected, $this->dumper->dump($this->array, 2), '->dump() takes an inline level argument'); $this->assertSameData($this->array, $this->parser->parse($expected)); $expected = <<<'EOF' -'': bar -foo: '#bar' -"foo'bar": { } -bar: - - 1 - - foo - - - a: A -foobar: - foo: bar - bar: - - 1 - - foo - foobar: - foo: bar - bar: [1, foo] - -EOF; + '': bar + foo: '#bar' + "foo'bar": { } + bar: + - 1 + - foo + - + a: A + foobar: + foo: bar + bar: + - 1 + - foo + foobar: + foo: bar + bar: [1, foo] + + EOF; $this->assertSame($expected, $this->dumper->dump($this->array, 3), '->dump() takes an inline level argument'); $this->assertSameData($this->array, $this->parser->parse($expected)); $expected = <<<'EOF' -'': bar -foo: '#bar' -"foo'bar": { } -bar: - - 1 - - foo - - - a: A -foobar: - foo: bar - bar: - - 1 - - foo - foobar: - foo: bar - bar: - - 1 - - foo - -EOF; + '': bar + foo: '#bar' + "foo'bar": { } + bar: + - 1 + - foo + - + a: A + foobar: + foo: bar + bar: + - 1 + - foo + foobar: + foo: bar + bar: + - 1 + - foo + + EOF; $this->assertSame($expected, $this->dumper->dump($this->array, 4), '->dump() takes an inline level argument'); $this->assertSame($expected, $this->dumper->dump($this->array, 10), '->dump() takes an inline level argument'); $this->assertSameData($this->array, $this->parser->parse($expected)); @@ -367,13 +367,13 @@ public function testDumpingArrayObjectInstancesRespectsInlineLevel() $yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP); $expected = <<assertSame($expected, $yaml); } @@ -385,8 +385,8 @@ public function testDumpingArrayObjectInstancesWithNumericKeysInlined() $yaml = $this->dumper->dump($outer, 0, 0, Yaml::DUMP_OBJECT_AS_MAP); $expected = <<assertSame($expected, $yaml); } @@ -397,13 +397,13 @@ public function testDumpingArrayObjectInstancesWithNumericKeysRespectsInlineLeve $outer = new \ArrayObject(['a', $inner]); $yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP); $expected = <<assertSame($expected, $yaml); } @@ -435,13 +435,13 @@ public function testDumpingStdClassInstancesRespectsInlineLevel() $yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP); $expected = <<assertSame($expected, $yaml); $this->assertSameData($outer, $this->parser->parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP)); } @@ -461,13 +461,13 @@ public function testDumpingTaggedValueSequenceRespectsInlineLevel() $yaml = $this->dumper->dump($data, 2); $expected = <<assertSame($expected, $yaml); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); } @@ -499,10 +499,10 @@ public function testDumpingTaggedValueTopLevelAssoc() $data = new TaggedValue('user', ['name' => 'jane']); $expected = <<<'YAML' -!user -name: jane + !user + name: jane -YAML; + YAML; $yaml = $this->dumper->dump($data, 2); $this->assertSame($expected, $yaml); } @@ -541,11 +541,11 @@ public function testDumpingTaggedValueSequenceWithInlinedTagValues() $yaml = $this->dumper->dump($data, 1); $expected = <<assertSame($expected, $yaml); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); } @@ -566,14 +566,14 @@ public function testDumpingTaggedValueMapRespectsInlineLevel() $yaml = $this->dumper->dump($data, 2); $expected = <<assertSame($expected, $yaml); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); } @@ -593,10 +593,10 @@ public function testDumpingTaggedValueMapWithInlinedTagValues() $yaml = $this->dumper->dump($data, 1); $expected = <<assertSame($expected, $yaml); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); } @@ -608,10 +608,10 @@ public function testDumpingNotInlinedScalarTaggedValue() 'user2' => new TaggedValue('user', 'john'), ]; $expected = <<assertSame($expected, $this->dumper->dump($data, 2)); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); @@ -623,9 +623,9 @@ public function testDumpingNotInlinedNullTaggedValue() 'foo' => new TaggedValue('bar', null), ]; $expected = <<assertSame($expected, $this->dumper->dump($data, 2)); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT)); @@ -705,10 +705,10 @@ public function testDumpingInlinedMultiLineIfRnBreakLineInTaggedValue() ], ]; $expected = <<<'YAML' -data: - foo: !bar "foo\r\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz" + data: + foo: !bar "foo\r\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz" -YAML; + YAML; $yml = $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); $this->assertSame($expected, $yml); $this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS)); @@ -728,22 +728,22 @@ public function testDumpMultiLineStringAsScalarBlock() ]; $yml = $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); $expected = str_replace("@\n", "\n", <<<'YAML' -data: - single_line: 'foo bar baz' - multi_line: |- - foo - line with trailing spaces: - @ - bar - integer like line: - 123456789 - empty line: - - baz - multi_line_with_carriage_return: "foo\nbar\r\nbaz" - nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" } - -YAML + data: + single_line: 'foo bar baz' + multi_line: |- + foo + line with trailing spaces: + @ + bar + integer like line: + 123456789 + empty line: + + baz + multi_line_with_carriage_return: "foo\nbar\r\nbaz" + nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" } + + YAML ); $this->assertSame($expected, $yml); $this->assertSame($data, $this->parser->parse($yml)); @@ -816,10 +816,10 @@ public function testCarriageReturnNotFollowedByNewlineIsPreservedWhenDumpingAsMu ], ]; $expected = <<<'YAML' -parent: - foo: "bar\n\rbaz: qux" + parent: + foo: "bar\n\rbaz: qux" -YAML; + YAML; $this->assertSame($expected, $this->dumper->dump($data, 4, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); $this->assertSame($data, $this->parser->parse($expected)); } @@ -858,31 +858,31 @@ public function testDumpTrailingNewlineInMultiLineLiteralBlocks() $yaml = $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); $expected = <<assertSame($expected, $yaml); $this->assertSame($data, $this->parser->parse($yaml)); @@ -1009,9 +1009,9 @@ public static function getNumericKeyData() ]; $expected = <<<'YAML' - '200': foo + '200': foo - YAML; + YAML; yield 'Int key with flag' => [ [200 => 'foo'], @@ -1021,9 +1021,9 @@ public static function getNumericKeyData() ]; $expected = <<<'YAML' - 200: foo + 200: foo - YAML; + YAML; yield 'Int key without flag' => [ [200 => 'foo'], @@ -1033,10 +1033,10 @@ public static function getNumericKeyData() ]; $expected = <<<'YAML' - - 200 - - foo + - 200 + - foo - YAML; + YAML; yield 'List array with flag' => [ [200, 'foo'], @@ -1046,9 +1046,9 @@ public static function getNumericKeyData() ]; $expected = <<<'YAML' - '200': !number 5 + '200': !number 5 - YAML; + YAML; yield 'Int tagged value with flag' => [ [ @@ -1060,9 +1060,9 @@ public static function getNumericKeyData() ]; $expected = <<<'YAML' - 200: !number 5 + 200: !number 5 - YAML; + YAML; yield 'Int tagged value without flag' => [ [ @@ -1077,11 +1077,11 @@ public static function getNumericKeyData() public function testDumpIdeographicSpaces() { $expected = <<assertSame($expected, $this->dumper->dump([ 'alone' => ' ', 'within_string' => 'a b', @@ -1161,133 +1161,133 @@ public static function getDumpCompactNestedMapping() yield 'Compact nested mapping 1' => [ $data, << [ $data, << [ $data, << [ $data, << [ $data, <<assertSame(['foo' => '&foo', 'bar' => '&bar', 'baz' => '&baz'], Inline::parse($yaml)); } @@ -1086,8 +1086,8 @@ public function testParseQuotedReferenceLikeStringsInMapping() public function testParseQuotedReferenceLikeStringsInSequence() { $yaml = <<assertSame(['&foo', '&bar', '&baz'], Inline::parse($yaml)); } diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index d729362c..578179d3 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -56,10 +56,10 @@ public function testTopLevelNull() public function testEmptyValueInExpandedMappingIsSupported() { $yml = <<<'YAML' -foo: - bar: - baz: qux -YAML; + foo: + bar: + baz: qux + YAML; $data = $this->parser->parse($yml); $expected = ['foo' => ['bar' => null, 'baz' => 'qux']]; @@ -69,11 +69,11 @@ public function testEmptyValueInExpandedMappingIsSupported() public function testEmptyValueInExpandedSequenceIsSupported() { $yml = <<<'YAML' -foo: - - bar - - - - baz -YAML; + foo: + - bar + - + - baz + YAML; $data = $this->parser->parse($yml); $expected = ['foo' => ['bar', null, 'baz']]; @@ -115,9 +115,9 @@ public function testTaggedValueTopLevelAssocInline() public function testTaggedValueTopLevelAssoc() { $yml = <<<'YAML' -!user -name: barbara -YAML; + !user + name: barbara + YAML; $data = $this->parser->parse($yml, Yaml::PARSE_CUSTOM_TAGS); $expected = new TaggedValue('user', ['name' => 'barbara']); $this->assertSameData($expected, $data); @@ -126,9 +126,9 @@ public function testTaggedValueTopLevelAssoc() public function testTaggedValueTopLevelList() { $yml = <<<'YAML' -!users -- barbara -YAML; + !users + - barbara + YAML; $data = $this->parser->parse($yml, Yaml::PARSE_CUSTOM_TAGS); $expected = new TaggedValue('users', ['barbara']); $this->assertSameData($expected, $data); @@ -137,9 +137,9 @@ public function testTaggedValueTopLevelList() public function testTaggedTextAsListItem() { $yml = <<<'YAML' -- !text | - first line -YAML; + - !text | + first line + YAML; // @todo Fix the parser, eliminate this exception. $this->expectException(ParseException::class); $this->expectExceptionMessage('Unable to parse at line 2 (near "!text |").'); @@ -238,10 +238,10 @@ public static function validTokenSeparators(): array public function testEndOfTheDocumentMarker() { $yaml = <<<'EOF' ---- %YAML:1.0 -foo -... -EOF; + --- %YAML:1.0 + foo + ... + EOF; $this->assertEquals('foo', $this->parser->parse($yaml)); } @@ -251,14 +251,14 @@ public static function getBlockChompingTests() $tests = []; $yaml = <<<'EOF' -foo: |- - one - two -bar: |- - one - two - -EOF; + foo: |- + one + two + bar: |- + one + two + + EOF; $expected = [ 'foo' => "one\ntwo", 'bar' => "one\ntwo", @@ -266,16 +266,16 @@ public static function getBlockChompingTests() $tests['Literal block chomping strip with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: |- - one - two + foo: |- + one + two -bar: |- - one - two + bar: |- + one + two -EOF; + EOF; $expected = [ 'foo' => "one\ntwo", 'bar' => "one\ntwo", @@ -283,21 +283,21 @@ public static function getBlockChompingTests() $tests['Literal block chomping strip with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -{} + {} -EOF; + EOF; $expected = []; $tests['Literal block chomping strip with multiple trailing newlines after a 1-liner'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: |- - one - two -bar: |- - one - two -EOF; + foo: |- + one + two + bar: |- + one + two + EOF; $expected = [ 'foo' => "one\ntwo", 'bar' => "one\ntwo", @@ -305,14 +305,14 @@ public static function getBlockChompingTests() $tests['Literal block chomping strip without trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: | - one - two -bar: | - one - two - -EOF; + foo: | + one + two + bar: | + one + two + + EOF; $expected = [ 'foo' => "one\ntwo\n", 'bar' => "one\ntwo\n", @@ -320,16 +320,16 @@ public static function getBlockChompingTests() $tests['Literal block chomping clip with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: | - one - two + foo: | + one + two -bar: | - one - two + bar: | + one + two -EOF; + EOF; $expected = [ 'foo' => "one\ntwo\n", 'bar' => "one\ntwo\n", @@ -337,12 +337,12 @@ public static function getBlockChompingTests() $tests['Literal block chomping clip with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: -- bar: | - one + foo: + - bar: | + one - two -EOF; + two + EOF; $expected = [ 'foo' => [ [ @@ -353,13 +353,13 @@ public static function getBlockChompingTests() $tests['Literal block chomping clip with embedded blank line inside unindented collection'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: | - one - two -bar: | - one - two -EOF; + foo: | + one + two + bar: | + one + two + EOF; $expected = [ 'foo' => "one\ntwo\n", 'bar' => "one\ntwo", @@ -367,14 +367,14 @@ public static function getBlockChompingTests() $tests['Literal block chomping clip without trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: |+ - one - two -bar: |+ - one - two - -EOF; + foo: |+ + one + two + bar: |+ + one + two + + EOF; $expected = [ 'foo' => "one\ntwo\n", 'bar' => "one\ntwo\n", @@ -382,16 +382,16 @@ public static function getBlockChompingTests() $tests['Literal block chomping keep with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: |+ - one - two + foo: |+ + one + two -bar: |+ - one - two + bar: |+ + one + two -EOF; + EOF; $expected = [ 'foo' => "one\ntwo\n\n", 'bar' => "one\ntwo\n\n", @@ -399,13 +399,13 @@ public static function getBlockChompingTests() $tests['Literal block chomping keep with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: |+ - one - two -bar: |+ - one - two -EOF; + foo: |+ + one + two + bar: |+ + one + two + EOF; $expected = [ 'foo' => "one\ntwo\n", 'bar' => "one\ntwo", @@ -413,14 +413,14 @@ public static function getBlockChompingTests() $tests['Literal block chomping keep without trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >- - one - two -bar: >- - one - two - -EOF; + foo: >- + one + two + bar: >- + one + two + + EOF; $expected = [ 'foo' => 'one two', 'bar' => 'one two', @@ -428,16 +428,16 @@ public static function getBlockChompingTests() $tests['Folded block chomping strip with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >- - one - two + foo: >- + one + two -bar: >- - one - two + bar: >- + one + two -EOF; + EOF; $expected = [ 'foo' => 'one two', 'bar' => 'one two', @@ -445,13 +445,13 @@ public static function getBlockChompingTests() $tests['Folded block chomping strip with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >- - one - two -bar: >- - one - two -EOF; + foo: >- + one + two + bar: >- + one + two + EOF; $expected = [ 'foo' => 'one two', 'bar' => 'one two', @@ -459,14 +459,14 @@ public static function getBlockChompingTests() $tests['Folded block chomping strip without trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: > - one - two -bar: > - one - two - -EOF; + foo: > + one + two + bar: > + one + two + + EOF; $expected = [ 'foo' => "one two\n", 'bar' => "one two\n", @@ -474,16 +474,16 @@ public static function getBlockChompingTests() $tests['Folded block chomping clip with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: > - one - two + foo: > + one + two -bar: > - one - two + bar: > + one + two -EOF; + EOF; $expected = [ 'foo' => "one two\n", 'bar' => "one two\n", @@ -491,13 +491,13 @@ public static function getBlockChompingTests() $tests['Folded block chomping clip with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: > - one - two -bar: > - one - two -EOF; + foo: > + one + two + bar: > + one + two + EOF; $expected = [ 'foo' => "one two\n", 'bar' => 'one two', @@ -505,14 +505,14 @@ public static function getBlockChompingTests() $tests['Folded block chomping clip without trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >+ - one - two -bar: >+ - one - two - -EOF; + foo: >+ + one + two + bar: >+ + one + two + + EOF; $expected = [ 'foo' => "one two\n", 'bar' => "one two\n", @@ -520,16 +520,16 @@ public static function getBlockChompingTests() $tests['Folded block chomping keep with single trailing newline'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >+ - one - two + foo: >+ + one + two -bar: >+ - one - two + bar: >+ + one + two -EOF; + EOF; $expected = [ 'foo' => "one two\n\n", 'bar' => "one two\n\n", @@ -537,13 +537,13 @@ public static function getBlockChompingTests() $tests['Folded block chomping keep with multiple trailing newlines'] = [$expected, $yaml]; $yaml = <<<'EOF' -foo: >+ - one - two -bar: >+ - one - two -EOF; + foo: >+ + one + two + bar: >+ + one + two + EOF; $expected = [ 'foo' => "one two\n", 'bar' => 'one two', @@ -567,12 +567,12 @@ public function testBlockChomping($expected, $yaml) public function testBlockLiteralWithLeadingNewlines() { $yaml = <<<'EOF' -foo: |- + foo: |- - bar + bar -EOF; + EOF; $expected = [ 'foo' => "\n\nbar", ]; @@ -583,18 +583,18 @@ public function testBlockLiteralWithLeadingNewlines() public function testObjectSupportEnabled() { $input = <<<'EOF' -foo: !php/object O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";} -bar: 1 -EOF; + foo: !php/object O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";} + bar: 1 + EOF; $this->assertSameData(['foo' => new B(), 'bar' => 1], $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects'); } public function testObjectSupportDisabledButNoExceptions() { $input = <<<'EOF' -foo: !php/object O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} -bar: 1 -EOF; + foo: !php/object O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} + bar: 1 + EOF; $this->assertSameData(['foo' => null, 'bar' => 1], $this->parser->parse($input), '->parse() does not parse objects'); } @@ -611,9 +611,9 @@ public static function getObjectForMapTests() $tests = []; $yaml = <<<'EOF' -foo: - fiz: [cat] -EOF; + foo: + fiz: [cat] + EOF; $expected = new \stdClass(); $expected->foo = new \stdClass(); $expected->foo->fiz = ['cat']; @@ -632,10 +632,10 @@ public static function getObjectForMapTests() $tests['object-for-map-is-applied-after-parsing'] = [$yaml, $expected]; $yaml = <<<'EOT' -array: - - key: one - - key: two -EOT; + array: + - key: one + - key: two + EOT; $expected = new \stdClass(); $expected->array = []; $expected->array[0] = new \stdClass(); @@ -645,10 +645,10 @@ public static function getObjectForMapTests() $tests['nest-map-and-sequence'] = [$yaml, $expected]; $yaml = <<<'YAML' -map: - 1: one - 2: two -YAML; + map: + 1: one + 2: two + YAML; $expected = new \stdClass(); $expected->map = new \stdClass(); $expected->map->{1} = 'one'; @@ -656,10 +656,10 @@ public static function getObjectForMapTests() $tests['numeric-keys'] = [$yaml, $expected]; $yaml = <<<'YAML' -map: - '0': one - '1': two -YAML; + map: + '0': one + '1': two + YAML; $expected = new \stdClass(); $expected->map = new \stdClass(); $expected->map->{0} = 'one'; @@ -672,9 +672,9 @@ public static function getObjectForMapTests() 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; + foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} + bar: 1 + EOF; $this->expectException(ParseException::class); @@ -684,10 +684,10 @@ public function testObjectsSupportDisabledWithExceptions() public function testMappingKeyInMultiLineStringThrowsException() { $yaml = <<<'EOF' -data: - dbal:wrong - default_connection: monolith -EOF; + data: + dbal:wrong + default_connection: monolith + EOF; $this->expectException(ParseException::class); $this->expectExceptionMessage('Mapping values are not allowed in multi-line blocks at line 2 (near "dbal:wrong").'); @@ -730,12 +730,12 @@ public function testUnindentedCollectionException() { $yaml = <<<'EOF' -collection: --item1 --item2 --item3 + collection: + -item1 + -item2 + -item3 -EOF; + EOF; $this->expectException(ParseException::class); @@ -746,11 +746,11 @@ public function testShortcutKeyUnindentedCollectionException() { $yaml = <<<'EOF' -collection: -- key: foo - foo: bar + collection: + - key: foo + foo: bar -EOF; + EOF; $this->expectException(ParseException::class); @@ -762,17 +762,17 @@ public function testMultipleDocumentsNotSupportedException() $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('/^Multiple documents are not supported.+/'); Yaml::parse(<<<'EOL' -# Ranking of 1998 home runs ---- -- Mark McGwire -- Sammy Sosa -- Ken Griffey - -# Team ranking ---- -- Chicago Cubs -- St Louis Cardinals -EOL + # Ranking of 1998 home runs + --- + - Mark McGwire + - Sammy Sosa + - Ken Griffey + + # Team ranking + --- + - Chicago Cubs + - St Louis Cardinals + EOL ); } @@ -780,24 +780,24 @@ public function testSequenceInAMapping() { $this->expectException(ParseException::class); Yaml::parse(<<<'EOF' -yaml: - hash: me - - array stuff -EOF + yaml: + hash: me + - array stuff + EOF ); } public function testSequenceInMappingStartedBySingleDashLine() { $yaml = <<<'EOT' -a: -- - b: - - - bar: baz -- foo -d: e -EOT; + a: + - + b: + - + bar: baz + - foo + d: e + EOT; $expected = [ 'a' => [ [ @@ -818,12 +818,12 @@ public function testSequenceInMappingStartedBySingleDashLine() public function testSequenceFollowedByCommentEmbeddedInMapping() { $yaml = <<<'EOT' -a: - b: - - c -# comment - d: e -EOT; + a: + b: + - c + # comment + d: e + EOT; $expected = [ 'a' => [ 'b' => ['c'], @@ -837,14 +837,14 @@ public function testSequenceFollowedByCommentEmbeddedInMapping() public function testNonStringFollowedByCommentEmbeddedInMapping() { $yaml = <<<'EOT' -a: - b: - {} -# comment - d: - 1.1 -# another comment -EOT; + a: + b: + {} + # comment + d: + 1.1 + # another comment + EOT; $expected = [ 'a' => [ 'b' => [], @@ -860,22 +860,22 @@ public static function getParseExceptionNotAffectedMultiLineStringLastResortPars $tests = []; $yaml = <<<'EOT' -a - b: -EOT; + a + b: + EOT; $tests['parse error on first line'] = [$yaml]; $yaml = <<<'EOT' -a + a -b - c: -EOT; + b + c: + EOT; $tests['parse error due to inconsistent indentation'] = [$yaml]; $yaml = <<<'EOT' - & * ! | > ' " % @ ` #, { asd a;sdasd }-@^qw3 -EOT; + & * ! | > ' " % @ ` #, { asd a;sdasd }-@^qw3 + EOT; $tests['symfony/symfony/issues/22967#issuecomment-322067742'] = [$yaml]; return $tests; @@ -891,11 +891,11 @@ public function testParseExceptionNotAffectedByMultiLineStringLastResortParsing( public function testMultiLineStringLastResortParsing() { $yaml = <<<'EOT' -test: - You can have things that don't look like strings here - true - yes you can -EOT; + test: + You can have things that don't look like strings here + true + yes you can + EOT; $expected = [ 'test' => 'You can have things that don\'t look like strings here true yes you can', ]; @@ -903,10 +903,10 @@ public function testMultiLineStringLastResortParsing() $this->assertSame($expected, $this->parser->parse($yaml)); $yaml = <<<'EOT' -a: - b - c -EOT; + a: + b + c + EOT; $expected = [ 'a' => 'b c', ]; @@ -918,10 +918,10 @@ public function testMappingInASequence() { $this->expectException(ParseException::class); Yaml::parse(<<<'EOF' -yaml: - - array stuff - hash: me -EOF + yaml: + - array stuff + hash: me + EOF ); } @@ -930,11 +930,11 @@ public function testScalarInSequence() $this->expectException(ParseException::class); $this->expectExceptionMessage('missing colon'); Yaml::parse(<<<'EOF' -foo: - - bar -"missing colon" - foo: bar -EOF + foo: + - bar + "missing colon" + foo: bar + EOF ); } @@ -951,13 +951,13 @@ public function testScalarInSequence() public function testMappingDuplicateKeyBlock() { $input = <<<'EOD' -parent: - child: first - child: duplicate -parent: - child: duplicate - child: duplicate -EOD; + parent: + child: first + child: duplicate + parent: + child: duplicate + child: duplicate + EOD; $this->expectException(ParseException::class); $this->expectExceptionMessage('Duplicate key "child" detected'); @@ -968,9 +968,9 @@ public function testMappingDuplicateKeyBlock() public function testMappingDuplicateKeyFlow() { $input = <<<'EOD' -parent: { child: first, child: duplicate } -parent: { child: duplicate, child: duplicate } -EOD; + parent: { child: first, child: duplicate } + parent: { child: duplicate, child: duplicate } + EOD; $this->expectException(ParseException::class); $this->expectExceptionMessage('Duplicate key "child" detected'); @@ -992,53 +992,53 @@ public static function getParseExceptionOnDuplicateData() $tests = []; $yaml = <<expectUserDeprecationMessage('Since symfony/yaml 7.2: Duplicate key "child" detected on line 4 whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.'); $yaml = <<assertSame(['hash' => null], Yaml::parse($input)); } @@ -1081,74 +1081,74 @@ public function testCommentAtTheRootIndent() ], ], ], Yaml::parse(<<<'EOF' -# comment 1 -services: -# comment 2 - # comment 3 - app.foo_service: - class: Foo -# comment 4 - # comment 5 - app/bar_service: - class: Bar -EOF + # comment 1 + services: + # comment 2 + # comment 3 + app.foo_service: + class: Foo + # comment 4 + # comment 5 + app/bar_service: + class: Bar + EOF )); } public function testStringBlockWithComments() { $this->assertSame(['content' => <<<'EOT' -# comment 1 -header + # comment 1 + header - # comment 2 - -

title

- + # comment 2 + +

title

+ -footer # comment3 -EOT + footer # comment3 + EOT ], Yaml::parse(<<<'EOF' -content: | - # comment 1 - header + content: | + # comment 1 + header - # comment 2 - -

title

- + # comment 2 + +

title

+ - footer # comment3 -EOF + footer # comment3 + EOF )); } public function testFoldedStringBlockWithComments() { $this->assertSame([['content' => <<<'EOT' -# comment 1 -header + # comment 1 + header - # comment 2 - -

title

- + # comment 2 + +

title

+ -footer # comment3 -EOT + footer # comment3 + EOT ]], Yaml::parse(<<<'EOF' -- - content: | - # comment 1 - header - - # comment 2 - -

title

- - - footer # comment3 -EOF + - + content: | + # comment 1 + header + + # comment 2 + +

title

+ + + footer # comment3 + EOF )); } @@ -1157,30 +1157,30 @@ public function testNestedFoldedStringBlockWithComments() $this->assertSame([[ 'title' => 'some title', 'content' => <<<'EOT' -# comment 1 -header + # comment 1 + header - # comment 2 - -

title

- + # comment 2 + +

title

+ -footer # comment3 -EOT, + footer # comment3 + EOT, ]], Yaml::parse(<<<'EOF' -- - title: some title - content: | - # comment 1 - header - - # comment 2 - -

title

- - - footer # comment3 -EOF + - + title: some title + content: | + # comment 1 + header + + # comment 2 + +

title

+ + + footer # comment3 + EOF )); } @@ -1201,41 +1201,41 @@ public function testReferenceResolvingInInlineStrings() 'baz' => ['foo'], 'foobar' => ['foo'], ], Yaml::parse(<<<'EOF' -var: &var var-value -scalar: *var -list: [ *var ] -list_in_list: [[ *var ]] -map_in_list: [ { key: *var } ] -embedded_mapping: [ key: *var ] -map: { key: *var } -list_in_map: { key: [*var] } -map_in_map: { foo: { bar: *var } } -foo: { bar: &baz baz } -bar: { foo: *baz } -baz: [ &foo foo ] -foobar: [ *foo ] -EOF + var: &var var-value + scalar: *var + list: [ *var ] + list_in_list: [[ *var ]] + map_in_list: [ { key: *var } ] + embedded_mapping: [ key: *var ] + map: { key: *var } + list_in_map: { key: [*var] } + map_in_map: { foo: { bar: *var } } + foo: { bar: &baz baz } + bar: { foo: *baz } + baz: [ &foo foo ] + foobar: [ *foo ] + EOF )); } public function testYamlDirective() { $yaml = <<<'EOF' -%YAML 1.2 ---- -foo: 1 -bar: 2 -EOF; + %YAML 1.2 + --- + foo: 1 + bar: 2 + EOF; $this->assertSame(['foo' => 1, 'bar' => 2], $this->parser->parse($yaml)); } public function testFloatKeys() { $yaml = <<<'EOF' -foo: - 1.2: "bar" - 1.3: "baz" -EOF; + foo: + 1.2: "bar" + 1.3: "baz" + EOF; $this->expectException(ParseException::class); $this->expectExceptionMessage('Numeric keys are not supported. Quote your evaluable mapping keys instead'); @@ -1246,9 +1246,9 @@ public function testFloatKeys() public function testBooleanKeys() { $yaml = <<<'EOF' -true: foo -false: bar -EOF; + true: foo + false: bar + EOF; $this->expectException(ParseException::class); $this->expectExceptionMessage('Non-string keys are not supported. Quote your evaluable mapping keys instead'); @@ -1259,15 +1259,15 @@ public function testBooleanKeys() public function testExplicitStringCasting() { $yaml = <<<'EOF' -'1.2': "bar" -!!str 1.3: "baz" + '1.2': "bar" + !!str 1.3: "baz" -'true': foo -!!str false: bar + 'true': foo + !!str false: bar -!!str null: 'null' -'~': 'null' -EOF; + !!str null: 'null' + '~': 'null' + EOF; $expected = [ '1.2' => 'bar', @@ -1284,8 +1284,8 @@ public function testExplicitStringCasting() public function testColonInMappingValueException() { $yaml = <<<'EOF' -foo: bar: baz -EOF; + foo: bar: baz + EOF; $this->expectException(ParseException::class); $this->expectExceptionMessage('A colon cannot be used in an unquoted mapping value'); @@ -1296,9 +1296,9 @@ public function testColonInMappingValueException() public function testColonInMappingValueExceptionNotTriggeredByColonInComment() { $yaml = <<<'EOT' -foo: - bar: foobar # Note: a comment after a colon -EOT; + foo: + bar: foobar # Note: a comment after a colon + EOT; $this->assertSame(['foo' => ['bar' => 'foobar']], $this->parser->parse($yaml)); } @@ -1314,35 +1314,35 @@ public static function getCommentLikeStringInScalarBlockData() $tests = []; $yaml = <<<'EOT' -pages: - - - title: some title - content: | - # comment 1 - header - - # comment 2 - -

title

- - - footer # comment3 -EOT; + pages: + - + title: some title + content: | + # comment 1 + header + + # comment 2 + +

title

+ + + footer # comment3 + EOT; $expected = [ 'pages' => [ [ 'title' => 'some title', 'content' => <<<'EOT' -# comment 1 -header + # comment 1 + header - # comment 2 - -

title

- + # comment 2 + +

title

+ -footer # comment3 -EOT + footer # comment3 + EOT , ], ], @@ -1350,44 +1350,44 @@ public static function getCommentLikeStringInScalarBlockData() $tests[] = [$yaml, $expected]; $yaml = <<<'EOT' -test: | - foo - # bar - baz -collection: - - one: | - foo - # bar - baz - - two: | - foo - # bar - baz -EOT; + test: | + foo + # bar + baz + collection: + - one: | + foo + # bar + baz + - two: | + foo + # bar + baz + EOT; $expected = [ 'test' => <<<'EOT' -foo -# bar -baz + foo + # bar + baz -EOT + EOT , 'collection' => [ [ 'one' => <<<'EOT' -foo -# bar -baz + foo + # bar + baz -EOT + EOT , ], [ 'two' => <<<'EOT' -foo -# bar -baz -EOT + foo + # bar + baz + EOT , ], ], @@ -1395,15 +1395,15 @@ public static function getCommentLikeStringInScalarBlockData() $tests[] = [$yaml, $expected]; $yaml = <<<'EOT' -foo: - bar: - scalar-block: > - line1 - line2> - baz: -# comment - foobar: ~ -EOT; + foo: + bar: + scalar-block: > + line1 + line2> + baz: + # comment + foobar: ~ + EOT; $expected = [ 'foo' => [ 'bar' => [ @@ -1417,13 +1417,13 @@ public static function getCommentLikeStringInScalarBlockData() $tests[] = [$yaml, $expected]; $yaml = <<<'EOT' -a: - b: hello -# c: | -# first row -# second row - d: hello -EOT; + a: + b: hello + # c: | + # first row + # second row + d: hello + EOT; $expected = [ 'a' => [ 'b' => 'hello', @@ -1438,21 +1438,21 @@ public static function getCommentLikeStringInScalarBlockData() public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks() { $yaml = <<<'EOT' -test: > -

A heading

+ test: > +

A heading

-
    -
  • a list
  • -
  • may be a good example
  • -
-EOT; +
    +
  • a list
  • +
  • may be a good example
  • +
+ EOT; $this->assertSame( [ 'test' => <<<'EOT' -

A heading

-
  • a list
  • may be a good example
-EOT +

A heading

+
  • a list
  • may be a good example
+ EOT , ], $this->parser->parse($yaml) @@ -1462,24 +1462,24 @@ public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks() public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks() { $yaml = <<<'EOT' -test: > -

A heading

+ test: > +

A heading

-
    -
  • a list
  • -
  • may be a good example
  • -
-EOT; +
    +
  • a list
  • +
  • may be a good example
  • +
+ EOT; $this->assertSame( [ 'test' => <<<'EOT' -

A heading

-
    -
  • a list
  • -
  • may be a good example
  • -
-EOT +

A heading

+
    +
  • a list
  • +
  • may be a good example
  • +
+ EOT , ], $this->parser->parse($yaml) @@ -1500,15 +1500,15 @@ public static function getBinaryData() 'containing spaces' => ['data: !!binary "SGVs bG8gd 29ybGQ="'], 'in block scalar' => [ <<<'EOT' -data: !!binary | - SGVsbG8gd29ybGQ= -EOT, + data: !!binary | + SGVsbG8gd29ybGQ= + EOT, ], 'containing spaces in block scalar' => [ <<<'EOT' -data: !!binary | - SGVs bG8gd 29ybGQ= -EOT, + data: !!binary | + SGVs bG8gd 29ybGQ= + EOT, ], ]; } @@ -1531,33 +1531,33 @@ public static function getInvalidBinaryData() 'misplaced equals character' => ['data: !!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'], 'length not a multiple of four in block scalar' => [ <<<'EOT' -data: !!binary | - SGVsbG8d29ybGQ= -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' => [ <<<'EOT' -data: !!binary | - SGVsbG8#d29ybGQ= -EOT + data: !!binary | + SGVsbG8#d29ybGQ= + EOT , '/The base64 encoded data \(.*\) contains invalid characters/', ], 'too many equals characters in block scalar' => [ <<<'EOT' -data: !!binary | - SGVsbG8gd29yb=== -EOT + data: !!binary | + SGVsbG8gd29yb=== + EOT , '/The base64 encoded data \(.*\) contains invalid characters/', ], 'misplaced equals character in block scalar' => [ <<<'EOT' -data: !!binary | - SGVsbG8gd29ybG=Q -EOT + data: !!binary | + SGVsbG8gd29ybG=Q + EOT , '/The base64 encoded data \(.*\) contains invalid characters/', ], @@ -1567,8 +1567,8 @@ public static function getInvalidBinaryData() public function testParseDateWithSubseconds() { $yaml = <<<'EOT' -date: 2002-12-14T01:23:45.670000Z -EOT; + date: 2002-12-14T01:23:45.670000Z + EOT; $this->assertSameData(['date' => 1039829025.67], $this->parser->parse($yaml)); } @@ -1576,8 +1576,8 @@ public function testParseDateWithSubseconds() public function testParseDateAsMappingValue() { $yaml = <<<'EOT' -date: 2002-12-14 -EOT; + date: 2002-12-14 + EOT; $expectedDate = (new \DateTimeImmutable()) ->setTimeZone(new \DateTimeZone('UTC')) ->setDate(2002, 12, 14) @@ -1601,49 +1601,49 @@ public static function parserThrowsExceptionWithCorrectLineNumberProvider() [ 4, <<<'YAML' -foo: - - - # bar - bar: "123", -YAML, + foo: + - + # bar + bar: "123", + YAML, ], [ 5, <<<'YAML' -foo: - - - # bar - # bar - bar: "123", -YAML, + foo: + - + # bar + # bar + bar: "123", + YAML, ], [ 8, <<<'YAML' -foo: - - - # foobar - baz: 123 -bar: - - - # bar - bar: "123", -YAML, + foo: + - + # foobar + baz: 123 + bar: + - + # bar + bar: "123", + YAML, ], [ 10, <<<'YAML' -foo: - - - # foobar - # foobar - baz: 123 -bar: - - - # bar - # bar - bar: "123", -YAML, + foo: + - + # foobar + # foobar + baz: 123 + bar: + - + # bar + # bar + bar: "123", + YAML, ], ]; } @@ -1651,12 +1651,12 @@ public static function parserThrowsExceptionWithCorrectLineNumberProvider() public function testParseMultiLineQuotedString() { $yaml = <<assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml)); } @@ -1664,10 +1664,10 @@ public function testParseMultiLineQuotedString() public function testMultiLineQuotedStringWithTrailingBackslash() { $yaml = <<assertSame(['foobar' => 'foobar'], $this->parser->parse($yaml)); } @@ -1675,11 +1675,11 @@ public function testMultiLineQuotedStringWithTrailingBackslash() public function testCommentCharactersInMultiLineQuotedStrings() { $yaml = << [ 'foobar' => 'foo #bar', @@ -1693,10 +1693,10 @@ public function testCommentCharactersInMultiLineQuotedStrings() public function testBlankLinesInQuotedMultiLineString() { $yaml = << "foo\nbar", ]; @@ -1707,10 +1707,10 @@ public function testBlankLinesInQuotedMultiLineString() public function testEscapedQuoteInQuotedMultiLineString() { $yaml = << 'foo "bar" baz', ]; @@ -1721,9 +1721,9 @@ public function testEscapedQuoteInQuotedMultiLineString() public function testBackslashInQuotedMultiLineString() { $yaml = << 'foo bar\\', ]; @@ -1760,12 +1760,12 @@ public static function wrappedUnquotedStringsProvider() public function testParseMultiLineUnquotedString() { $yaml = <<assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml)); } @@ -1781,51 +1781,51 @@ public static function unquotedStringWithTrailingComment() return [ 'comment after comma' => [ <<<'YAML' - { - foo: 3, # comment - bar: 3 - } - YAML, + { + foo: 3, # comment + bar: 3 + } + YAML, ['foo' => 3, 'bar' => 3], ], 'comment after space' => [ <<<'YAML' - { - foo: 3 # comment - } - YAML, + { + foo: 3 # comment + } + YAML, ['foo' => 3], ], 'comment after space, but missing space after #' => [ <<<'YAML' - { - foo: 3 #comment - } - YAML, + { + foo: 3 #comment + } + YAML, ['foo' => 3], ], 'comment after tab' => [ << 3], ], 'comment after tab, but missing space after #' => [ << 3], ], '# in mapping value' => [ <<<'YAML' - { - foo: example.com/#about - } - YAML, + { + foo: example.com/#about + } + YAML, ['foo' => 'example.com/#about'], ], ]; @@ -1842,11 +1842,11 @@ public static function escapedQuotationCharactersInQuotedStrings() return [ 'single quoted string' => [ << [ @@ -1859,11 +1859,11 @@ public static function escapedQuotationCharactersInQuotedStrings() ], 'double quoted string' => [ << [ @@ -1898,13 +1898,13 @@ public static function multiLineDataProvider() $tests = []; $yaml = <<<'EOF' -foo: -- bar: - one + foo: + - bar: + one - two - three -EOF; + two + three + EOF; $expected = [ 'foo' => [ [ @@ -1916,35 +1916,35 @@ public static function multiLineDataProvider() $tests[] = [$yaml, $expected, false]; $yaml = <<<'EOF' -bar -"foo" -EOF; + bar + "foo" + EOF; $expected = 'bar "foo"'; $tests[] = [$yaml, $expected, false]; $yaml = <<<'EOF' -bar -"foo -EOF; + bar + "foo + EOF; $expected = 'bar "foo'; $tests[] = [$yaml, $expected, false]; $yaml = <<<'EOF' -bar + bar -'foo' -EOF; + 'foo' + EOF; $expected = "bar\n'foo'"; $tests[] = [$yaml, $expected, false]; $yaml = <<<'EOF' -bar + bar -foo' -EOF; + foo' + EOF; $expected = "bar\nfoo'"; $tests[] = [$yaml, $expected, false]; @@ -1964,41 +1964,41 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'mapping' => [ ['foo' => 'bar', 'bar' => 'baz'], << [ ['foo' => 'bar', 'bar' => 'baz'], << [ ['foo', 'bar'], << [ ['foo', 'bar'], << [ @@ -2008,9 +2008,9 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ @@ -2022,9 +2022,9 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ [ @@ -2032,20 +2032,20 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ['entry2'], ], << [ ['foo' => ['bar', 'foobar'], 'bar' => ['baz']], << [ @@ -2057,11 +2057,11 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ @@ -2073,12 +2073,12 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'bar' => 'baz', ], << [ [ @@ -2091,11 +2091,11 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ @@ -2109,24 +2109,24 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ ['foo', ['bar' => 'baz']], << [ @@ -2137,11 +2137,11 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ @@ -2154,12 +2154,12 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ @@ -2172,40 +2172,40 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ], ], << [ "foo\nbar", << [ "foo\nbar", << [ ['foo' => "bar\nbaz"], << [ [ @@ -2216,12 +2216,12 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'param' => 'some', ], << [ [ @@ -2232,9 +2232,9 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'param' => 'some', ], << [ [ @@ -2245,9 +2245,9 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'param' => 'some', ], << [ [ @@ -2258,10 +2258,10 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array 'param' => 'some', ], << [ [ @@ -2275,33 +2275,33 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ['foo' => 'bar}'], ], << [ [ @@ -2315,14 +2315,14 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array ['te"st]'], ], <<expectExceptionMessage('Unable to parse at line 2 (near "foobar").'); $yaml = <<parser->parse($yaml); } @@ -2346,8 +2346,8 @@ public function testInlineMappingFollowedByMoreContentIsInvalid() $this->expectExceptionMessage('Unexpected token "baz" at line 1 (near "{ foo: bar } baz").'); $yaml = <<parser->parse($yaml); } @@ -2358,8 +2358,8 @@ public function testInlineSequenceFollowedByMoreContentIsInvalid() $this->expectExceptionMessage('Unexpected token ",bar," at line 1 (near "[\'foo\'],bar,").'); $yaml = <<parser->parse($yaml); } @@ -2391,35 +2391,35 @@ public static function taggedValuesProvider() 'quz' => new TaggedValue('long', 'this is a long text'), ], << - this is a long - text -YAML, + foo: !inline bar + quz: !long > + this is a long + text + YAML, ], 'sequences' => [ [new TaggedValue('foo', ['yaml']), new TaggedValue('quz', ['bar'])], << [ new TaggedValue('foo', ['foo' => new TaggedValue('quz', ['bar']), 'quz' => new TaggedValue('foo', ['quz' => 'bar'])]), << [ [new TaggedValue('foo', ['foo', 'bar']), new TaggedValue('quz', ['foo' => 'bar', 'quz' => new TaggedValue('bar', ['one' => 'bar'])])], << [ [new TaggedValue('foo', 'bar')], @@ -2430,24 +2430,24 @@ public static function taggedValuesProvider() [new TaggedValue('foo', ['foo', 'baz'])], ], << [ [ [new TaggedValue('foo', ['foo', 'baz'])], ], <<expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 1 (near "? "1"").'); @@ -2502,11 +2502,11 @@ public function testComplexMappingThrowsParseException() public function testComplexMappingNestedInMappingThrowsParseException() { $yaml = <<expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 2 (near "? "1"").'); @@ -2517,10 +2517,10 @@ public function testComplexMappingNestedInMappingThrowsParseException() public function testComplexMappingNestedInSequenceThrowsParseException() { $yaml = <<expectException(ParseException::class); $this->expectExceptionMessage('Complex mappings are not supported at line 1 (near "- ? "1"").'); @@ -2531,10 +2531,10 @@ public function testComplexMappingNestedInSequenceThrowsParseException() public function testParsingIniThrowsException() { $ini = <<expectException(ParseException::class); $this->expectExceptionMessage('Unable to parse at line 2 (near " foo = bar").'); @@ -2585,17 +2585,17 @@ public function testCanParseVeryLongValue() public function testParserCleansUpReferencesBetweenRuns() { $yaml = <<parser->parse($yaml); $yaml = <<expectException(ParseException::class); $this->expectExceptionMessage('Reference "foo" does not exist at line 2'); @@ -2606,12 +2606,12 @@ public function testParserCleansUpReferencesBetweenRuns() public function testPhpConstantTagMappingKey() { $yaml = << [ 'foo' => [ @@ -2637,13 +2637,13 @@ public function testWrongPhpConstantSyntax() public function testPhpConstantTagMappingAsScalarKey() { $yaml = <<assertSame([ 'map1' => [['foo' => 'value_0', 'bar' => 'value_1']], 'map2' => [['foo' => 'value_0', 'bar' => 'value_1']], @@ -2653,10 +2653,10 @@ public function testPhpConstantTagMappingAsScalarKey() public function testTagMappingAsScalarKey() { $yaml = <<assertSame([ 'map1' => [['0' => 'value_0', '1' => 'value_1']], ], $this->parser->parse($yaml)); @@ -2665,19 +2665,19 @@ public function testTagMappingAsScalarKey() public function testMergeKeysWhenMappingsAreParsedAsObjects() { $yaml = << (object) [ 'bar' => 1, @@ -2740,15 +2740,15 @@ public function testParsingNotReadableFilesThrowsException() public function testParseReferencesOnMergeKeys() { $yaml = << [ 'a' => 'foo', @@ -2768,15 +2768,15 @@ public function testParseReferencesOnMergeKeys() public function testParseReferencesOnMergeKeysWithMappingsParsedAsObjects() { $yaml = << (object) [ 'a' => 'foo', @@ -2796,8 +2796,8 @@ public function testParseReferencesOnMergeKeysWithMappingsParsedAsObjects() public function testEvalRefException() { $yaml = <<expectException(ParseException::class); $this->expectExceptionMessage('Reference "foo" does not exist'); @@ -2818,28 +2818,28 @@ public static function circularReferenceProvider() $tests = []; $yaml = <<- - #/string/bar -anyOfMultiline: - - $ref: >- - #/string/bar - second line -nested: - anyOf: - - $ref: >- - #/string/bar -YAML; + anyOf: + - $ref: >- + #/string/bar + anyOfMultiline: + - $ref: >- + #/string/bar + second line + nested: + anyOf: + - $ref: >- + #/string/bar + YAML; $expected = [ 'anyOf' => [ 0 => [ @@ -2894,11 +2894,11 @@ public static function indentedMappingData() $tests = []; $yaml = << [ [ @@ -2910,11 +2910,11 @@ public static function indentedMappingData() $tests['comment line is first line in indented block'] = [$yaml, $expected]; $yaml = << [ [ @@ -2927,10 +2927,10 @@ public static function indentedMappingData() $tests['mapping value on new line starting with a comment line'] = [$yaml, $expected]; $yaml = << [ [ @@ -2941,10 +2941,10 @@ public static function indentedMappingData() $tests['mapping in sequence starting on a new line'] = [$yaml, $expected]; $yaml = << [ 'bar' => 'baz', @@ -2958,11 +2958,11 @@ public static function indentedMappingData() public function testMultiLineComment() { $yaml = <<assertSame(['parameters' => 'abc'], $this->parser->parse($yaml)); } @@ -2970,14 +2970,14 @@ public function testMultiLineComment() public function testParseValueWithModifiers() { $yaml = <<assertSame( [ 'parameters' => [ @@ -2991,14 +2991,14 @@ public function testParseValueWithModifiers() public function testParseValueWithNegativeModifiers() { $yaml = <<assertSame( [ 'parameters' => [ @@ -3070,12 +3070,12 @@ public function testParsingMultipleDocuments() { $shortDocument = 'foo: bar'; $longDocument = <<assertSame([ 'unquoted' => ' ', 'quoted' => ' ', From 270c3752fe285e4ada47218776f7acb1b8f23e8a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 1 Aug 2025 14:58:41 +0200 Subject: [PATCH 14/14] run tests with PHPUnit 12.3 --- Tests/InlineTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/InlineTest.php b/Tests/InlineTest.php index dc1c2195..fd7bc80a 100644 --- a/Tests/InlineTest.php +++ b/Tests/InlineTest.php @@ -556,7 +556,7 @@ public static function getTestsForDump() } #[DataProvider('getTimestampTests')] - public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond) + public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone) { $expectedDate = (new \DateTimeImmutable($yaml, new \DateTimeZone('UTC')))->format('U'); $this->assertSame($microsecond ? (float) "$expectedDate.$microsecond" : (int) $expectedDate, Inline::parse($yaml)); @@ -586,7 +586,7 @@ public static function getTimestampTests(): array } #[DataProvider('getTimestampTests')] - public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond) + public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone) { $expected = (new \DateTimeImmutable($yaml)) ->setTimeZone(new \DateTimeZone('UTC'))