From 534d894d3827b9b1c65476c650fb8a1b472187f4 Mon Sep 17 00:00:00 2001 From: EntranceJew Date: Wed, 25 Jul 2018 18:34:40 -0400 Subject: [PATCH] expand constants in nearly every circumstance of this project we will want constants --- Processor.php | 4 ++-- Tests/ProcessorTest.php | 2 +- Tests/fixtures/testcases/parse_constants/dist.yml | 6 ++++++ Tests/fixtures/testcases/parse_constants/existing.yml | 7 +++++++ Tests/fixtures/testcases/parse_constants/expected.yml | 7 +++++++ Tests/fixtures/testcases/parse_constants/setup.yml | 1 + composer.json | 3 +++ 7 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Tests/fixtures/testcases/parse_constants/dist.yml create mode 100644 Tests/fixtures/testcases/parse_constants/existing.yml create mode 100644 Tests/fixtures/testcases/parse_constants/expected.yml create mode 100644 Tests/fixtures/testcases/parse_constants/setup.yml diff --git a/Processor.php b/Processor.php index 6dc208f..814e531 100644 --- a/Processor.php +++ b/Processor.php @@ -31,7 +31,7 @@ public function processFile(array $config) $this->io->write(sprintf('%s the "%s" file', $action, $realFile)); // Find the expected params - $expectedValues = $yamlParser->parse(file_get_contents($config['dist-file'])); + $expectedValues = $yamlParser->parse(file_get_contents($config['dist-file']), Yaml::PARSE_CONSTANT); if (!isset($expectedValues[$parameterKey])) { throw new \InvalidArgumentException(sprintf('The top-level key %s is missing.', $parameterKey)); } @@ -44,7 +44,7 @@ public function processFile(array $config) array($parameterKey => array()) ); if ($exists) { - $existingValues = $yamlParser->parse(file_get_contents($realFile)); + $existingValues = $yamlParser->parse(file_get_contents($realFile), Yaml::PARSE_CONSTANT); if ($existingValues === null) { $existingValues = array(); } diff --git a/Tests/ProcessorTest.php b/Tests/ProcessorTest.php index 4a1163d..dd55d7c 100644 --- a/Tests/ProcessorTest.php +++ b/Tests/ProcessorTest.php @@ -107,7 +107,7 @@ public function testParameterHandling($testCaseName) 'environment' => array(), 'interactive' => false, ), - (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml')) + (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml'), Yaml::PARSE_CONSTANT) ); $workingDir = sys_get_temp_dir() . '/incenteev_parameter_handler'; diff --git a/Tests/fixtures/testcases/parse_constants/dist.yml b/Tests/fixtures/testcases/parse_constants/dist.yml new file mode 100644 index 0000000..d0c172b --- /dev/null +++ b/Tests/fixtures/testcases/parse_constants/dist.yml @@ -0,0 +1,6 @@ +parameters: + transitions: + !php/const 'Symfony\Component\Yaml\Yaml::PARSE_CONSTANT': + from: + - !php/const 'Symfony\Component\Yaml\Yaml::PARSE_CUSTOM_TAGS' + to: !php/const 'Symfony\Component\Yaml\Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE' diff --git a/Tests/fixtures/testcases/parse_constants/existing.yml b/Tests/fixtures/testcases/parse_constants/existing.yml new file mode 100644 index 0000000..7f40bc6 --- /dev/null +++ b/Tests/fixtures/testcases/parse_constants/existing.yml @@ -0,0 +1,7 @@ +# This file is auto-generated during the composer install +parameters: + transitions: + !php/const 'Symfony\Component\Yaml\Yaml::PARSE_CONSTANT': + from: + - !php/const 'Symfony\Component\Yaml\Yaml::PARSE_CUSTOM_TAGS' + to: !php/const 'Symfony\Component\Yaml\Yaml::PARSE_OBJECT' diff --git a/Tests/fixtures/testcases/parse_constants/expected.yml b/Tests/fixtures/testcases/parse_constants/expected.yml new file mode 100644 index 0000000..79c3df8 --- /dev/null +++ b/Tests/fixtures/testcases/parse_constants/expected.yml @@ -0,0 +1,7 @@ +# This file is auto-generated during the composer install +parameters: + transitions: + 256: + from: + - 512 + to: 4 diff --git a/Tests/fixtures/testcases/parse_constants/setup.yml b/Tests/fixtures/testcases/parse_constants/setup.yml new file mode 100644 index 0000000..db0453f --- /dev/null +++ b/Tests/fixtures/testcases/parse_constants/setup.yml @@ -0,0 +1 @@ +title: Constants are parsed diff --git a/composer.json b/composer.json index f5e257b..2c93d53 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,9 @@ "autoload": { "psr-4": { "Incenteev\\ParameterHandler\\": "" } }, + "autoload-dev": { + "psr-4": { "Symfony\\Component\\Yaml\\": "" } + }, "extra": { "branch-alias": { "dev-master": "2.1.x-dev"