From dbd4014b18f60ea6910193a47491a5738db658ad Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sat, 10 Sep 2016 08:19:14 +0200 Subject: [PATCH 01/32] Added JSON support // Restructured directories / files / namespaces. --- Parser/JsonParser.php | 35 ++++++ Parser/ParseException.php | 8 ++ Parser/ParserInterface.php | 18 +++ Parser/YamlParser.php | 10 ++ .../AbstractProcessor.php | 107 +++++++++++++----- Processor/JsonProcessor.php | 19 ++++ Processor/ProcessorInterface.php | 15 +++ Processor/YamlProcessor.php | 21 ++++ ScriptHandler.php | 98 +++++++++++++++- ...rocessorTest.php => YamlProcessorTest.php} | 5 +- composer.json | 6 +- 11 files changed, 307 insertions(+), 35 deletions(-) create mode 100644 Parser/JsonParser.php create mode 100644 Parser/ParseException.php create mode 100644 Parser/ParserInterface.php create mode 100644 Parser/YamlParser.php rename Processor.php => Processor/AbstractProcessor.php (57%) create mode 100644 Processor/JsonProcessor.php create mode 100644 Processor/ProcessorInterface.php create mode 100644 Processor/YamlProcessor.php rename Tests/{ProcessorTest.php => YamlProcessorTest.php} (96%) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php new file mode 100644 index 0000000..98dcf2f --- /dev/null +++ b/Parser/JsonParser.php @@ -0,0 +1,35 @@ +io = $io; + $this->parser = $parser; + $this->io = $io; } + /** + * {@inheritdoc} + * + * @throws \InvalidArgumentException|\RuntimeException + */ public function processFile(array $config) { $config = $this->processConfig($config); - $realFile = $config['file']; + $realFile = $config['file']; $parameterKey = $config['parameter-key']; $exists = is_file($realFile); - $yamlParser = new Parser(); - $action = $exists ? 'Updating' : 'Creating'; $this->io->write(sprintf('%s the "%s" file', $action, $realFile)); // Find the expected params - $expectedValues = $yamlParser->parse(file_get_contents($config['dist-file'])); + $expectedValues = $this->parser->parse(file_get_contents($config['dist-file'])); + if (!isset($expectedValues[$parameterKey])) { throw new \InvalidArgumentException(sprintf('The top-level key %s is missing.', $parameterKey)); } @@ -39,14 +62,14 @@ public function processFile(array $config) // find the actual params $actualValues = array_merge( - // Preserve other top-level keys than `$parameterKey` in the file + // Preserve other top-level keys than `$parameterKey` in the file $expectedValues, - array($parameterKey => array()) + [$parameterKey => []] ); if ($exists) { - $existingValues = $yamlParser->parse(file_get_contents($realFile)); + $existingValues = $this->parser->parse(file_get_contents($realFile)); if ($existingValues === null) { - $existingValues = array(); + $existingValues = []; } if (!is_array($existingValues)) { throw new \InvalidArgumentException(sprintf('The existing "%s" file does not contain an array', $realFile)); @@ -56,14 +79,22 @@ public function processFile(array $config) $actualValues[$parameterKey] = $this->processParams($config, $expectedParams, (array) $actualValues[$parameterKey]); - if (!is_dir($dir = dirname($realFile))) { - mkdir($dir, 0755, true); + if (!is_dir($dir = dirname($realFile)) && (!@mkdir($dir, 0755, true) && !is_dir($dir))) { + throw new \RuntimeException( + sprintf('Error while creating directory "%s". Check path and permissions.', $dir) + ); } - file_put_contents($realFile, "# This file is auto-generated during the composer install\n" . Yaml::dump($actualValues, 99)); + $this->writeFile($realFile, $actualValues); } - private function processConfig(array $config) + /** + * @param array $config + * @return array + * + * @throws \InvalidArgumentException + */ + protected function processConfig(array $config) { if (empty($config['file'])) { throw new \InvalidArgumentException('The extra.incenteev-parameters.file setting is required to use this script handler.'); @@ -84,10 +115,10 @@ private function processConfig(array $config) return $config; } - private function processParams(array $config, array $expectedParams, array $actualParams) + protected function processParams(array $config, array $expectedParams, array $actualParams) { // Grab values for parameters that were renamed - $renameMap = empty($config['rename-map']) ? array() : (array) $config['rename-map']; + $renameMap = empty($config['rename-map']) ? [] : (array) $config['rename-map']; $actualParams = array_replace($actualParams, $this->processRenamedValues($renameMap, $actualParams)); $keepOutdatedParams = false; @@ -99,7 +130,7 @@ private function processParams(array $config, array $expectedParams, array $actu $actualParams = array_intersect_key($actualParams, $expectedParams); } - $envMap = empty($config['env-map']) ? array() : (array) $config['env-map']; + $envMap = empty($config['env-map']) ? [] : (array) $config['env-map']; // Add the params coming from the environment values $actualParams = array_replace($actualParams, $this->getEnvValues($envMap)); @@ -107,9 +138,18 @@ private function processParams(array $config, array $expectedParams, array $actu return $this->getParams($expectedParams, $actualParams); } - private function getEnvValues(array $envMap) + /** + * Parses environments variables by map and resolves correct types. + * As environment variables can only be strings, they are also parsed to allow specifying null, false, + * true or numbers easily. + * + * @param array $envMap Map used to map data from environment variable name to parameter name. + * + * @return array + */ + protected function getEnvValues(array $envMap) { - $params = array(); + $params = []; foreach ($envMap as $param => $env) { $value = getenv($env); if ($value) { @@ -146,7 +186,7 @@ private function getParams(array $expectedParams, array $actualParams) $isStarted = false; - foreach ($expectedParams as $key => $message) { + foreach ($expectedParams as $key => $value) { if (array_key_exists($key, $actualParams)) { continue; } @@ -156,12 +196,23 @@ private function getParams(array $expectedParams, array $actualParams) $this->io->write('Some parameters are missing. Please provide them.'); } - $default = Inline::dump($message); - $value = $this->io->ask(sprintf('%s (%s): ', $key, $default), $default); + $default = Inline::dump($value); + + $value = $this->io->ask(sprintf('%s (%s): ', $key, $default), $default); $actualParams[$key] = Inline::parse($value); } return $actualParams; } + + /** + * Persists configuration. + * + * @param string $file Filename to persist configuration to. + * @param array $configuration Configuration to persist as an array. + * + * @return bool TRUE after successful persisting the file, otherwise FALSE + */ + abstract protected function writeFile($file, array $configuration); } diff --git a/Processor/JsonProcessor.php b/Processor/JsonProcessor.php new file mode 100644 index 0000000..121b327 --- /dev/null +++ b/Processor/JsonProcessor.php @@ -0,0 +1,19 @@ +getComposer()->getPackage()->getExtra(); @@ -21,17 +63,67 @@ public static function buildParameters(Event $event) } if (array_keys($configs) !== range(0, count($configs) - 1)) { - $configs = array($configs); + $configs = [$configs]; } - $processor = new Processor($event->getIO()); - foreach ($configs as $config) { if (!is_array($config)) { throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array of configuration objects.'); } + $type = self::retrieveConfigurationTypeByFile($config['file']); + + if (self::CONFIGURATION_FORMAT_YAML === $type) { + $processor = new YamlProcessor($event->getIO(), new YamlParser()); + } elseif (self::FILE_EXTENSION_JSON === $type) { + $processor = new JsonProcessor($event->getIO(), new JsonParser()); + } else { + throw new \OutOfBoundsException( + sprintf( + 'Configuration format in file "%s" can not be handled. Currently supported: "%s"', + $config['file'], + var_export(self::$handable, true) + ) + ); + } + $processor->processFile($config); } + + echo 'ALALALALA'; + die; + } + + /** + * Returns type of configuration by file extension. + * + * @example Files with extension ".yml" will be resolved to type YAML, extension ".json" will be resolved to type JSON + * + * @param string $file File to parse extension from + * + * @author Benjamin Carl + * + * @return string Type of configuration, either self::FILE_TYPE_YAML or self::FILE_TYPE_JSON + * + * @throws \OutOfBoundsException + */ + private static function retrieveConfigurationTypeByFile($file) + { + $info = new \SplFileInfo($file); + $extension = strtolower($info->getExtension()); + + switch ($extension) { + case self::FILE_EXTENSION_YAML: + $type = self::CONFIGURATION_FORMAT_YAML; + break; + case self::FILE_EXTENSION_JSON: + $type = self::CONFIGURATION_FORMAT_JSON; + break; + default: + $type = null; + break; + } + + return $type; } } diff --git a/Tests/ProcessorTest.php b/Tests/YamlProcessorTest.php similarity index 96% rename from Tests/ProcessorTest.php rename to Tests/YamlProcessorTest.php index babf44a..38a9963 100644 --- a/Tests/ProcessorTest.php +++ b/Tests/YamlProcessorTest.php @@ -2,7 +2,8 @@ namespace Incenteev\ParameterHandler\Tests; -use Incenteev\ParameterHandler\Processor; +use Incenteev\ParameterHandler\Parser\YamlParser; +use Incenteev\ParameterHandler\Processor\YamlProcessor; use Prophecy\PhpUnit\ProphecyTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Yaml\Yaml; @@ -22,7 +23,7 @@ protected function setUp() parent::setUp(); $this->io = $this->prophesize('Composer\IO\IOInterface'); - $this->processor = new Processor($this->io->reveal()); + $this->processor = new YamlProcessor($this->io->reveal(), new YamlParser()); } protected function tearDown() diff --git a/composer.json b/composer.json index 784ccfd..7b2251c 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,14 @@ ], "require": { "php": ">=5.3.3", - "symfony/yaml": "~2.3|~3.0" + "symfony/yaml": "~2.3|~3.0", + "seld/jsonlint": "~1.4" }, "require-dev": { "composer/composer": "1.0.*@dev", "phpspec/prophecy-phpunit": "~1.0", - "symfony/filesystem": "~2.2" + "symfony/filesystem": "~2.2", + "symfony/var-dumper": "~2.8" }, "autoload": { "psr-4": { "Incenteev\\ParameterHandler\\": "" } From 55de495ae5eeda3f0952a8221af88d6739597b38 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sat, 10 Sep 2016 08:33:41 +0200 Subject: [PATCH 02/32] Aligned tests with new structure. --- Processor/AbstractProcessor.php | 4 ---- ScriptHandler.php | 7 ++++--- Tests/YamlProcessorTest.php | 4 ---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Processor/AbstractProcessor.php b/Processor/AbstractProcessor.php index 4734fc2..da6dba2 100644 --- a/Processor/AbstractProcessor.php +++ b/Processor/AbstractProcessor.php @@ -96,10 +96,6 @@ public function processFile(array $config) */ protected function processConfig(array $config) { - if (empty($config['file'])) { - throw new \InvalidArgumentException('The extra.incenteev-parameters.file setting is required to use this script handler.'); - } - if (empty($config['dist-file'])) { $config['dist-file'] = $config['file'].'.dist'; } diff --git a/ScriptHandler.php b/ScriptHandler.php index 1397d5c..426bff8 100644 --- a/ScriptHandler.php +++ b/ScriptHandler.php @@ -71,6 +71,10 @@ public static function buildParameters(Event $event) throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array of configuration objects.'); } + if (!array_key_exists('file', $config)) { + throw new \InvalidArgumentException('The extra.incenteev-parameters.file setting is required to use this script handler.'); + } + $type = self::retrieveConfigurationTypeByFile($config['file']); if (self::CONFIGURATION_FORMAT_YAML === $type) { @@ -89,9 +93,6 @@ public static function buildParameters(Event $event) $processor->processFile($config); } - - echo 'ALALALALA'; - die; } /** diff --git a/Tests/YamlProcessorTest.php b/Tests/YamlProcessorTest.php index 38a9963..1ce4f38 100644 --- a/Tests/YamlProcessorTest.php +++ b/Tests/YamlProcessorTest.php @@ -54,10 +54,6 @@ public function testInvalidConfiguration(array $config, $exceptionMessage) public function provideInvalidConfiguration() { return array( - 'no file' => array( - array(), - 'The extra.incenteev-parameters.file setting is required to use this script handler.', - ), 'missing default dist file' => array( array( 'file' => 'fixtures/invalid/missing.yml', From 82c088717664fea90714ce85ba5821499476b0b2 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sat, 10 Sep 2016 12:39:59 +0200 Subject: [PATCH 03/32] Restructured tests and related fixtures // Adapting first tests for JSON. --- Parser/JsonParser.php | 93 +++++++++- Parser/ParseException.php | 2 +- Processor/AbstractProcessor.php | 3 +- Processor/JsonProcessor.php | 2 +- Tests/JsonProcessorTest.php | 171 ++++++++++++++++++ Tests/YamlProcessorTest.php | 22 +-- .../invalid/invalid_existing_values.json} | 0 .../invalid/invalid_existing_values.json.dist | 5 + .../json/invalid/missing_top_level.json.dist | 3 + .../json/testcases/custom_dist_file/dist.json | 6 + .../testcases/custom_dist_file/existing.json | 6 + .../testcases/custom_dist_file/expected.json | 6 + .../json/testcases/custom_dist_file/setup.yml | 6 + .../invalid/invalid_existing_values.yml | 0 .../invalid/invalid_existing_values.yml.dist | 0 .../invalid/missing_top_level.yml.dist | 0 .../testcases/custom_dist_file/dist.yml | 0 .../testcases/custom_dist_file/existing.yml | 0 .../testcases/custom_dist_file/expected.yml | 0 .../testcases/custom_dist_file/setup.yml | 0 .../{ => yaml}/testcases/custom_key/dist.yml | 0 .../testcases/custom_key/existing.yml | 0 .../testcases/custom_key/expected.yml | 0 .../{ => yaml}/testcases/custom_key/setup.yml | 0 .../{ => yaml}/testcases/existent/dist.yml | 0 .../testcases/existent/existing.yml | 0 .../testcases/existent/expected.yml | 0 .../{ => yaml}/testcases/existent/setup.yml | 0 .../testcases/existent_empty/dist.yml | 0 .../testcases/existent_empty/existing.yml | 0 .../testcases/existent_empty/expected.yml | 0 .../testcases/existent_empty/setup.yml | 0 .../testcases/existent_without_key/dist.yml | 0 .../existent_without_key/existing.yml | 0 .../existent_without_key/expected.yml | 0 .../testcases/existent_without_key/setup.yml | 0 .../{ => yaml}/testcases/extra_keys/dist.yml | 0 .../testcases/extra_keys/existing.yml | 0 .../testcases/extra_keys/expected.yml | 0 .../{ => yaml}/testcases/extra_keys/setup.yml | 0 .../testcases/interaction_existent/dist.yml | 0 .../interaction_existent/existing.yml | 0 .../interaction_existent/expected.yml | 0 .../testcases/interaction_existent/setup.yml | 0 .../interaction_non_existent/dist.yml | 0 .../interaction_non_existent/expected.yml | 0 .../interaction_non_existent/setup.yml | 0 .../interaction_with_environment/dist.yml | 0 .../interaction_with_environment/expected.yml | 0 .../interaction_with_environment/setup.yml | 0 .../testcases/keep_outdated/dist.yml | 0 .../testcases/keep_outdated/existing.yml | 0 .../testcases/keep_outdated/expected.yml | 0 .../testcases/keep_outdated/setup.yml | 0 .../testcases/non_existent/dist.yml | 0 .../testcases/non_existent/expected.yml | 0 .../testcases/non_existent/setup.yml | 0 .../non_existent_with_environment/dist.yml | 0 .../expected.yml | 0 .../non_existent_with_environment/setup.yml | 0 .../testcases/remove_outdated/dist.yml | 0 .../testcases/remove_outdated/existing.yml | 0 .../testcases/remove_outdated/expected.yml | 0 .../testcases/remove_outdated/setup.yml | 0 .../{ => yaml}/testcases/renamed/dist.yml | 0 .../{ => yaml}/testcases/renamed/existing.yml | 0 .../{ => yaml}/testcases/renamed/expected.yml | 0 .../{ => yaml}/testcases/renamed/setup.yml | 0 .../renamed_and_environment/dist.yml | 0 .../renamed_and_environment/existing.yml | 0 .../renamed_and_environment/expected.yml | 0 .../renamed_and_environment/setup.yml | 0 .../{ => yaml}/testcases/subfolder/dist.yml | 0 .../testcases/subfolder/existing.yml | 0 .../testcases/subfolder/expected.yml | 0 .../{ => yaml}/testcases/subfolder/setup.yml | 0 .../testcases/subfolder_created/dist.yml | 0 .../testcases/subfolder_created/expected.yml | 0 .../testcases/subfolder_created/setup.yml | 0 79 files changed, 303 insertions(+), 22 deletions(-) create mode 100644 Tests/JsonProcessorTest.php rename Tests/fixtures/{testcases/existent_empty/existing.yml => json/invalid/invalid_existing_values.json} (100%) create mode 100644 Tests/fixtures/json/invalid/invalid_existing_values.json.dist create mode 100644 Tests/fixtures/json/invalid/missing_top_level.json.dist create mode 100644 Tests/fixtures/json/testcases/custom_dist_file/dist.json create mode 100644 Tests/fixtures/json/testcases/custom_dist_file/existing.json create mode 100644 Tests/fixtures/json/testcases/custom_dist_file/expected.json create mode 100644 Tests/fixtures/json/testcases/custom_dist_file/setup.yml rename Tests/fixtures/{ => yaml}/invalid/invalid_existing_values.yml (100%) rename Tests/fixtures/{ => yaml}/invalid/invalid_existing_values.yml.dist (100%) rename Tests/fixtures/{ => yaml}/invalid/missing_top_level.yml.dist (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_dist_file/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_dist_file/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_dist_file/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_dist_file/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_key/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_key/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_key/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/custom_key/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_empty/dist.yml (100%) create mode 100644 Tests/fixtures/yaml/testcases/existent_empty/existing.yml rename Tests/fixtures/{ => yaml}/testcases/existent_empty/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_empty/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_without_key/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_without_key/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_without_key/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/existent_without_key/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/extra_keys/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/extra_keys/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/extra_keys/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/extra_keys/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_existent/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_existent/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_existent/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_existent/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_non_existent/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_non_existent/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_non_existent/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_with_environment/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_with_environment/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/interaction_with_environment/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/keep_outdated/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/keep_outdated/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/keep_outdated/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/keep_outdated/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent_with_environment/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent_with_environment/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/non_existent_with_environment/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/remove_outdated/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/remove_outdated/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/remove_outdated/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/remove_outdated/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed_and_environment/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed_and_environment/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed_and_environment/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/renamed_and_environment/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder/existing.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder/setup.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder_created/dist.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder_created/expected.yml (100%) rename Tests/fixtures/{ => yaml}/testcases/subfolder_created/setup.yml (100%) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index 98dcf2f..af15d34 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -20,14 +20,91 @@ public function parse($value, $flags = 0, $assoc = true, $depth = 512) { $result = json_decode($value, $assoc, $depth, $flags); - if (null === $result) { - $errorCode = json_last_error(); - $errorMessage = json_last_error_msg(); - - // public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null) - throw new ParseException( - sprintf('Error "%s: %s" while parsing JSON string.', $errorCode, $errorMessage) - ); + return (null === $result) ? false : $result; + } + + /** + * Dumps a given array of data to JSON format. + * + * @param array $data Data to dump. + * + * @author Benjamin Carl + * + * @return string Dumped JSON data + */ + public function dump(array $data) + { + return $this->prettyPrint(json_encode($data)); + } + + /** + * Pretty print JSON custom implementation for compatibility with PHP < 5.4 and custom spacing. + * + * @param string $json JSON data to be pretty printed + * @param string $spacer Spacer used e.g. ' ' or "\t" + * @param int $spacing Multiplicator for spacer (count) + * + * @author Benjamin Carl + * + * @return string Pretty printed JSON data + */ + protected function prettyPrint($json, $spacer = ' ', $spacing = 2) + { + $result = ''; + $level = 0; + $in_quotes = false; + $in_escape = false; + $ends_line_level = null; + $json_length = strlen($json); + + for ($i = 0; $i < $json_length; ++$i) { + $char = $json[$i]; + $new_line_level = null; + $post = ''; + if ($ends_line_level !== null) { + $new_line_level = $ends_line_level; + $ends_line_level = null; + } + if ($in_escape) { + $in_escape = false; + } elseif ($char === '"') { + $in_quotes = !$in_quotes; + } elseif (!$in_quotes) { + switch ($char) { + case '}': + case ']': + $level--; + $ends_line_level = null; + $new_line_level = $level; + break; + + case '{': + case '[': + $level++; + case ',': + $ends_line_level = $level; + break; + + case ':': + $post = ' '; + break; + + case ' ': + case "\t": + case "\n": + case "\r": + $char = ''; + $ends_line_level = $new_line_level; + $new_line_level = null; + break; + } + } elseif ($char === '\\') { + $in_escape = true; + } + if ($new_line_level !== null) { + $result .= "\n".str_repeat(str_repeat($spacer, $spacing), $new_line_level); + } + $result .= $char.$post; } return $result; diff --git a/Parser/ParseException.php b/Parser/ParseException.php index 59a8cc4..b7cecb9 100644 --- a/Parser/ParseException.php +++ b/Parser/ParseException.php @@ -2,7 +2,7 @@ namespace Incenteev\ParameterHandler\Parser; -class ParseException extends \Symfony\Component\Yaml\Exception\ParseException +class ParseException extends \InvalidArgumentException { // Intentionally left empty. } diff --git a/Processor/AbstractProcessor.php b/Processor/AbstractProcessor.php index da6dba2..6238302 100644 --- a/Processor/AbstractProcessor.php +++ b/Processor/AbstractProcessor.php @@ -90,6 +90,7 @@ public function processFile(array $config) /** * @param array $config + * * @return array * * @throws \InvalidArgumentException @@ -194,7 +195,7 @@ private function getParams(array $expectedParams, array $actualParams) $default = Inline::dump($value); - $value = $this->io->ask(sprintf('%s (%s): ', $key, $default), $default); + $value = $this->io->ask(sprintf('%s (%s): ', $key, $default), $default); $actualParams[$key] = Inline::parse($value); } diff --git a/Processor/JsonProcessor.php b/Processor/JsonProcessor.php index 121b327..e963541 100644 --- a/Processor/JsonProcessor.php +++ b/Processor/JsonProcessor.php @@ -13,7 +13,7 @@ protected function writeFile($filename, array $configuration) { return false !== file_put_contents( - $filename, json_encode($configuration, JSON_PRETTY_PRINT) + $filename, $this->parser->dump($configuration) ); } } diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php new file mode 100644 index 0000000..f8b4ec0 --- /dev/null +++ b/Tests/JsonProcessorTest.php @@ -0,0 +1,171 @@ +io = $this->prophesize('Composer\IO\IOInterface'); + $this->processor = new JsonProcessor($this->io->reveal(), new JsonParser()); + } + + protected function tearDown() + { + parent::tearDown(); + + foreach ($this->environmentBackup as $var => $value) { + if (false === $value) { + putenv($var); + } else { + putenv($var.'='.$value); + } + } + } + + /** + * @dataProvider provideInvalidConfiguration + */ + public function testInvalidConfiguration(array $config, $exceptionMessage) + { + chdir(__DIR__); + + $this->setExpectedException('InvalidArgumentException', $exceptionMessage); + + $this->processor->processFile($config); + } + + public function provideInvalidConfiguration() + { + return [ + 'missing default dist file' => [ + [ + 'file' => 'fixtures/json/invalid/missing.json', + ], + 'The dist file "fixtures/json/invalid/missing.json.dist" does not exist. Check your dist-file config or create it.', + ], + 'missing custom dist file' => [ + [ + 'file' => 'fixtures/json/invalid/missing.json', + 'dist-file' => 'fixtures/json/invalid/non-existent.dist.json', + ], + 'The dist file "fixtures/json/invalid/non-existent.dist.json" does not exist. Check your dist-file config or create it.', + ], + 'missing top level key in dist file' => [ + [ + 'file' => 'fixtures/json/invalid/missing_top_level.json', + ], + 'The top-level key parameters is missing.', + ], + 'invalid values in the existing file' => [ + [ + 'file' => 'fixtures/json/invalid/invalid_existing_values.json', + ], + 'The existing "fixtures/json/invalid/invalid_existing_values.json" file does not contain an array', + ], + ]; + } + + /** + * @dataProvider provideParameterHandlingTestCases + */ + public function testParameterHandling($testCaseName) + { + $dataDir = __DIR__.'/fixtures/json/testcases/'.$testCaseName; + + $testCase = array_replace_recursive( + [ + 'title' => 'unknown test', + 'config' => [ + 'file' => 'parameters.json', + ], + 'dist-file' => 'parameters.json.dist', + 'environment' => [], + 'interactive' => false, + ], + (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml')) + ); + + $workingDir = sys_get_temp_dir().'/incenteev_parameter_handler'; + $exists = $this->initializeTestCase($testCase, $dataDir, $workingDir); + + $message = sprintf('%s the "%s" file', $exists ? 'Updating' : 'Creating', $testCase['config']['file']); + $this->io->write($message)->shouldBeCalled(); + + $this->setInteractionExpectations($testCase); + + $this->processor->processFile($testCase['config']); + + $this->assertFileEquals($dataDir.'/expected.json', $workingDir.'/'.$testCase['config']['file'], $testCase['title']); + } + + private function initializeTestCase(array $testCase, $dataDir, $workingDir) + { + $fs = new Filesystem(); + + if (is_dir($workingDir)) { + $fs->remove($workingDir); + } + + $fs->copy($dataDir.'/dist.json', $workingDir.'/'.$testCase['dist-file']); + + if ($exists = file_exists($dataDir.'/existing.json')) { + $fs->copy($dataDir.'/existing.json', $workingDir.'/'.$testCase['config']['file']); + } + + foreach ($testCase['environment'] as $var => $value) { + $this->environmentBackup[$var] = getenv($var); + putenv($var.'='.$value); + }; + + chdir($workingDir); + + return $exists; + } + + private function setInteractionExpectations(array $testCase) + { + $this->io->isInteractive()->willReturn($testCase['interactive']); + + if (!$testCase['interactive']) { + return; + } + + if (!empty($testCase['requested_params'])) { + $this->io->write('Some parameters are missing. Please provide them.')->shouldBeCalledTimes(1); + } + + foreach ($testCase['requested_params'] as $param => $settings) { + $this->io->ask(sprintf('%s (%s): ', $param, $settings['default']), $settings['default']) + ->willReturn($settings['input']) + ->shouldBeCalled(); + } + } + + public function provideParameterHandlingTestCases() + { + $tests = []; + + foreach (glob(__DIR__.'/fixtures/json/testcases/*/') as $folder) { + $tests[] = [basename($folder)]; + } + + return $tests; + } +} diff --git a/Tests/YamlProcessorTest.php b/Tests/YamlProcessorTest.php index 1ce4f38..13785e7 100644 --- a/Tests/YamlProcessorTest.php +++ b/Tests/YamlProcessorTest.php @@ -8,7 +8,7 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Yaml\Yaml; -class ProcessorTest extends ProphecyTestCase +class YamlProcessorTest extends ProphecyTestCase { private $io; private $environmentBackup = array(); @@ -56,28 +56,28 @@ public function provideInvalidConfiguration() return array( 'missing default dist file' => array( array( - 'file' => 'fixtures/invalid/missing.yml', + 'file' => 'fixtures/yaml/invalid/missing.yml', ), - 'The dist file "fixtures/invalid/missing.yml.dist" does not exist. Check your dist-file config or create it.', + 'The dist file "fixtures/yaml/invalid/missing.yml.dist" does not exist. Check your dist-file config or create it.', ), 'missing custom dist file' => array( array( - 'file' => 'fixtures/invalid/missing.yml', - 'dist-file' => 'fixtures/invalid/non-existent.dist.yml', + 'file' => 'fixtures/yaml/invalid/missing.yml', + 'dist-file' => 'fixtures/yaml/invalid/non-existent.dist.yml', ), - 'The dist file "fixtures/invalid/non-existent.dist.yml" does not exist. Check your dist-file config or create it.', + 'The dist file "fixtures/yaml/invalid/non-existent.dist.yml" does not exist. Check your dist-file config or create it.', ), 'missing top level key in dist file' => array( array( - 'file' => 'fixtures/invalid/missing_top_level.yml', + 'file' => 'fixtures/yaml/invalid/missing_top_level.yml', ), 'The top-level key parameters is missing.', ), 'invalid values in the existing file' => array( array( - 'file' => 'fixtures/invalid/invalid_existing_values.yml', + 'file' => 'fixtures/yaml/invalid/invalid_existing_values.yml', ), - 'The existing "fixtures/invalid/invalid_existing_values.yml" file does not contain an array', + 'The existing "fixtures/yaml/invalid/invalid_existing_values.yml" file does not contain an array', ), ); } @@ -87,7 +87,7 @@ public function provideInvalidConfiguration() */ public function testParameterHandling($testCaseName) { - $dataDir = __DIR__.'/fixtures/testcases/'.$testCaseName; + $dataDir = __DIR__.'/fixtures/yaml/testcases/'.$testCaseName; $testCase = array_replace_recursive( array( @@ -162,7 +162,7 @@ public function provideParameterHandlingTestCases() { $tests = array(); - foreach (glob(__DIR__.'/fixtures/testcases/*/') as $folder) { + foreach (glob(__DIR__.'/fixtures/yaml/testcases/*/') as $folder) { $tests[] = array(basename($folder)); } diff --git a/Tests/fixtures/testcases/existent_empty/existing.yml b/Tests/fixtures/json/invalid/invalid_existing_values.json similarity index 100% rename from Tests/fixtures/testcases/existent_empty/existing.yml rename to Tests/fixtures/json/invalid/invalid_existing_values.json diff --git a/Tests/fixtures/json/invalid/invalid_existing_values.json.dist b/Tests/fixtures/json/invalid/invalid_existing_values.json.dist new file mode 100644 index 0000000..e797330 --- /dev/null +++ b/Tests/fixtures/json/invalid/invalid_existing_values.json.dist @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} diff --git a/Tests/fixtures/json/invalid/missing_top_level.json.dist b/Tests/fixtures/json/invalid/missing_top_level.json.dist new file mode 100644 index 0000000..e63d37b --- /dev/null +++ b/Tests/fixtures/json/invalid/missing_top_level.json.dist @@ -0,0 +1,3 @@ +{ + "foo": "bar" +} diff --git a/Tests/fixtures/json/testcases/custom_dist_file/dist.json b/Tests/fixtures/json/testcases/custom_dist_file/dist.json new file mode 100644 index 0000000..e66031d --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_dist_file/dist.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_dist_file/existing.json b/Tests/fixtures/json/testcases/custom_dist_file/existing.json new file mode 100644 index 0000000..10608a6 --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_dist_file/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_dist_file/expected.json b/Tests/fixtures/json/testcases/custom_dist_file/expected.json new file mode 100644 index 0000000..10608a6 --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_dist_file/expected.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_dist_file/setup.yml b/Tests/fixtures/json/testcases/custom_dist_file/setup.yml new file mode 100644 index 0000000..d3d7fd9 --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_dist_file/setup.yml @@ -0,0 +1,6 @@ +title: Existing values are kept + +config: + dist-file: parameters.dist.json + +dist-file: parameters.dist.json diff --git a/Tests/fixtures/invalid/invalid_existing_values.yml b/Tests/fixtures/yaml/invalid/invalid_existing_values.yml similarity index 100% rename from Tests/fixtures/invalid/invalid_existing_values.yml rename to Tests/fixtures/yaml/invalid/invalid_existing_values.yml diff --git a/Tests/fixtures/invalid/invalid_existing_values.yml.dist b/Tests/fixtures/yaml/invalid/invalid_existing_values.yml.dist similarity index 100% rename from Tests/fixtures/invalid/invalid_existing_values.yml.dist rename to Tests/fixtures/yaml/invalid/invalid_existing_values.yml.dist diff --git a/Tests/fixtures/invalid/missing_top_level.yml.dist b/Tests/fixtures/yaml/invalid/missing_top_level.yml.dist similarity index 100% rename from Tests/fixtures/invalid/missing_top_level.yml.dist rename to Tests/fixtures/yaml/invalid/missing_top_level.yml.dist diff --git a/Tests/fixtures/testcases/custom_dist_file/dist.yml b/Tests/fixtures/yaml/testcases/custom_dist_file/dist.yml similarity index 100% rename from Tests/fixtures/testcases/custom_dist_file/dist.yml rename to Tests/fixtures/yaml/testcases/custom_dist_file/dist.yml diff --git a/Tests/fixtures/testcases/custom_dist_file/existing.yml b/Tests/fixtures/yaml/testcases/custom_dist_file/existing.yml similarity index 100% rename from Tests/fixtures/testcases/custom_dist_file/existing.yml rename to Tests/fixtures/yaml/testcases/custom_dist_file/existing.yml diff --git a/Tests/fixtures/testcases/custom_dist_file/expected.yml b/Tests/fixtures/yaml/testcases/custom_dist_file/expected.yml similarity index 100% rename from Tests/fixtures/testcases/custom_dist_file/expected.yml rename to Tests/fixtures/yaml/testcases/custom_dist_file/expected.yml diff --git a/Tests/fixtures/testcases/custom_dist_file/setup.yml b/Tests/fixtures/yaml/testcases/custom_dist_file/setup.yml similarity index 100% rename from Tests/fixtures/testcases/custom_dist_file/setup.yml rename to Tests/fixtures/yaml/testcases/custom_dist_file/setup.yml diff --git a/Tests/fixtures/testcases/custom_key/dist.yml b/Tests/fixtures/yaml/testcases/custom_key/dist.yml similarity index 100% rename from Tests/fixtures/testcases/custom_key/dist.yml rename to Tests/fixtures/yaml/testcases/custom_key/dist.yml diff --git a/Tests/fixtures/testcases/custom_key/existing.yml b/Tests/fixtures/yaml/testcases/custom_key/existing.yml similarity index 100% rename from Tests/fixtures/testcases/custom_key/existing.yml rename to Tests/fixtures/yaml/testcases/custom_key/existing.yml diff --git a/Tests/fixtures/testcases/custom_key/expected.yml b/Tests/fixtures/yaml/testcases/custom_key/expected.yml similarity index 100% rename from Tests/fixtures/testcases/custom_key/expected.yml rename to Tests/fixtures/yaml/testcases/custom_key/expected.yml diff --git a/Tests/fixtures/testcases/custom_key/setup.yml b/Tests/fixtures/yaml/testcases/custom_key/setup.yml similarity index 100% rename from Tests/fixtures/testcases/custom_key/setup.yml rename to Tests/fixtures/yaml/testcases/custom_key/setup.yml diff --git a/Tests/fixtures/testcases/existent/dist.yml b/Tests/fixtures/yaml/testcases/existent/dist.yml similarity index 100% rename from Tests/fixtures/testcases/existent/dist.yml rename to Tests/fixtures/yaml/testcases/existent/dist.yml diff --git a/Tests/fixtures/testcases/existent/existing.yml b/Tests/fixtures/yaml/testcases/existent/existing.yml similarity index 100% rename from Tests/fixtures/testcases/existent/existing.yml rename to Tests/fixtures/yaml/testcases/existent/existing.yml diff --git a/Tests/fixtures/testcases/existent/expected.yml b/Tests/fixtures/yaml/testcases/existent/expected.yml similarity index 100% rename from Tests/fixtures/testcases/existent/expected.yml rename to Tests/fixtures/yaml/testcases/existent/expected.yml diff --git a/Tests/fixtures/testcases/existent/setup.yml b/Tests/fixtures/yaml/testcases/existent/setup.yml similarity index 100% rename from Tests/fixtures/testcases/existent/setup.yml rename to Tests/fixtures/yaml/testcases/existent/setup.yml diff --git a/Tests/fixtures/testcases/existent_empty/dist.yml b/Tests/fixtures/yaml/testcases/existent_empty/dist.yml similarity index 100% rename from Tests/fixtures/testcases/existent_empty/dist.yml rename to Tests/fixtures/yaml/testcases/existent_empty/dist.yml diff --git a/Tests/fixtures/yaml/testcases/existent_empty/existing.yml b/Tests/fixtures/yaml/testcases/existent_empty/existing.yml new file mode 100644 index 0000000..e69de29 diff --git a/Tests/fixtures/testcases/existent_empty/expected.yml b/Tests/fixtures/yaml/testcases/existent_empty/expected.yml similarity index 100% rename from Tests/fixtures/testcases/existent_empty/expected.yml rename to Tests/fixtures/yaml/testcases/existent_empty/expected.yml diff --git a/Tests/fixtures/testcases/existent_empty/setup.yml b/Tests/fixtures/yaml/testcases/existent_empty/setup.yml similarity index 100% rename from Tests/fixtures/testcases/existent_empty/setup.yml rename to Tests/fixtures/yaml/testcases/existent_empty/setup.yml diff --git a/Tests/fixtures/testcases/existent_without_key/dist.yml b/Tests/fixtures/yaml/testcases/existent_without_key/dist.yml similarity index 100% rename from Tests/fixtures/testcases/existent_without_key/dist.yml rename to Tests/fixtures/yaml/testcases/existent_without_key/dist.yml diff --git a/Tests/fixtures/testcases/existent_without_key/existing.yml b/Tests/fixtures/yaml/testcases/existent_without_key/existing.yml similarity index 100% rename from Tests/fixtures/testcases/existent_without_key/existing.yml rename to Tests/fixtures/yaml/testcases/existent_without_key/existing.yml diff --git a/Tests/fixtures/testcases/existent_without_key/expected.yml b/Tests/fixtures/yaml/testcases/existent_without_key/expected.yml similarity index 100% rename from Tests/fixtures/testcases/existent_without_key/expected.yml rename to Tests/fixtures/yaml/testcases/existent_without_key/expected.yml diff --git a/Tests/fixtures/testcases/existent_without_key/setup.yml b/Tests/fixtures/yaml/testcases/existent_without_key/setup.yml similarity index 100% rename from Tests/fixtures/testcases/existent_without_key/setup.yml rename to Tests/fixtures/yaml/testcases/existent_without_key/setup.yml diff --git a/Tests/fixtures/testcases/extra_keys/dist.yml b/Tests/fixtures/yaml/testcases/extra_keys/dist.yml similarity index 100% rename from Tests/fixtures/testcases/extra_keys/dist.yml rename to Tests/fixtures/yaml/testcases/extra_keys/dist.yml diff --git a/Tests/fixtures/testcases/extra_keys/existing.yml b/Tests/fixtures/yaml/testcases/extra_keys/existing.yml similarity index 100% rename from Tests/fixtures/testcases/extra_keys/existing.yml rename to Tests/fixtures/yaml/testcases/extra_keys/existing.yml diff --git a/Tests/fixtures/testcases/extra_keys/expected.yml b/Tests/fixtures/yaml/testcases/extra_keys/expected.yml similarity index 100% rename from Tests/fixtures/testcases/extra_keys/expected.yml rename to Tests/fixtures/yaml/testcases/extra_keys/expected.yml diff --git a/Tests/fixtures/testcases/extra_keys/setup.yml b/Tests/fixtures/yaml/testcases/extra_keys/setup.yml similarity index 100% rename from Tests/fixtures/testcases/extra_keys/setup.yml rename to Tests/fixtures/yaml/testcases/extra_keys/setup.yml diff --git a/Tests/fixtures/testcases/interaction_existent/dist.yml b/Tests/fixtures/yaml/testcases/interaction_existent/dist.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_existent/dist.yml rename to Tests/fixtures/yaml/testcases/interaction_existent/dist.yml diff --git a/Tests/fixtures/testcases/interaction_existent/existing.yml b/Tests/fixtures/yaml/testcases/interaction_existent/existing.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_existent/existing.yml rename to Tests/fixtures/yaml/testcases/interaction_existent/existing.yml diff --git a/Tests/fixtures/testcases/interaction_existent/expected.yml b/Tests/fixtures/yaml/testcases/interaction_existent/expected.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_existent/expected.yml rename to Tests/fixtures/yaml/testcases/interaction_existent/expected.yml diff --git a/Tests/fixtures/testcases/interaction_existent/setup.yml b/Tests/fixtures/yaml/testcases/interaction_existent/setup.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_existent/setup.yml rename to Tests/fixtures/yaml/testcases/interaction_existent/setup.yml diff --git a/Tests/fixtures/testcases/interaction_non_existent/dist.yml b/Tests/fixtures/yaml/testcases/interaction_non_existent/dist.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_non_existent/dist.yml rename to Tests/fixtures/yaml/testcases/interaction_non_existent/dist.yml diff --git a/Tests/fixtures/testcases/interaction_non_existent/expected.yml b/Tests/fixtures/yaml/testcases/interaction_non_existent/expected.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_non_existent/expected.yml rename to Tests/fixtures/yaml/testcases/interaction_non_existent/expected.yml diff --git a/Tests/fixtures/testcases/interaction_non_existent/setup.yml b/Tests/fixtures/yaml/testcases/interaction_non_existent/setup.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_non_existent/setup.yml rename to Tests/fixtures/yaml/testcases/interaction_non_existent/setup.yml diff --git a/Tests/fixtures/testcases/interaction_with_environment/dist.yml b/Tests/fixtures/yaml/testcases/interaction_with_environment/dist.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_with_environment/dist.yml rename to Tests/fixtures/yaml/testcases/interaction_with_environment/dist.yml diff --git a/Tests/fixtures/testcases/interaction_with_environment/expected.yml b/Tests/fixtures/yaml/testcases/interaction_with_environment/expected.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_with_environment/expected.yml rename to Tests/fixtures/yaml/testcases/interaction_with_environment/expected.yml diff --git a/Tests/fixtures/testcases/interaction_with_environment/setup.yml b/Tests/fixtures/yaml/testcases/interaction_with_environment/setup.yml similarity index 100% rename from Tests/fixtures/testcases/interaction_with_environment/setup.yml rename to Tests/fixtures/yaml/testcases/interaction_with_environment/setup.yml diff --git a/Tests/fixtures/testcases/keep_outdated/dist.yml b/Tests/fixtures/yaml/testcases/keep_outdated/dist.yml similarity index 100% rename from Tests/fixtures/testcases/keep_outdated/dist.yml rename to Tests/fixtures/yaml/testcases/keep_outdated/dist.yml diff --git a/Tests/fixtures/testcases/keep_outdated/existing.yml b/Tests/fixtures/yaml/testcases/keep_outdated/existing.yml similarity index 100% rename from Tests/fixtures/testcases/keep_outdated/existing.yml rename to Tests/fixtures/yaml/testcases/keep_outdated/existing.yml diff --git a/Tests/fixtures/testcases/keep_outdated/expected.yml b/Tests/fixtures/yaml/testcases/keep_outdated/expected.yml similarity index 100% rename from Tests/fixtures/testcases/keep_outdated/expected.yml rename to Tests/fixtures/yaml/testcases/keep_outdated/expected.yml diff --git a/Tests/fixtures/testcases/keep_outdated/setup.yml b/Tests/fixtures/yaml/testcases/keep_outdated/setup.yml similarity index 100% rename from Tests/fixtures/testcases/keep_outdated/setup.yml rename to Tests/fixtures/yaml/testcases/keep_outdated/setup.yml diff --git a/Tests/fixtures/testcases/non_existent/dist.yml b/Tests/fixtures/yaml/testcases/non_existent/dist.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent/dist.yml rename to Tests/fixtures/yaml/testcases/non_existent/dist.yml diff --git a/Tests/fixtures/testcases/non_existent/expected.yml b/Tests/fixtures/yaml/testcases/non_existent/expected.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent/expected.yml rename to Tests/fixtures/yaml/testcases/non_existent/expected.yml diff --git a/Tests/fixtures/testcases/non_existent/setup.yml b/Tests/fixtures/yaml/testcases/non_existent/setup.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent/setup.yml rename to Tests/fixtures/yaml/testcases/non_existent/setup.yml diff --git a/Tests/fixtures/testcases/non_existent_with_environment/dist.yml b/Tests/fixtures/yaml/testcases/non_existent_with_environment/dist.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent_with_environment/dist.yml rename to Tests/fixtures/yaml/testcases/non_existent_with_environment/dist.yml diff --git a/Tests/fixtures/testcases/non_existent_with_environment/expected.yml b/Tests/fixtures/yaml/testcases/non_existent_with_environment/expected.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent_with_environment/expected.yml rename to Tests/fixtures/yaml/testcases/non_existent_with_environment/expected.yml diff --git a/Tests/fixtures/testcases/non_existent_with_environment/setup.yml b/Tests/fixtures/yaml/testcases/non_existent_with_environment/setup.yml similarity index 100% rename from Tests/fixtures/testcases/non_existent_with_environment/setup.yml rename to Tests/fixtures/yaml/testcases/non_existent_with_environment/setup.yml diff --git a/Tests/fixtures/testcases/remove_outdated/dist.yml b/Tests/fixtures/yaml/testcases/remove_outdated/dist.yml similarity index 100% rename from Tests/fixtures/testcases/remove_outdated/dist.yml rename to Tests/fixtures/yaml/testcases/remove_outdated/dist.yml diff --git a/Tests/fixtures/testcases/remove_outdated/existing.yml b/Tests/fixtures/yaml/testcases/remove_outdated/existing.yml similarity index 100% rename from Tests/fixtures/testcases/remove_outdated/existing.yml rename to Tests/fixtures/yaml/testcases/remove_outdated/existing.yml diff --git a/Tests/fixtures/testcases/remove_outdated/expected.yml b/Tests/fixtures/yaml/testcases/remove_outdated/expected.yml similarity index 100% rename from Tests/fixtures/testcases/remove_outdated/expected.yml rename to Tests/fixtures/yaml/testcases/remove_outdated/expected.yml diff --git a/Tests/fixtures/testcases/remove_outdated/setup.yml b/Tests/fixtures/yaml/testcases/remove_outdated/setup.yml similarity index 100% rename from Tests/fixtures/testcases/remove_outdated/setup.yml rename to Tests/fixtures/yaml/testcases/remove_outdated/setup.yml diff --git a/Tests/fixtures/testcases/renamed/dist.yml b/Tests/fixtures/yaml/testcases/renamed/dist.yml similarity index 100% rename from Tests/fixtures/testcases/renamed/dist.yml rename to Tests/fixtures/yaml/testcases/renamed/dist.yml diff --git a/Tests/fixtures/testcases/renamed/existing.yml b/Tests/fixtures/yaml/testcases/renamed/existing.yml similarity index 100% rename from Tests/fixtures/testcases/renamed/existing.yml rename to Tests/fixtures/yaml/testcases/renamed/existing.yml diff --git a/Tests/fixtures/testcases/renamed/expected.yml b/Tests/fixtures/yaml/testcases/renamed/expected.yml similarity index 100% rename from Tests/fixtures/testcases/renamed/expected.yml rename to Tests/fixtures/yaml/testcases/renamed/expected.yml diff --git a/Tests/fixtures/testcases/renamed/setup.yml b/Tests/fixtures/yaml/testcases/renamed/setup.yml similarity index 100% rename from Tests/fixtures/testcases/renamed/setup.yml rename to Tests/fixtures/yaml/testcases/renamed/setup.yml diff --git a/Tests/fixtures/testcases/renamed_and_environment/dist.yml b/Tests/fixtures/yaml/testcases/renamed_and_environment/dist.yml similarity index 100% rename from Tests/fixtures/testcases/renamed_and_environment/dist.yml rename to Tests/fixtures/yaml/testcases/renamed_and_environment/dist.yml diff --git a/Tests/fixtures/testcases/renamed_and_environment/existing.yml b/Tests/fixtures/yaml/testcases/renamed_and_environment/existing.yml similarity index 100% rename from Tests/fixtures/testcases/renamed_and_environment/existing.yml rename to Tests/fixtures/yaml/testcases/renamed_and_environment/existing.yml diff --git a/Tests/fixtures/testcases/renamed_and_environment/expected.yml b/Tests/fixtures/yaml/testcases/renamed_and_environment/expected.yml similarity index 100% rename from Tests/fixtures/testcases/renamed_and_environment/expected.yml rename to Tests/fixtures/yaml/testcases/renamed_and_environment/expected.yml diff --git a/Tests/fixtures/testcases/renamed_and_environment/setup.yml b/Tests/fixtures/yaml/testcases/renamed_and_environment/setup.yml similarity index 100% rename from Tests/fixtures/testcases/renamed_and_environment/setup.yml rename to Tests/fixtures/yaml/testcases/renamed_and_environment/setup.yml diff --git a/Tests/fixtures/testcases/subfolder/dist.yml b/Tests/fixtures/yaml/testcases/subfolder/dist.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder/dist.yml rename to Tests/fixtures/yaml/testcases/subfolder/dist.yml diff --git a/Tests/fixtures/testcases/subfolder/existing.yml b/Tests/fixtures/yaml/testcases/subfolder/existing.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder/existing.yml rename to Tests/fixtures/yaml/testcases/subfolder/existing.yml diff --git a/Tests/fixtures/testcases/subfolder/expected.yml b/Tests/fixtures/yaml/testcases/subfolder/expected.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder/expected.yml rename to Tests/fixtures/yaml/testcases/subfolder/expected.yml diff --git a/Tests/fixtures/testcases/subfolder/setup.yml b/Tests/fixtures/yaml/testcases/subfolder/setup.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder/setup.yml rename to Tests/fixtures/yaml/testcases/subfolder/setup.yml diff --git a/Tests/fixtures/testcases/subfolder_created/dist.yml b/Tests/fixtures/yaml/testcases/subfolder_created/dist.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder_created/dist.yml rename to Tests/fixtures/yaml/testcases/subfolder_created/dist.yml diff --git a/Tests/fixtures/testcases/subfolder_created/expected.yml b/Tests/fixtures/yaml/testcases/subfolder_created/expected.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder_created/expected.yml rename to Tests/fixtures/yaml/testcases/subfolder_created/expected.yml diff --git a/Tests/fixtures/testcases/subfolder_created/setup.yml b/Tests/fixtures/yaml/testcases/subfolder_created/setup.yml similarity index 100% rename from Tests/fixtures/testcases/subfolder_created/setup.yml rename to Tests/fixtures/yaml/testcases/subfolder_created/setup.yml From 78b494386b7cef2b7c13ba8b05eebb89110b65f7 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sat, 10 Sep 2016 12:46:54 +0200 Subject: [PATCH 04/32] Added tests for custom key JSON. --- Tests/fixtures/json/testcases/custom_key/dist.json | 11 +++++++++++ .../fixtures/json/testcases/custom_key/existing.json | 11 +++++++++++ .../fixtures/json/testcases/custom_key/expected.json | 11 +++++++++++ Tests/fixtures/json/testcases/custom_key/setup.yml | 5 +++++ 4 files changed, 38 insertions(+) create mode 100644 Tests/fixtures/json/testcases/custom_key/dist.json create mode 100644 Tests/fixtures/json/testcases/custom_key/existing.json create mode 100644 Tests/fixtures/json/testcases/custom_key/expected.json create mode 100644 Tests/fixtures/json/testcases/custom_key/setup.yml diff --git a/Tests/fixtures/json/testcases/custom_key/dist.json b/Tests/fixtures/json/testcases/custom_key/dist.json new file mode 100644 index 0000000..915d656 --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_key/dist.json @@ -0,0 +1,11 @@ +{ + "config": { + "foo": "bar", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_key/existing.json b/Tests/fixtures/json/testcases/custom_key/existing.json new file mode 100644 index 0000000..181046d --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_key/existing.json @@ -0,0 +1,11 @@ +{ + "config": { + "foo": "existing_foo", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_key/expected.json b/Tests/fixtures/json/testcases/custom_key/expected.json new file mode 100644 index 0000000..181046d --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_key/expected.json @@ -0,0 +1,11 @@ +{ + "config": { + "foo": "existing_foo", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/custom_key/setup.yml b/Tests/fixtures/json/testcases/custom_key/setup.yml new file mode 100644 index 0000000..6611ac7 --- /dev/null +++ b/Tests/fixtures/json/testcases/custom_key/setup.yml @@ -0,0 +1,5 @@ +title: Using a custom parameter key + +config: + parameter-key: config + From 18f59588e288c28eb5435ca6ace4de307775f38b Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 08:56:32 +0200 Subject: [PATCH 05/32] Added testcase existent. --- Tests/fixtures/json/testcases/existent/dist.json | 11 +++++++++++ Tests/fixtures/json/testcases/existent/existing.json | 11 +++++++++++ Tests/fixtures/json/testcases/existent/expected.json | 11 +++++++++++ Tests/fixtures/json/testcases/existent/setup.yml | 1 + 4 files changed, 34 insertions(+) create mode 100644 Tests/fixtures/json/testcases/existent/dist.json create mode 100644 Tests/fixtures/json/testcases/existent/existing.json create mode 100644 Tests/fixtures/json/testcases/existent/expected.json create mode 100644 Tests/fixtures/json/testcases/existent/setup.yml diff --git a/Tests/fixtures/json/testcases/existent/dist.json b/Tests/fixtures/json/testcases/existent/dist.json new file mode 100644 index 0000000..58aafc3 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent/dist.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent/existing.json b/Tests/fixtures/json/testcases/existent/existing.json new file mode 100644 index 0000000..559e966 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent/existing.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent/expected.json b/Tests/fixtures/json/testcases/existent/expected.json new file mode 100644 index 0000000..559e966 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent/expected.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent/setup.yml b/Tests/fixtures/json/testcases/existent/setup.yml new file mode 100644 index 0000000..b72f1b5 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent/setup.yml @@ -0,0 +1 @@ +title: Existing values are kept From b0c8db191e78cab0306a91f8478f8c6a7bd3eae8 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 09:35:44 +0200 Subject: [PATCH 06/32] Added testcase existent_empty and existent_without_key. --- Parser/JsonParser.php | 11 +++++++++-- .../json/invalid/invalid_existing_values.json | 1 + .../fixtures/json/testcases/existent_empty/dist.json | 5 +++++ .../json/testcases/existent_empty/existing.json | 0 .../json/testcases/existent_empty/expected.json | 5 +++++ .../fixtures/json/testcases/existent_empty/setup.yml | 1 + .../json/testcases/existent_without_key/dist.json | 5 +++++ .../json/testcases/existent_without_key/existing.json | 3 +++ .../json/testcases/existent_without_key/expected.json | 6 ++++++ .../json/testcases/existent_without_key/setup.yml | 1 + 10 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 Tests/fixtures/json/testcases/existent_empty/dist.json create mode 100644 Tests/fixtures/json/testcases/existent_empty/existing.json create mode 100644 Tests/fixtures/json/testcases/existent_empty/expected.json create mode 100644 Tests/fixtures/json/testcases/existent_empty/setup.yml create mode 100644 Tests/fixtures/json/testcases/existent_without_key/dist.json create mode 100644 Tests/fixtures/json/testcases/existent_without_key/existing.json create mode 100644 Tests/fixtures/json/testcases/existent_without_key/expected.json create mode 100644 Tests/fixtures/json/testcases/existent_without_key/setup.yml diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index af15d34..ec20cdf 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -18,9 +18,16 @@ class JsonParser implements ParserInterface */ public function parse($value, $flags = 0, $assoc = true, $depth = 512) { - $result = json_decode($value, $assoc, $depth, $flags); + if ('' === $value) { + $result = []; + } else { + $result = json_decode($value, $assoc, $depth, $flags); + if (null === $result) { + $result = false; + } + } - return (null === $result) ? false : $result; + return $result; } /** diff --git a/Tests/fixtures/json/invalid/invalid_existing_values.json b/Tests/fixtures/json/invalid/invalid_existing_values.json index e69de29..250c317 100644 --- a/Tests/fixtures/json/invalid/invalid_existing_values.json +++ b/Tests/fixtures/json/invalid/invalid_existing_values.json @@ -0,0 +1 @@ +not valid json \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_empty/dist.json b/Tests/fixtures/json/testcases/existent_empty/dist.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_empty/dist.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_empty/existing.json b/Tests/fixtures/json/testcases/existent_empty/existing.json new file mode 100644 index 0000000..e69de29 diff --git a/Tests/fixtures/json/testcases/existent_empty/expected.json b/Tests/fixtures/json/testcases/existent_empty/expected.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_empty/expected.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_empty/setup.yml b/Tests/fixtures/json/testcases/existent_empty/setup.yml new file mode 100644 index 0000000..dedcd0f --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_empty/setup.yml @@ -0,0 +1 @@ +title: Existing empty files are valid (Capifony compatibility) diff --git a/Tests/fixtures/json/testcases/existent_without_key/dist.json b/Tests/fixtures/json/testcases/existent_without_key/dist.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_without_key/dist.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_without_key/existing.json b/Tests/fixtures/json/testcases/existent_without_key/existing.json new file mode 100644 index 0000000..3e440fa --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_without_key/existing.json @@ -0,0 +1,3 @@ +{ + "foobar": "baz" +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_without_key/expected.json b/Tests/fixtures/json/testcases/existent_without_key/expected.json new file mode 100644 index 0000000..fa841cb --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_without_key/expected.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "bar" + }, + "foobar": "baz" +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/existent_without_key/setup.yml b/Tests/fixtures/json/testcases/existent_without_key/setup.yml new file mode 100644 index 0000000..3797a0b --- /dev/null +++ b/Tests/fixtures/json/testcases/existent_without_key/setup.yml @@ -0,0 +1 @@ +title: Existing files without the parameters key are valid From d4948d42084d82d48619373f832ff2e50fb7a2c3 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 09:42:17 +0200 Subject: [PATCH 07/32] Added testcase extra_keys. --- Tests/fixtures/json/testcases/extra_keys/dist.json | 7 +++++++ Tests/fixtures/json/testcases/extra_keys/existing.json | 6 ++++++ Tests/fixtures/json/testcases/extra_keys/expected.json | 8 ++++++++ Tests/fixtures/json/testcases/extra_keys/setup.yml | 1 + 4 files changed, 22 insertions(+) create mode 100644 Tests/fixtures/json/testcases/extra_keys/dist.json create mode 100644 Tests/fixtures/json/testcases/extra_keys/existing.json create mode 100644 Tests/fixtures/json/testcases/extra_keys/expected.json create mode 100644 Tests/fixtures/json/testcases/extra_keys/setup.yml diff --git a/Tests/fixtures/json/testcases/extra_keys/dist.json b/Tests/fixtures/json/testcases/extra_keys/dist.json new file mode 100644 index 0000000..ef2b43c --- /dev/null +++ b/Tests/fixtures/json/testcases/extra_keys/dist.json @@ -0,0 +1,7 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false + }, + "extra_key": "a new extra key" +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/extra_keys/existing.json b/Tests/fixtures/json/testcases/extra_keys/existing.json new file mode 100644 index 0000000..3ed7c73 --- /dev/null +++ b/Tests/fixtures/json/testcases/extra_keys/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo" + }, + "another_key": "foo" +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/extra_keys/expected.json b/Tests/fixtures/json/testcases/extra_keys/expected.json new file mode 100644 index 0000000..597641e --- /dev/null +++ b/Tests/fixtures/json/testcases/extra_keys/expected.json @@ -0,0 +1,8 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false + }, + "extra_key": "a new extra key", + "another_key": "foo" +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/extra_keys/setup.yml b/Tests/fixtures/json/testcases/extra_keys/setup.yml new file mode 100644 index 0000000..50666fd --- /dev/null +++ b/Tests/fixtures/json/testcases/extra_keys/setup.yml @@ -0,0 +1 @@ +title: Extra top level keys are preserved From ccf75ad7d8a211ca85f6373b09bb2c724396bea0 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 18:47:44 +0200 Subject: [PATCH 08/32] Added testcase interaction_existent. --- .../json/testcases/interaction_existent/dist.json | 7 +++++++ .../json/testcases/interaction_existent/existing.json | 5 +++++ .../json/testcases/interaction_existent/expected.json | 7 +++++++ .../json/testcases/interaction_existent/setup.yml | 11 +++++++++++ 4 files changed, 30 insertions(+) create mode 100644 Tests/fixtures/json/testcases/interaction_existent/dist.json create mode 100644 Tests/fixtures/json/testcases/interaction_existent/existing.json create mode 100644 Tests/fixtures/json/testcases/interaction_existent/expected.json create mode 100644 Tests/fixtures/json/testcases/interaction_existent/setup.yml diff --git a/Tests/fixtures/json/testcases/interaction_existent/dist.json b/Tests/fixtures/json/testcases/interaction_existent/dist.json new file mode 100644 index 0000000..3e051a0 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_existent/dist.json @@ -0,0 +1,7 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": null + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_existent/existing.json b/Tests/fixtures/json/testcases/interaction_existent/existing.json new file mode 100644 index 0000000..98ee282 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_existent/existing.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "existing_foo" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_existent/expected.json b/Tests/fixtures/json/testcases/interaction_existent/expected.json new file mode 100644 index 0000000..e96f5df --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_existent/expected.json @@ -0,0 +1,7 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": "null" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_existent/setup.yml b/Tests/fixtures/json/testcases/interaction_existent/setup.yml new file mode 100644 index 0000000..79664cb --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_existent/setup.yml @@ -0,0 +1,11 @@ +title: Existing values are not asked interactively again + +interactive: true + +requested_params: + boolean: + default: 'false' + input: 'false' + another: + default: 'null' + input: '"null"' From 38e2de9e8a007adcbfcea17601aa3a059044be27 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 18:55:16 +0200 Subject: [PATCH 09/32] Fixed expectation. --- .../fixtures/json/testcases/interaction_existent/expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/fixtures/json/testcases/interaction_existent/expected.json b/Tests/fixtures/json/testcases/interaction_existent/expected.json index e96f5df..b108940 100644 --- a/Tests/fixtures/json/testcases/interaction_existent/expected.json +++ b/Tests/fixtures/json/testcases/interaction_existent/expected.json @@ -1,6 +1,6 @@ { "parameters": { - "foo": "bar", + "foo": "existing_foo", "boolean": false, "another": "null" } From f2de56941e42c32681b3952b878e3cdab40f8ac4 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 19:03:06 +0200 Subject: [PATCH 10/32] Added testcase interaction_non_existent. --- .../testcases/interaction_non_existent/dist.json | 7 +++++++ .../interaction_non_existent/expected.json | 14 ++++++++++++++ .../testcases/interaction_non_existent/setup.yml | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 Tests/fixtures/json/testcases/interaction_non_existent/dist.json create mode 100644 Tests/fixtures/json/testcases/interaction_non_existent/expected.json create mode 100644 Tests/fixtures/json/testcases/interaction_non_existent/setup.yml diff --git a/Tests/fixtures/json/testcases/interaction_non_existent/dist.json b/Tests/fixtures/json/testcases/interaction_non_existent/dist.json new file mode 100644 index 0000000..9419076 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_non_existent/dist.json @@ -0,0 +1,7 @@ +{ + "parameters": { + "boolean": false, + "another": "test", + "nested": "nested" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_non_existent/expected.json b/Tests/fixtures/json/testcases/interaction_non_existent/expected.json new file mode 100644 index 0000000..5689ca2 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_non_existent/expected.json @@ -0,0 +1,14 @@ +{ + "parameters": { + "boolean": true, + "another": null, + "nested": { + "foo": "bar", + "bar": [ + "foo", + "test", + null + ] + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_non_existent/setup.yml b/Tests/fixtures/json/testcases/interaction_non_existent/setup.yml new file mode 100644 index 0000000..40effce --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_non_existent/setup.yml @@ -0,0 +1,14 @@ +title: Missing keys are asked interactively + +interactive: true + +requested_params: + boolean: + default: 'false' + input: 'true' + nested: + default: nested + input: '{foo: bar, bar: [foo, test, null]}' + another: + default: test + input: 'null' From 6bc84389737f43dfa84b4d9a51f6e0fc9938a1bc Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Sun, 11 Sep 2016 19:11:25 +0200 Subject: [PATCH 11/32] Added testcase interaction_with_environment. --- .../interaction_with_environment/dist.json | 7 +++++++ .../interaction_with_environment/expected.json | 14 ++++++++++++++ .../interaction_with_environment/setup.yml | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 Tests/fixtures/json/testcases/interaction_with_environment/dist.json create mode 100644 Tests/fixtures/json/testcases/interaction_with_environment/expected.json create mode 100644 Tests/fixtures/json/testcases/interaction_with_environment/setup.yml diff --git a/Tests/fixtures/json/testcases/interaction_with_environment/dist.json b/Tests/fixtures/json/testcases/interaction_with_environment/dist.json new file mode 100644 index 0000000..9419076 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_with_environment/dist.json @@ -0,0 +1,7 @@ +{ + "parameters": { + "boolean": false, + "another": "test", + "nested": "nested" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_with_environment/expected.json b/Tests/fixtures/json/testcases/interaction_with_environment/expected.json new file mode 100644 index 0000000..20d2422 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_with_environment/expected.json @@ -0,0 +1,14 @@ +{ + "parameters": { + "boolean": true, + "nested": { + "foo": "env_foo", + "bar": [ + "env", + "test", + null + ] + }, + "another": null + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/interaction_with_environment/setup.yml b/Tests/fixtures/json/testcases/interaction_with_environment/setup.yml new file mode 100644 index 0000000..80e2585 --- /dev/null +++ b/Tests/fixtures/json/testcases/interaction_with_environment/setup.yml @@ -0,0 +1,17 @@ +title: Values provided by the environment are not asked interactively + +config: + env-map: + boolean: IC_TEST_BOOL + nested: IC_TEST_NESTED + +environment: + IC_TEST_BOOL: 'true' + IC_TEST_NESTED: '{foo: env_foo, bar: [env, test, null]}' + +interactive: true + +requested_params: + another: + default: test + input: 'null' From b8cfbb2ef9b60e39e7a108766c0ec64a9a666192 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 06:53:47 +0200 Subject: [PATCH 12/32] Added testcase keep_outdated. --- Tests/fixtures/json/testcases/keep_outdated/dist.json | 5 +++++ Tests/fixtures/json/testcases/keep_outdated/existing.json | 6 ++++++ Tests/fixtures/json/testcases/keep_outdated/expected.json | 6 ++++++ Tests/fixtures/json/testcases/keep_outdated/setup.yml | 4 ++++ 4 files changed, 21 insertions(+) create mode 100644 Tests/fixtures/json/testcases/keep_outdated/dist.json create mode 100644 Tests/fixtures/json/testcases/keep_outdated/existing.json create mode 100644 Tests/fixtures/json/testcases/keep_outdated/expected.json create mode 100644 Tests/fixtures/json/testcases/keep_outdated/setup.yml diff --git a/Tests/fixtures/json/testcases/keep_outdated/dist.json b/Tests/fixtures/json/testcases/keep_outdated/dist.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/keep_outdated/dist.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/keep_outdated/existing.json b/Tests/fixtures/json/testcases/keep_outdated/existing.json new file mode 100644 index 0000000..2af597d --- /dev/null +++ b/Tests/fixtures/json/testcases/keep_outdated/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "outdated": "outdated_param" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/keep_outdated/expected.json b/Tests/fixtures/json/testcases/keep_outdated/expected.json new file mode 100644 index 0000000..2af597d --- /dev/null +++ b/Tests/fixtures/json/testcases/keep_outdated/expected.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "outdated": "outdated_param" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/keep_outdated/setup.yml b/Tests/fixtures/json/testcases/keep_outdated/setup.yml new file mode 100644 index 0000000..d3f2eec --- /dev/null +++ b/Tests/fixtures/json/testcases/keep_outdated/setup.yml @@ -0,0 +1,4 @@ +title: Outdated keys can be kept in the parameters file + +config: + keep-outdated: true From a1bd237e44effed3de990731ffe226d560583cf7 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 06:57:18 +0200 Subject: [PATCH 13/32] Added testcase non_existent. --- Tests/fixtures/json/testcases/non_existent/dist.json | 11 +++++++++++ .../json/testcases/non_existent/expected.json | 11 +++++++++++ Tests/fixtures/json/testcases/non_existent/setup.yml | 1 + 3 files changed, 23 insertions(+) create mode 100644 Tests/fixtures/json/testcases/non_existent/dist.json create mode 100644 Tests/fixtures/json/testcases/non_existent/expected.json create mode 100644 Tests/fixtures/json/testcases/non_existent/setup.yml diff --git a/Tests/fixtures/json/testcases/non_existent/dist.json b/Tests/fixtures/json/testcases/non_existent/dist.json new file mode 100644 index 0000000..58aafc3 --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent/dist.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/non_existent/expected.json b/Tests/fixtures/json/testcases/non_existent/expected.json new file mode 100644 index 0000000..58aafc3 --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent/expected.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/non_existent/setup.yml b/Tests/fixtures/json/testcases/non_existent/setup.yml new file mode 100644 index 0000000..9c33d2d --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent/setup.yml @@ -0,0 +1 @@ +title: Non existent files are created From 18a6f37c57bcba2c1c61e028aa8763aaca944a93 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:07:53 +0200 Subject: [PATCH 14/32] Added testcase non_existent_with_environment. --- .../non_existent_with_environment/dist.json | 11 +++++++++++ .../non_existent_with_environment/expected.json | 15 +++++++++++++++ .../non_existent_with_environment/setup.yml | 13 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Tests/fixtures/json/testcases/non_existent_with_environment/dist.json create mode 100644 Tests/fixtures/json/testcases/non_existent_with_environment/expected.json create mode 100644 Tests/fixtures/json/testcases/non_existent_with_environment/setup.yml diff --git a/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json b/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json new file mode 100644 index 0000000..58aafc3 --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json @@ -0,0 +1,11 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false, + "another": null, + "nested": { + "foo": "bar", + "bar": "baz" + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json b/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json new file mode 100644 index 0000000..b9b0189 --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json @@ -0,0 +1,15 @@ +{ + "parameters": { + "foo": "foobar", + "boolean": true, + "another": null, + "nested": { + "foo": "env_foo", + "bar": [ + "env", + "test", + null + ] + } + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/non_existent_with_environment/setup.yml b/Tests/fixtures/json/testcases/non_existent_with_environment/setup.yml new file mode 100644 index 0000000..684e4de --- /dev/null +++ b/Tests/fixtures/json/testcases/non_existent_with_environment/setup.yml @@ -0,0 +1,13 @@ +title: Environment variables are used over dist file defaults + +config: + env-map: + boolean: IC_TEST_BOOL + foo: IC_TEST_FOO + nested: IC_TEST_NESTED + another: IC_TEST_NOT_SET + +environment: + IC_TEST_BOOL: 'true' + IC_TEST_FOO: 'foobar' + IC_TEST_NESTED: '{foo: env_foo, bar: [env, test, null]}' From 8d709a07ed621a915e6d64650d360a717b87304c Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:10:33 +0200 Subject: [PATCH 15/32] Added testcase remove_outdated. --- Tests/fixtures/json/testcases/remove_outdated/dist.json | 5 +++++ Tests/fixtures/json/testcases/remove_outdated/existing.json | 6 ++++++ Tests/fixtures/json/testcases/remove_outdated/expected.json | 5 +++++ Tests/fixtures/json/testcases/remove_outdated/setup.yml | 1 + 4 files changed, 17 insertions(+) create mode 100644 Tests/fixtures/json/testcases/remove_outdated/dist.json create mode 100644 Tests/fixtures/json/testcases/remove_outdated/existing.json create mode 100644 Tests/fixtures/json/testcases/remove_outdated/expected.json create mode 100644 Tests/fixtures/json/testcases/remove_outdated/setup.yml diff --git a/Tests/fixtures/json/testcases/remove_outdated/dist.json b/Tests/fixtures/json/testcases/remove_outdated/dist.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/remove_outdated/dist.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/remove_outdated/existing.json b/Tests/fixtures/json/testcases/remove_outdated/existing.json new file mode 100644 index 0000000..2af597d --- /dev/null +++ b/Tests/fixtures/json/testcases/remove_outdated/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "outdated": "outdated_param" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/remove_outdated/expected.json b/Tests/fixtures/json/testcases/remove_outdated/expected.json new file mode 100644 index 0000000..98ee282 --- /dev/null +++ b/Tests/fixtures/json/testcases/remove_outdated/expected.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "existing_foo" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/remove_outdated/setup.yml b/Tests/fixtures/json/testcases/remove_outdated/setup.yml new file mode 100644 index 0000000..183e5cd --- /dev/null +++ b/Tests/fixtures/json/testcases/remove_outdated/setup.yml @@ -0,0 +1 @@ +title: Outdated keys are removed from the parameters file From 40d417771e7d6e9e1e1d5a8dac454c7ee567c4d8 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:14:57 +0200 Subject: [PATCH 16/32] Added testcase renamed. --- Tests/fixtures/json/testcases/renamed/dist.json | 9 +++++++++ Tests/fixtures/json/testcases/renamed/existing.json | 8 ++++++++ Tests/fixtures/json/testcases/renamed/expected.json | 9 +++++++++ Tests/fixtures/json/testcases/renamed/setup.yml | 9 +++++++++ 4 files changed, 35 insertions(+) create mode 100644 Tests/fixtures/json/testcases/renamed/dist.json create mode 100644 Tests/fixtures/json/testcases/renamed/existing.json create mode 100644 Tests/fixtures/json/testcases/renamed/expected.json create mode 100644 Tests/fixtures/json/testcases/renamed/setup.yml diff --git a/Tests/fixtures/json/testcases/renamed/dist.json b/Tests/fixtures/json/testcases/renamed/dist.json new file mode 100644 index 0000000..7e11e1b --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed/dist.json @@ -0,0 +1,9 @@ +{ + "parameters": { + "new": "bar", + "new2": "new2", + "new3": "test", + "new4": "test4", + "new5": "test5" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed/existing.json b/Tests/fixtures/json/testcases/renamed/existing.json new file mode 100644 index 0000000..7cf2f11 --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed/existing.json @@ -0,0 +1,8 @@ +{ + "parameters": { + "old": "old_value", + "new2": "foo", + "old2": "bar", + "old4": "old4" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed/expected.json b/Tests/fixtures/json/testcases/renamed/expected.json new file mode 100644 index 0000000..d96420f --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed/expected.json @@ -0,0 +1,9 @@ +{ + "parameters": { + "new": "old_value", + "new2": "foo", + "new3": "test", + "new4": "old4", + "new5": "old4" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed/setup.yml b/Tests/fixtures/json/testcases/renamed/setup.yml new file mode 100644 index 0000000..153ed8c --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed/setup.yml @@ -0,0 +1,9 @@ +title: Key can be renamed and the value is reused + +config: + rename-map: + new: old + new2: old2 + new3: old3 + new4: old4 + new5: new4 # Cascade renaming From 0bbf577100b3253d24fd042e75cace83c82a35ca Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:26:27 +0200 Subject: [PATCH 17/32] Added testcase renamed_and_environment. --- .../json/testcases/renamed_and_environment/dist.json | 6 ++++++ .../testcases/renamed_and_environment/existing.json | 6 ++++++ .../testcases/renamed_and_environment/expected.json | 6 ++++++ .../json/testcases/renamed_and_environment/setup.yml | 11 +++++++++++ 4 files changed, 29 insertions(+) create mode 100644 Tests/fixtures/json/testcases/renamed_and_environment/dist.json create mode 100644 Tests/fixtures/json/testcases/renamed_and_environment/existing.json create mode 100644 Tests/fixtures/json/testcases/renamed_and_environment/expected.json create mode 100644 Tests/fixtures/json/testcases/renamed_and_environment/setup.yml diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/dist.json b/Tests/fixtures/json/testcases/renamed_and_environment/dist.json new file mode 100644 index 0000000..db8a93a --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed_and_environment/dist.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "new": "bar", + "new2": "new2" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/existing.json b/Tests/fixtures/json/testcases/renamed_and_environment/existing.json new file mode 100644 index 0000000..07051d1 --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed_and_environment/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "old": "old_value", + "old2": "old_value2" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/expected.json b/Tests/fixtures/json/testcases/renamed_and_environment/expected.json new file mode 100644 index 0000000..db77349 --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed_and_environment/expected.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "new": "new_env_value", + "new2": "old_value2" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/setup.yml b/Tests/fixtures/json/testcases/renamed_and_environment/setup.yml new file mode 100644 index 0000000..7c3853f --- /dev/null +++ b/Tests/fixtures/json/testcases/renamed_and_environment/setup.yml @@ -0,0 +1,11 @@ +title: Environment variables win over renamed keys + +config: + rename-map: + new: old + new2: old2 + env-map: + new: IC_TEST_NEW + +environment: + IC_TEST_NEW: 'new_env_value' From 95617c85b42fc74ca2760e1e666e0a8e3523995f Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:28:43 +0200 Subject: [PATCH 18/32] Added testcase subfolder. --- Tests/fixtures/json/testcases/subfolder/dist.json | 6 ++++++ Tests/fixtures/json/testcases/subfolder/existing.json | 6 ++++++ Tests/fixtures/json/testcases/subfolder/expected.json | 6 ++++++ Tests/fixtures/json/testcases/subfolder/setup.yml | 6 ++++++ 4 files changed, 24 insertions(+) create mode 100644 Tests/fixtures/json/testcases/subfolder/dist.json create mode 100644 Tests/fixtures/json/testcases/subfolder/existing.json create mode 100644 Tests/fixtures/json/testcases/subfolder/expected.json create mode 100644 Tests/fixtures/json/testcases/subfolder/setup.yml diff --git a/Tests/fixtures/json/testcases/subfolder/dist.json b/Tests/fixtures/json/testcases/subfolder/dist.json new file mode 100644 index 0000000..e66031d --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder/dist.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "bar", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/subfolder/existing.json b/Tests/fixtures/json/testcases/subfolder/existing.json new file mode 100644 index 0000000..10608a6 --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder/existing.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/subfolder/expected.json b/Tests/fixtures/json/testcases/subfolder/expected.json new file mode 100644 index 0000000..10608a6 --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder/expected.json @@ -0,0 +1,6 @@ +{ + "parameters": { + "foo": "existing_foo", + "boolean": false + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/subfolder/setup.yml b/Tests/fixtures/json/testcases/subfolder/setup.yml new file mode 100644 index 0000000..21a4b00 --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder/setup.yml @@ -0,0 +1,6 @@ +title: Files can be located in subfolders + +config: + file: 'app/parameters.yml' + +dist-file: 'app/parameters.yml.dist' From 0b71c134610af313a9d0806723bda9b5098fbb76 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 07:30:38 +0200 Subject: [PATCH 19/32] Added testcase subfolder_created. --- Tests/fixtures/json/testcases/subfolder_created/dist.json | 5 +++++ .../json/testcases/subfolder_created/expected.json | 5 +++++ Tests/fixtures/json/testcases/subfolder_created/setup.yml | 7 +++++++ 3 files changed, 17 insertions(+) create mode 100644 Tests/fixtures/json/testcases/subfolder_created/dist.json create mode 100644 Tests/fixtures/json/testcases/subfolder_created/expected.json create mode 100644 Tests/fixtures/json/testcases/subfolder_created/setup.yml diff --git a/Tests/fixtures/json/testcases/subfolder_created/dist.json b/Tests/fixtures/json/testcases/subfolder_created/dist.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder_created/dist.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/subfolder_created/expected.json b/Tests/fixtures/json/testcases/subfolder_created/expected.json new file mode 100644 index 0000000..13eb389 --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder_created/expected.json @@ -0,0 +1,5 @@ +{ + "parameters": { + "foo": "bar" + } +} \ No newline at end of file diff --git a/Tests/fixtures/json/testcases/subfolder_created/setup.yml b/Tests/fixtures/json/testcases/subfolder_created/setup.yml new file mode 100644 index 0000000..c30049a --- /dev/null +++ b/Tests/fixtures/json/testcases/subfolder_created/setup.yml @@ -0,0 +1,7 @@ +title: Files can be located in different folders than the dist and the folder is created + +config: + file: 'app/parameters.yml' + dist-file: 'dist/parameters.yml' + +dist-file: 'dist/parameters.yml' From 776afbf9d87965c491ad5e8fa954497b8a4e2a19 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 08:15:53 +0200 Subject: [PATCH 20/32] TidyUp removed deprecated interface. --- Processor/JsonProcessor.php | 2 +- Processor/ProcessorInterface.php | 15 --------------- Processor/YamlProcessor.php | 2 +- 3 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 Processor/ProcessorInterface.php diff --git a/Processor/JsonProcessor.php b/Processor/JsonProcessor.php index e963541..e11b22c 100644 --- a/Processor/JsonProcessor.php +++ b/Processor/JsonProcessor.php @@ -2,7 +2,7 @@ namespace Incenteev\ParameterHandler\Processor; -class JsonProcessor extends AbstractProcessor implements ProcessorInterface +class JsonProcessor extends AbstractProcessor { /** * Persists an array to a file in JSON format. diff --git a/Processor/ProcessorInterface.php b/Processor/ProcessorInterface.php deleted file mode 100644 index f0efd57..0000000 --- a/Processor/ProcessorInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Mon, 12 Sep 2016 08:32:12 +0200 Subject: [PATCH 21/32] TidyUp comments & minor refactoring. --- Processor/AbstractProcessor.php | 30 ++++++++++++++++++++---------- ScriptHandler.php | 9 ++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Processor/AbstractProcessor.php b/Processor/AbstractProcessor.php index 6238302..be2c3e7 100644 --- a/Processor/AbstractProcessor.php +++ b/Processor/AbstractProcessor.php @@ -3,14 +3,14 @@ namespace Incenteev\ParameterHandler\Processor; use Composer\IO\IOInterface; -use Incenteev\ParameterHandler\Parser\JsonParser; -use Symfony\Component\Yaml\Parser as YamlParser; +use Incenteev\ParameterHandler\Parser\ParseException; +use Incenteev\ParameterHandler\Parser\ParserInterface; use Symfony\Component\Yaml\Inline; abstract class AbstractProcessor { /** - * IO Interface of composer used for displaying messages. + * IO Interface of composer used for displaying messages and requesting input from user. * * @var IOInterface */ @@ -19,26 +19,26 @@ abstract class AbstractProcessor /** * Parser. * - * @var IOInterface + * @var ParserInterface */ protected $parser; /** * Constructor. * - * @param IOInterface $io Composer IO Interface - * @param YamlParser|JsonParser $parser Instance of parser to parse configuration + * @param IOInterface $io Composer IO + * @param ParserInterface $parser Instance of parser for type YAML or JSON */ - public function __construct(IOInterface $io, $parser) + public function __construct(IOInterface $io, ParserInterface $parser) { $this->parser = $parser; $this->io = $io; } /** - * {@inheritdoc} + * Aloha * - * @throws \InvalidArgumentException|\RuntimeException + * @throws ParseException|\InvalidArgumentException|\RuntimeException */ public function processFile(array $config) { @@ -174,6 +174,16 @@ private function processRenamedValues(array $renameMap, array $actualParams) return $actualParams; } + /** + * Returns the current set of parameters. + * If IO mode non interactive it simply sets the expected values, otherwise it asks user for defining missing + * parameters. + * + * @param array $expectedParams Parameters required + * @param array $actualParams Parameters defined already + * + * @return array Updated set of parameters + */ private function getParams(array $expectedParams, array $actualParams) { // Simply use the expectedParams value as default for the missing params. @@ -207,7 +217,7 @@ private function getParams(array $expectedParams, array $actualParams) * Persists configuration. * * @param string $file Filename to persist configuration to. - * @param array $configuration Configuration to persist as an array. + * @param array $configuration Configuration to persist. * * @return bool TRUE after successful persisting the file, otherwise FALSE */ diff --git a/ScriptHandler.php b/ScriptHandler.php index 426bff8..91fdd2c 100644 --- a/ScriptHandler.php +++ b/ScriptHandler.php @@ -96,17 +96,12 @@ public static function buildParameters(Event $event) } /** - * Returns type of configuration by file extension. - * - * @example Files with extension ".yml" will be resolved to type YAML, extension ".json" will be resolved to type JSON + * Returns type of configuration by files extension. + * Files with extension ".yml" will be resolved to type YAML, extension ".json" will be resolved to type JSON * * @param string $file File to parse extension from * - * @author Benjamin Carl - * * @return string Type of configuration, either self::FILE_TYPE_YAML or self::FILE_TYPE_JSON - * - * @throws \OutOfBoundsException */ private static function retrieveConfigurationTypeByFile($file) { From 3dd8dce8e85a3744e5b8a37f699cd41c1bdf3922 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 21:44:20 +0200 Subject: [PATCH 22/32] Removed some comments // Added new line parameter for pretty print JSON. --- Parser/JsonParser.php | 22 +++++++++++++--------- ScriptHandler.php | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index ec20cdf..e0886e5 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -35,8 +35,6 @@ public function parse($value, $flags = 0, $assoc = true, $depth = 512) * * @param array $data Data to dump. * - * @author Benjamin Carl - * * @return string Dumped JSON data */ public function dump(array $data) @@ -45,17 +43,17 @@ public function dump(array $data) } /** - * Pretty print JSON custom implementation for compatibility with PHP < 5.4 and custom spacing. - * - * @param string $json JSON data to be pretty printed - * @param string $spacer Spacer used e.g. ' ' or "\t" - * @param int $spacing Multiplicator for spacer (count) + * Returns pretty printed JSON string. + * Custom implementation for compatibility with PHP < 5.4 and custom spacing. * - * @author Benjamin Carl + * @param string $json JSON data to be pretty printed + * @param string $spacer Spacer used e.g. ' ' or "\t" + * @param int $spacing Multiplicand for spacer (count) + * @param bool $newLineAtEof Whether to write a nl at end of file or not * * @return string Pretty printed JSON data */ - protected function prettyPrint($json, $spacer = ' ', $spacing = 2) + protected function prettyPrint($json, $spacer = ' ', $spacing = 2, $newLineAtEof = true) { $result = ''; $level = 0; @@ -114,6 +112,12 @@ protected function prettyPrint($json, $spacer = ' ', $spacing = 2) $result .= $char.$post; } + $result = trim($result); + + if (true === $newLineAtEof) { + $result .= PHP_EOL; + } + return $result; } } diff --git a/ScriptHandler.php b/ScriptHandler.php index 91fdd2c..7674276 100644 --- a/ScriptHandler.php +++ b/ScriptHandler.php @@ -101,7 +101,7 @@ public static function buildParameters(Event $event) * * @param string $file File to parse extension from * - * @return string Type of configuration, either self::FILE_TYPE_YAML or self::FILE_TYPE_JSON + * @return string Type of configuration, either self::CONFIGURATION_FORMAT_YAML or self::CONFIGURATION_FORMAT_JSON */ private static function retrieveConfigurationTypeByFile($file) { From 0d6c07f61c001a600d48648d0421db959a751181 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 21:51:01 +0200 Subject: [PATCH 23/32] Added nl to JSON files as expectation. --- Parser/JsonParser.php | 2 +- Tests/fixtures/json/testcases/custom_dist_file/dist.json | 2 +- Tests/fixtures/json/testcases/custom_dist_file/existing.json | 2 +- Tests/fixtures/json/testcases/custom_dist_file/expected.json | 2 +- Tests/fixtures/json/testcases/custom_key/dist.json | 2 +- Tests/fixtures/json/testcases/custom_key/existing.json | 2 +- Tests/fixtures/json/testcases/custom_key/expected.json | 2 +- Tests/fixtures/json/testcases/existent/dist.json | 2 +- Tests/fixtures/json/testcases/existent/existing.json | 2 +- Tests/fixtures/json/testcases/existent/expected.json | 2 +- Tests/fixtures/json/testcases/existent_empty/dist.json | 2 +- Tests/fixtures/json/testcases/existent_empty/expected.json | 2 +- Tests/fixtures/json/testcases/existent_without_key/dist.json | 2 +- .../fixtures/json/testcases/existent_without_key/existing.json | 2 +- .../fixtures/json/testcases/existent_without_key/expected.json | 2 +- Tests/fixtures/json/testcases/extra_keys/dist.json | 2 +- Tests/fixtures/json/testcases/extra_keys/existing.json | 2 +- Tests/fixtures/json/testcases/extra_keys/expected.json | 2 +- Tests/fixtures/json/testcases/interaction_existent/dist.json | 2 +- .../fixtures/json/testcases/interaction_existent/existing.json | 2 +- .../fixtures/json/testcases/interaction_existent/expected.json | 2 +- .../fixtures/json/testcases/interaction_non_existent/dist.json | 2 +- .../json/testcases/interaction_non_existent/expected.json | 2 +- .../json/testcases/interaction_with_environment/dist.json | 2 +- .../json/testcases/interaction_with_environment/expected.json | 2 +- Tests/fixtures/json/testcases/keep_outdated/dist.json | 2 +- Tests/fixtures/json/testcases/keep_outdated/existing.json | 2 +- Tests/fixtures/json/testcases/keep_outdated/expected.json | 2 +- Tests/fixtures/json/testcases/non_existent/dist.json | 2 +- Tests/fixtures/json/testcases/non_existent/expected.json | 2 +- .../json/testcases/non_existent_with_environment/dist.json | 2 +- .../json/testcases/non_existent_with_environment/expected.json | 2 +- Tests/fixtures/json/testcases/remove_outdated/dist.json | 2 +- Tests/fixtures/json/testcases/remove_outdated/existing.json | 2 +- Tests/fixtures/json/testcases/remove_outdated/expected.json | 2 +- Tests/fixtures/json/testcases/renamed/dist.json | 2 +- Tests/fixtures/json/testcases/renamed/existing.json | 2 +- Tests/fixtures/json/testcases/renamed/expected.json | 2 +- Tests/fixtures/json/testcases/renamed_and_environment/dist.json | 2 +- .../json/testcases/renamed_and_environment/existing.json | 2 +- .../json/testcases/renamed_and_environment/expected.json | 2 +- Tests/fixtures/json/testcases/subfolder/dist.json | 2 +- Tests/fixtures/json/testcases/subfolder/existing.json | 2 +- Tests/fixtures/json/testcases/subfolder/expected.json | 2 +- Tests/fixtures/json/testcases/subfolder_created/dist.json | 2 +- Tests/fixtures/json/testcases/subfolder_created/expected.json | 2 +- 46 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index e0886e5..6b02555 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -115,7 +115,7 @@ protected function prettyPrint($json, $spacer = ' ', $spacing = 2, $newLineAtEof $result = trim($result); if (true === $newLineAtEof) { - $result .= PHP_EOL; + $result .= "\n"; } return $result; diff --git a/Tests/fixtures/json/testcases/custom_dist_file/dist.json b/Tests/fixtures/json/testcases/custom_dist_file/dist.json index e66031d..4d3059b 100644 --- a/Tests/fixtures/json/testcases/custom_dist_file/dist.json +++ b/Tests/fixtures/json/testcases/custom_dist_file/dist.json @@ -3,4 +3,4 @@ "foo": "bar", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/custom_dist_file/existing.json b/Tests/fixtures/json/testcases/custom_dist_file/existing.json index 10608a6..869e880 100644 --- a/Tests/fixtures/json/testcases/custom_dist_file/existing.json +++ b/Tests/fixtures/json/testcases/custom_dist_file/existing.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/custom_dist_file/expected.json b/Tests/fixtures/json/testcases/custom_dist_file/expected.json index 10608a6..869e880 100644 --- a/Tests/fixtures/json/testcases/custom_dist_file/expected.json +++ b/Tests/fixtures/json/testcases/custom_dist_file/expected.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/custom_key/dist.json b/Tests/fixtures/json/testcases/custom_key/dist.json index 915d656..6dd3e6c 100644 --- a/Tests/fixtures/json/testcases/custom_key/dist.json +++ b/Tests/fixtures/json/testcases/custom_key/dist.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/custom_key/existing.json b/Tests/fixtures/json/testcases/custom_key/existing.json index 181046d..52e0335 100644 --- a/Tests/fixtures/json/testcases/custom_key/existing.json +++ b/Tests/fixtures/json/testcases/custom_key/existing.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/custom_key/expected.json b/Tests/fixtures/json/testcases/custom_key/expected.json index 181046d..52e0335 100644 --- a/Tests/fixtures/json/testcases/custom_key/expected.json +++ b/Tests/fixtures/json/testcases/custom_key/expected.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent/dist.json b/Tests/fixtures/json/testcases/existent/dist.json index 58aafc3..beb78e9 100644 --- a/Tests/fixtures/json/testcases/existent/dist.json +++ b/Tests/fixtures/json/testcases/existent/dist.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent/existing.json b/Tests/fixtures/json/testcases/existent/existing.json index 559e966..b4d4064 100644 --- a/Tests/fixtures/json/testcases/existent/existing.json +++ b/Tests/fixtures/json/testcases/existent/existing.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent/expected.json b/Tests/fixtures/json/testcases/existent/expected.json index 559e966..b4d4064 100644 --- a/Tests/fixtures/json/testcases/existent/expected.json +++ b/Tests/fixtures/json/testcases/existent/expected.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent_empty/dist.json b/Tests/fixtures/json/testcases/existent_empty/dist.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/existent_empty/dist.json +++ b/Tests/fixtures/json/testcases/existent_empty/dist.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent_empty/expected.json b/Tests/fixtures/json/testcases/existent_empty/expected.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/existent_empty/expected.json +++ b/Tests/fixtures/json/testcases/existent_empty/expected.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent_without_key/dist.json b/Tests/fixtures/json/testcases/existent_without_key/dist.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/existent_without_key/dist.json +++ b/Tests/fixtures/json/testcases/existent_without_key/dist.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent_without_key/existing.json b/Tests/fixtures/json/testcases/existent_without_key/existing.json index 3e440fa..cbd009c 100644 --- a/Tests/fixtures/json/testcases/existent_without_key/existing.json +++ b/Tests/fixtures/json/testcases/existent_without_key/existing.json @@ -1,3 +1,3 @@ { "foobar": "baz" -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/existent_without_key/expected.json b/Tests/fixtures/json/testcases/existent_without_key/expected.json index fa841cb..daf3967 100644 --- a/Tests/fixtures/json/testcases/existent_without_key/expected.json +++ b/Tests/fixtures/json/testcases/existent_without_key/expected.json @@ -3,4 +3,4 @@ "foo": "bar" }, "foobar": "baz" -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/extra_keys/dist.json b/Tests/fixtures/json/testcases/extra_keys/dist.json index ef2b43c..11d2fd9 100644 --- a/Tests/fixtures/json/testcases/extra_keys/dist.json +++ b/Tests/fixtures/json/testcases/extra_keys/dist.json @@ -4,4 +4,4 @@ "boolean": false }, "extra_key": "a new extra key" -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/extra_keys/existing.json b/Tests/fixtures/json/testcases/extra_keys/existing.json index 3ed7c73..a5e6df1 100644 --- a/Tests/fixtures/json/testcases/extra_keys/existing.json +++ b/Tests/fixtures/json/testcases/extra_keys/existing.json @@ -3,4 +3,4 @@ "foo": "existing_foo" }, "another_key": "foo" -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/extra_keys/expected.json b/Tests/fixtures/json/testcases/extra_keys/expected.json index 597641e..d6ea26f 100644 --- a/Tests/fixtures/json/testcases/extra_keys/expected.json +++ b/Tests/fixtures/json/testcases/extra_keys/expected.json @@ -5,4 +5,4 @@ }, "extra_key": "a new extra key", "another_key": "foo" -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_existent/dist.json b/Tests/fixtures/json/testcases/interaction_existent/dist.json index 3e051a0..839fab3 100644 --- a/Tests/fixtures/json/testcases/interaction_existent/dist.json +++ b/Tests/fixtures/json/testcases/interaction_existent/dist.json @@ -4,4 +4,4 @@ "boolean": false, "another": null } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_existent/existing.json b/Tests/fixtures/json/testcases/interaction_existent/existing.json index 98ee282..57437bc 100644 --- a/Tests/fixtures/json/testcases/interaction_existent/existing.json +++ b/Tests/fixtures/json/testcases/interaction_existent/existing.json @@ -2,4 +2,4 @@ "parameters": { "foo": "existing_foo" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_existent/expected.json b/Tests/fixtures/json/testcases/interaction_existent/expected.json index b108940..fd746b9 100644 --- a/Tests/fixtures/json/testcases/interaction_existent/expected.json +++ b/Tests/fixtures/json/testcases/interaction_existent/expected.json @@ -4,4 +4,4 @@ "boolean": false, "another": "null" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_non_existent/dist.json b/Tests/fixtures/json/testcases/interaction_non_existent/dist.json index 9419076..3412193 100644 --- a/Tests/fixtures/json/testcases/interaction_non_existent/dist.json +++ b/Tests/fixtures/json/testcases/interaction_non_existent/dist.json @@ -4,4 +4,4 @@ "another": "test", "nested": "nested" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_non_existent/expected.json b/Tests/fixtures/json/testcases/interaction_non_existent/expected.json index 5689ca2..6c251bb 100644 --- a/Tests/fixtures/json/testcases/interaction_non_existent/expected.json +++ b/Tests/fixtures/json/testcases/interaction_non_existent/expected.json @@ -11,4 +11,4 @@ ] } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_with_environment/dist.json b/Tests/fixtures/json/testcases/interaction_with_environment/dist.json index 9419076..3412193 100644 --- a/Tests/fixtures/json/testcases/interaction_with_environment/dist.json +++ b/Tests/fixtures/json/testcases/interaction_with_environment/dist.json @@ -4,4 +4,4 @@ "another": "test", "nested": "nested" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/interaction_with_environment/expected.json b/Tests/fixtures/json/testcases/interaction_with_environment/expected.json index 20d2422..904b4ff 100644 --- a/Tests/fixtures/json/testcases/interaction_with_environment/expected.json +++ b/Tests/fixtures/json/testcases/interaction_with_environment/expected.json @@ -11,4 +11,4 @@ }, "another": null } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/keep_outdated/dist.json b/Tests/fixtures/json/testcases/keep_outdated/dist.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/keep_outdated/dist.json +++ b/Tests/fixtures/json/testcases/keep_outdated/dist.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/keep_outdated/existing.json b/Tests/fixtures/json/testcases/keep_outdated/existing.json index 2af597d..ee8f822 100644 --- a/Tests/fixtures/json/testcases/keep_outdated/existing.json +++ b/Tests/fixtures/json/testcases/keep_outdated/existing.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "outdated": "outdated_param" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/keep_outdated/expected.json b/Tests/fixtures/json/testcases/keep_outdated/expected.json index 2af597d..ee8f822 100644 --- a/Tests/fixtures/json/testcases/keep_outdated/expected.json +++ b/Tests/fixtures/json/testcases/keep_outdated/expected.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "outdated": "outdated_param" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/non_existent/dist.json b/Tests/fixtures/json/testcases/non_existent/dist.json index 58aafc3..beb78e9 100644 --- a/Tests/fixtures/json/testcases/non_existent/dist.json +++ b/Tests/fixtures/json/testcases/non_existent/dist.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/non_existent/expected.json b/Tests/fixtures/json/testcases/non_existent/expected.json index 58aafc3..beb78e9 100644 --- a/Tests/fixtures/json/testcases/non_existent/expected.json +++ b/Tests/fixtures/json/testcases/non_existent/expected.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json b/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json index 58aafc3..beb78e9 100644 --- a/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json +++ b/Tests/fixtures/json/testcases/non_existent_with_environment/dist.json @@ -8,4 +8,4 @@ "bar": "baz" } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json b/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json index b9b0189..bc36e58 100644 --- a/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json +++ b/Tests/fixtures/json/testcases/non_existent_with_environment/expected.json @@ -12,4 +12,4 @@ ] } } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/remove_outdated/dist.json b/Tests/fixtures/json/testcases/remove_outdated/dist.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/remove_outdated/dist.json +++ b/Tests/fixtures/json/testcases/remove_outdated/dist.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/remove_outdated/existing.json b/Tests/fixtures/json/testcases/remove_outdated/existing.json index 2af597d..ee8f822 100644 --- a/Tests/fixtures/json/testcases/remove_outdated/existing.json +++ b/Tests/fixtures/json/testcases/remove_outdated/existing.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "outdated": "outdated_param" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/remove_outdated/expected.json b/Tests/fixtures/json/testcases/remove_outdated/expected.json index 98ee282..57437bc 100644 --- a/Tests/fixtures/json/testcases/remove_outdated/expected.json +++ b/Tests/fixtures/json/testcases/remove_outdated/expected.json @@ -2,4 +2,4 @@ "parameters": { "foo": "existing_foo" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed/dist.json b/Tests/fixtures/json/testcases/renamed/dist.json index 7e11e1b..2547e1a 100644 --- a/Tests/fixtures/json/testcases/renamed/dist.json +++ b/Tests/fixtures/json/testcases/renamed/dist.json @@ -6,4 +6,4 @@ "new4": "test4", "new5": "test5" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed/existing.json b/Tests/fixtures/json/testcases/renamed/existing.json index 7cf2f11..763a2bc 100644 --- a/Tests/fixtures/json/testcases/renamed/existing.json +++ b/Tests/fixtures/json/testcases/renamed/existing.json @@ -5,4 +5,4 @@ "old2": "bar", "old4": "old4" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed/expected.json b/Tests/fixtures/json/testcases/renamed/expected.json index d96420f..5ec77ae 100644 --- a/Tests/fixtures/json/testcases/renamed/expected.json +++ b/Tests/fixtures/json/testcases/renamed/expected.json @@ -6,4 +6,4 @@ "new4": "old4", "new5": "old4" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/dist.json b/Tests/fixtures/json/testcases/renamed_and_environment/dist.json index db8a93a..0ce2ab4 100644 --- a/Tests/fixtures/json/testcases/renamed_and_environment/dist.json +++ b/Tests/fixtures/json/testcases/renamed_and_environment/dist.json @@ -3,4 +3,4 @@ "new": "bar", "new2": "new2" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/existing.json b/Tests/fixtures/json/testcases/renamed_and_environment/existing.json index 07051d1..cad0abb 100644 --- a/Tests/fixtures/json/testcases/renamed_and_environment/existing.json +++ b/Tests/fixtures/json/testcases/renamed_and_environment/existing.json @@ -3,4 +3,4 @@ "old": "old_value", "old2": "old_value2" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/renamed_and_environment/expected.json b/Tests/fixtures/json/testcases/renamed_and_environment/expected.json index db77349..cb24ebe 100644 --- a/Tests/fixtures/json/testcases/renamed_and_environment/expected.json +++ b/Tests/fixtures/json/testcases/renamed_and_environment/expected.json @@ -3,4 +3,4 @@ "new": "new_env_value", "new2": "old_value2" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/subfolder/dist.json b/Tests/fixtures/json/testcases/subfolder/dist.json index e66031d..4d3059b 100644 --- a/Tests/fixtures/json/testcases/subfolder/dist.json +++ b/Tests/fixtures/json/testcases/subfolder/dist.json @@ -3,4 +3,4 @@ "foo": "bar", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/subfolder/existing.json b/Tests/fixtures/json/testcases/subfolder/existing.json index 10608a6..869e880 100644 --- a/Tests/fixtures/json/testcases/subfolder/existing.json +++ b/Tests/fixtures/json/testcases/subfolder/existing.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/subfolder/expected.json b/Tests/fixtures/json/testcases/subfolder/expected.json index 10608a6..869e880 100644 --- a/Tests/fixtures/json/testcases/subfolder/expected.json +++ b/Tests/fixtures/json/testcases/subfolder/expected.json @@ -3,4 +3,4 @@ "foo": "existing_foo", "boolean": false } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/subfolder_created/dist.json b/Tests/fixtures/json/testcases/subfolder_created/dist.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/subfolder_created/dist.json +++ b/Tests/fixtures/json/testcases/subfolder_created/dist.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} diff --git a/Tests/fixtures/json/testcases/subfolder_created/expected.json b/Tests/fixtures/json/testcases/subfolder_created/expected.json index 13eb389..e797330 100644 --- a/Tests/fixtures/json/testcases/subfolder_created/expected.json +++ b/Tests/fixtures/json/testcases/subfolder_created/expected.json @@ -2,4 +2,4 @@ "parameters": { "foo": "bar" } -} \ No newline at end of file +} From 3b8403e0d50ada7d0a545dee12fe38c6a25532e8 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 22:05:06 +0200 Subject: [PATCH 24/32] Fixes for PHP < 5.4 - missed some notations. --- Tests/JsonProcessorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php index f8b4ec0..c4e1a92 100644 --- a/Tests/JsonProcessorTest.php +++ b/Tests/JsonProcessorTest.php @@ -11,7 +11,7 @@ class JsonProcessorTest extends ProphecyTestCase { private $io; - private $environmentBackup = []; + private $environmentBackup = array(); /** * @var Processor @@ -96,7 +96,7 @@ public function testParameterHandling($testCaseName) 'file' => 'parameters.json', ], 'dist-file' => 'parameters.json.dist', - 'environment' => [], + 'environment' => array(), 'interactive' => false, ], (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml')) @@ -160,7 +160,7 @@ private function setInteractionExpectations(array $testCase) public function provideParameterHandlingTestCases() { - $tests = []; + $tests = array(); foreach (glob(__DIR__.'/fixtures/json/testcases/*/') as $folder) { $tests[] = [basename($folder)]; From 3441069cb98cb0980c0f0a2f1e1fed2d741ce42e Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 22:08:47 +0200 Subject: [PATCH 25/32] Fixes for PHP < 5.4 - missed some notations. --- Tests/JsonProcessorTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php index c4e1a92..fbb3b89 100644 --- a/Tests/JsonProcessorTest.php +++ b/Tests/JsonProcessorTest.php @@ -90,15 +90,15 @@ public function testParameterHandling($testCaseName) $dataDir = __DIR__.'/fixtures/json/testcases/'.$testCaseName; $testCase = array_replace_recursive( - [ + array( 'title' => 'unknown test', - 'config' => [ + 'config' => array( 'file' => 'parameters.json', - ], + ), 'dist-file' => 'parameters.json.dist', 'environment' => array(), 'interactive' => false, - ], + ), (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml')) ); From 4d40e3c94d20c7644b1b60cd319eaf2a98ad4b51 Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 23:09:20 +0200 Subject: [PATCH 26/32] Fixes for PHP < 5.4 - missed some notations. --- Tests/JsonProcessorTest.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php index fbb3b89..f36e8da 100644 --- a/Tests/JsonProcessorTest.php +++ b/Tests/JsonProcessorTest.php @@ -53,33 +53,33 @@ public function testInvalidConfiguration(array $config, $exceptionMessage) public function provideInvalidConfiguration() { - return [ - 'missing default dist file' => [ - [ + return array( + 'missing default dist file' => array( + array( 'file' => 'fixtures/json/invalid/missing.json', - ], + ), 'The dist file "fixtures/json/invalid/missing.json.dist" does not exist. Check your dist-file config or create it.', - ], - 'missing custom dist file' => [ - [ + ), + 'missing custom dist file' => array( + array( 'file' => 'fixtures/json/invalid/missing.json', 'dist-file' => 'fixtures/json/invalid/non-existent.dist.json', - ], + ), 'The dist file "fixtures/json/invalid/non-existent.dist.json" does not exist. Check your dist-file config or create it.', - ], - 'missing top level key in dist file' => [ - [ + ), + 'missing top level key in dist file' => array( + array( 'file' => 'fixtures/json/invalid/missing_top_level.json', - ], + ), 'The top-level key parameters is missing.', - ], - 'invalid values in the existing file' => [ - [ + ), + 'invalid values in the existing file' => array( + array( 'file' => 'fixtures/json/invalid/invalid_existing_values.json', - ], + ), 'The existing "fixtures/json/invalid/invalid_existing_values.json" file does not contain an array', - ], - ]; + ), + ); } /** From e9dd59e3159f1558e88cd6d55e3b7769fdbf705e Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 23:12:33 +0200 Subject: [PATCH 27/32] Fixes for PHP < 5.4 - missed some notations. --- Tests/JsonProcessorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php index f36e8da..47395b3 100644 --- a/Tests/JsonProcessorTest.php +++ b/Tests/JsonProcessorTest.php @@ -163,7 +163,7 @@ public function provideParameterHandlingTestCases() $tests = array(); foreach (glob(__DIR__.'/fixtures/json/testcases/*/') as $folder) { - $tests[] = [basename($folder)]; + $tests[] = array(basename($folder)); } return $tests; From 0fe9a343010160c28d2b6644e79bb4725350012a Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 23:31:10 +0200 Subject: [PATCH 28/32] Fixes for PHP < 5.4 - missed some notations. --- Processor/AbstractProcessor.php | 10 +++++----- Tests/JsonProcessorTest.php | 2 +- Tests/YamlProcessorTest.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Processor/AbstractProcessor.php b/Processor/AbstractProcessor.php index be2c3e7..d3ec3c6 100644 --- a/Processor/AbstractProcessor.php +++ b/Processor/AbstractProcessor.php @@ -64,12 +64,12 @@ public function processFile(array $config) $actualValues = array_merge( // Preserve other top-level keys than `$parameterKey` in the file $expectedValues, - [$parameterKey => []] + array($parameterKey => array()) ); if ($exists) { $existingValues = $this->parser->parse(file_get_contents($realFile)); if ($existingValues === null) { - $existingValues = []; + $existingValues = array(); } if (!is_array($existingValues)) { throw new \InvalidArgumentException(sprintf('The existing "%s" file does not contain an array', $realFile)); @@ -115,7 +115,7 @@ protected function processConfig(array $config) protected function processParams(array $config, array $expectedParams, array $actualParams) { // Grab values for parameters that were renamed - $renameMap = empty($config['rename-map']) ? [] : (array) $config['rename-map']; + $renameMap = empty($config['rename-map']) ? array() : (array) $config['rename-map']; $actualParams = array_replace($actualParams, $this->processRenamedValues($renameMap, $actualParams)); $keepOutdatedParams = false; @@ -127,7 +127,7 @@ protected function processParams(array $config, array $expectedParams, array $ac $actualParams = array_intersect_key($actualParams, $expectedParams); } - $envMap = empty($config['env-map']) ? [] : (array) $config['env-map']; + $envMap = empty($config['env-map']) ? array() : (array) $config['env-map']; // Add the params coming from the environment values $actualParams = array_replace($actualParams, $this->getEnvValues($envMap)); @@ -146,7 +146,7 @@ protected function processParams(array $config, array $expectedParams, array $ac */ protected function getEnvValues(array $envMap) { - $params = []; + $params = array(); foreach ($envMap as $param => $env) { $value = getenv($env); if ($value) { diff --git a/Tests/JsonProcessorTest.php b/Tests/JsonProcessorTest.php index 47395b3..25825d9 100644 --- a/Tests/JsonProcessorTest.php +++ b/Tests/JsonProcessorTest.php @@ -132,7 +132,7 @@ private function initializeTestCase(array $testCase, $dataDir, $workingDir) foreach ($testCase['environment'] as $var => $value) { $this->environmentBackup[$var] = getenv($var); putenv($var.'='.$value); - }; + } chdir($workingDir); diff --git a/Tests/YamlProcessorTest.php b/Tests/YamlProcessorTest.php index 13785e7..873e606 100644 --- a/Tests/YamlProcessorTest.php +++ b/Tests/YamlProcessorTest.php @@ -132,7 +132,7 @@ private function initializeTestCase(array $testCase, $dataDir, $workingDir) foreach ($testCase['environment'] as $var => $value) { $this->environmentBackup[$var] = getenv($var); putenv($var.'='.$value); - }; + } chdir($workingDir); From 93100961d0ebb08bcd64ed516d9633ac2826aa2c Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Mon, 12 Sep 2016 23:36:00 +0200 Subject: [PATCH 29/32] Fixes for PHP < 5.4 - missed some notations. --- Parser/JsonParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index 6b02555..a12124b 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -19,7 +19,7 @@ class JsonParser implements ParserInterface public function parse($value, $flags = 0, $assoc = true, $depth = 512) { if ('' === $value) { - $result = []; + $result = array(); } else { $result = json_decode($value, $assoc, $depth, $flags); if (null === $result) { From ddc70fa8e803b14a09aaf97069ab11862296aecc Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Tue, 13 Sep 2016 00:03:14 +0200 Subject: [PATCH 30/32] Fixes for PHP < 5.4 - missed some notations. --- ScriptHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ScriptHandler.php b/ScriptHandler.php index 7674276..767743a 100644 --- a/ScriptHandler.php +++ b/ScriptHandler.php @@ -43,10 +43,10 @@ class ScriptHandler * * @var array */ - protected static $handable = [ + protected static $handable = array( self::CONFIGURATION_FORMAT_YAML, self::CONFIGURATION_FORMAT_JSON, - ]; + ); public static function buildParameters(Event $event) { @@ -63,7 +63,7 @@ public static function buildParameters(Event $event) } if (array_keys($configs) !== range(0, count($configs) - 1)) { - $configs = [$configs]; + $configs = array($configs); } foreach ($configs as $config) { From 8cd469f512e643d174f4fe45408f12ee1bf0adab Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Tue, 13 Sep 2016 00:07:57 +0200 Subject: [PATCH 31/32] Fixes for PHP < 5.4 - json_decode. --- Parser/JsonParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index a12124b..e8d07cc 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -21,7 +21,7 @@ public function parse($value, $flags = 0, $assoc = true, $depth = 512) if ('' === $value) { $result = array(); } else { - $result = json_decode($value, $assoc, $depth, $flags); + $result = json_decode($value, $assoc, $depth); if (null === $result) { $result = false; } From e780caceeeb38a2ac2d10cb229d7371076c950dd Mon Sep 17 00:00:00 2001 From: Benjamin Carl Date: Thu, 15 Sep 2016 08:39:13 +0200 Subject: [PATCH 32/32] TidyUp // Fixed some bad comments and typehints. --- Parser/JsonParser.php | 2 -- Parser/ParseException.php | 8 -------- Processor/AbstractProcessor.php | 4 +++- Tests/JsonProcessorTest.php | 9 ++++++++- Tests/ScriptHandlerTest.php | 12 ++++++++++++ Tests/YamlProcessorTest.php | 9 ++++++++- 6 files changed, 31 insertions(+), 13 deletions(-) delete mode 100644 Parser/ParseException.php diff --git a/Parser/JsonParser.php b/Parser/JsonParser.php index e8d07cc..000ec5c 100644 --- a/Parser/JsonParser.php +++ b/Parser/JsonParser.php @@ -13,8 +13,6 @@ class JsonParser implements ParserInterface * @param int $depth User specified recursion depth. * * @return mixed A PHP value - * - * @throws ParseException On any error parsing the JSON data. */ public function parse($value, $flags = 0, $assoc = true, $depth = 512) { diff --git a/Parser/ParseException.php b/Parser/ParseException.php deleted file mode 100644 index b7cecb9..0000000 --- a/Parser/ParseException.php +++ /dev/null @@ -1,8 +0,0 @@ -event = $this->prophesize('Composer\Script\Event'); $this->io = $this->prophesize('Composer\IO\IOInterface'); $this->package = $this->prophesize('Composer\Package\PackageInterface'); + /* @var $composer \Composer\Composer */ $composer = $this->prophesize('Composer\Composer'); $composer->getPackage()->willReturn($this->package); diff --git a/Tests/YamlProcessorTest.php b/Tests/YamlProcessorTest.php index 873e606..226d31f 100644 --- a/Tests/YamlProcessorTest.php +++ b/Tests/YamlProcessorTest.php @@ -10,11 +10,18 @@ class YamlProcessorTest extends ProphecyTestCase { + /** + * @var \Composer\IO\IOInterface + */ private $io; + + /** + * @var array + */ private $environmentBackup = array(); /** - * @var Processor + * @var YamlProcessor */ private $processor;