Skip to content

Commit

Permalink
expand constants
Browse files Browse the repository at this point in the history
in nearly every circumstance of this project we will want constants
  • Loading branch information
EntranceJew committed Jul 26, 2018
1 parent 933c45a commit 534d894
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function processFile(array $config)
$this->io->write(sprintf('<info>%s the "%s" file</info>', $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));
}
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/testcases/parse_constants/dist.yml
Original file line number Diff line number Diff line change
@@ -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'
7 changes: 7 additions & 0 deletions Tests/fixtures/testcases/parse_constants/existing.yml
Original file line number Diff line number Diff line change
@@ -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'
7 changes: 7 additions & 0 deletions Tests/fixtures/testcases/parse_constants/expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is auto-generated during the composer install
parameters:
transitions:
256:
from:
- 512
to: 4
1 change: 1 addition & 0 deletions Tests/fixtures/testcases/parse_constants/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: Constants are parsed
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 534d894

Please sign in to comment.