diff --git a/src/Console/Command/YamlMungeCommand.php b/src/Console/Command/YamlMungeCommand.php index ccbcba0ed5..018d6def82 100644 --- a/src/Console/Command/YamlMungeCommand.php +++ b/src/Console/Command/YamlMungeCommand.php @@ -60,7 +60,7 @@ protected function munge($file1, $file2) { $file1_contents = (array) $this->parseFile($file1); $file2_contents = (array) $this->parseFile($file2); - $munged_contents = $this->arrayMergeRecursiveExceptEmpty($file1_contents, $file2_contents); + $munged_contents = self::arrayMergeRecursiveExceptEmpty($file1_contents, $file2_contents); return Yaml::dump($munged_contents, 3, 2); } @@ -100,12 +100,12 @@ protected function parseFile($file) { * * @return array */ - protected function arrayMergeRecursiveExceptEmpty(array &$array1, array &$array2) { + public static function arrayMergeRecursiveExceptEmpty(array &$array1, array &$array2) { $merged = $array1; foreach ($array2 as $key => &$value) { if (is_array($value) && isset($merged[$key]) && is_array($merged[$key]) && !empty($value)) { - $merged[$key] = $this->arrayMergeRecursiveExceptEmpty($merged[$key], $value); + $merged[$key] = self::arrayMergeRecursiveExceptEmpty($merged[$key], $value); } else { $merged[$key] = $value; diff --git a/tests/phpunit/Blt/YamlMungeCommandTest.php b/tests/phpunit/Blt/YamlMungeCommandTest.php new file mode 100644 index 0000000000..e487ade5e3 --- /dev/null +++ b/tests/phpunit/Blt/YamlMungeCommandTest.php @@ -0,0 +1,62 @@ +assertEquals(YamlMungeCommand::arrayMergeRecursiveExceptEmpty($array1, $array2), $expected_array); + } + + /** + * Provides values to testArrayMergeRecursiveExceptEmpty(). + * + * @return array + * An array of values to test. + */ + public function getValueProvider() + { + + return [ + [ + [ + 'modules' => [ + 'local' => [ 'test' ], + 'ci' => [ 'shield'], + ], + 'behat' => [ + 'tags' => 'test', + 'launch-selenium' => 'true', + ], + ], + [ + 'modules' => [ + 'local' => [ ], + 'ci' => [ 'shield'], + ], + 'behat' => [ + 'tags' => 'nottest' + ] + ], + [ + 'modules' => [ + 'local' => [ ], + 'ci' => [ 'shield' ], + ], + 'behat' => [ + 'tags' => 'nottest', + 'launch-selenium' => 'true', + ] + ], + ], + ]; + } +}