Skip to content

Commit

Permalink
Fixes #888: Adding unit test for YamlMungeCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Jan 11, 2017
1 parent 9813a1a commit c3b8ada
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Console/Command/YamlMungeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
74 changes: 74 additions & 0 deletions tests/phpunit/Blt/YamlMungeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Acquia\Blt\Tests\Blt;

use Acquia\Blt\Console\Command\YamlMungeCommand;
use Acquia\Blt\Tests\BltTestBase;

class YamlMungeCommandTest extends \PHPUnit_Framework_TestCase {

/**
* Tests arrayMergeRecursiveExceptEmpty().
*
* @dataProvider getValueProvider
*/
public function testArrayMergeRecursiveExceptEmpty($array1, $array2, $expected_array) {
$this->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' => [
'enable' => [ 'test' ]
],
'ci' => [
'uninstall' => [ 'shield' ]
],
],
'behat' => [
'tags' => 'test',
'launch-selenium' => 'true',
],
],
[
'modules' => [
'local' => [
'enable' => [ ]
],
'ci' => [
'uninstall' => [ 'shield' ]
],
],
'behat' => [
'tags' => 'nottest'
]
],
[
'modules' => [
'local' => [
'enable' => [ ]
],
'ci' => [
'uninstall' => [ 'shield' ]
],
],
'behat' => [
'tags' => 'nottest',
'launch-selenium' => 'true',
]
],
],
];
}
}

0 comments on commit c3b8ada

Please sign in to comment.