forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…cquia#1327) * Allow deploy-exclude-additions.txt to be defined. * Add unit test for new text:munge command. * Update docs to include new exclude additions feature. * Add deploy-exclude-additions.txt to ignore-existing.txt.
- Loading branch information
1 parent
d50eb1c
commit a3cb96a
Showing
8 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Acquia\Blt\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* | ||
*/ | ||
class TextMungeCommand extends BaseCommand { | ||
|
||
/** | ||
* ${inheritdoc}. | ||
*/ | ||
protected function configure() { | ||
$this | ||
->setName('text:munge') | ||
->setAliases(['txt:munge']) | ||
->setDescription('Munge values in two text|txt files') | ||
->addArgument( | ||
'file1', | ||
InputArgument::REQUIRED, | ||
'The first text or txt.' | ||
) | ||
->addArgument( | ||
'file2', | ||
InputArgument::REQUIRED, | ||
'The second text or txt.' | ||
); | ||
} | ||
|
||
/** | ||
* ${inheritdoc}. | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$file1 = $input->getArgument('file1'); | ||
$file2 = $input->getArgument('file2'); | ||
$munged_contents = $this->munge($file1, $file2); | ||
$output->writeln($munged_contents); | ||
} | ||
|
||
/** | ||
* Merges the arrays in two text files. | ||
* | ||
* @param string $file1 | ||
* The file path of the first file. | ||
* @param string $file2 | ||
* The file path of the second file. | ||
* | ||
* @return string | ||
* The merged arrays, in yaml format. | ||
*/ | ||
protected function munge($file1, $file2) { | ||
$file1_contents = file($file1); | ||
$file2_contents = file($file2); | ||
|
||
$munged_contents = self::arrayMergeNoDuplicates($file1_contents, $file2_contents); | ||
|
||
return $munged_contents; | ||
} | ||
|
||
/** | ||
* Merges two arrays and removes duplicate values. | ||
* | ||
* @param array $array1 | ||
* The first array. | ||
* @param array $array2 | ||
* The second array. | ||
* | ||
* @return array | ||
*/ | ||
public static function arrayMergeNoDuplicates(array &$array1, array &$array2) { | ||
$merged = array_merge($array1, $array2); | ||
$merged_without_dups = array_unique($merged); | ||
|
||
return $merged_without_dups; | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Acquia\Blt\Tests\Blt; | ||
|
||
use Acquia\Blt\Console\Command\TextMungeCommand; | ||
|
||
/** | ||
* Tests text:munge command in blt-console. | ||
*/ | ||
class TextMungeCommandTest extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* Tests arrayMergeNoDuplicates(). | ||
* | ||
* @dataProvider getValueProvider | ||
*/ | ||
public function testArrayMergeNoDuplicates( | ||
$array1, | ||
$array2, | ||
$expected_array | ||
) { | ||
$this->assertEquals(TextMungeCommand::arrayMergeNoDuplicates($array1, | ||
$array2), $expected_array); | ||
} | ||
|
||
/** | ||
* Provides values to testArrayMergeNoDuplicates(). | ||
* | ||
* @return array | ||
* An array of values to test. | ||
*/ | ||
public function getValueProvider() { | ||
return [ | ||
[ | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
], | ||
[ | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
'/blt.sh', | ||
'/box', | ||
'/build', | ||
'/additionalfile.txt', | ||
], | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
'/blt.sh', | ||
'/box', | ||
'/build', | ||
'/additionalfile.txt', | ||
], | ||
], | ||
[ | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
], | ||
[], | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
], | ||
], | ||
[ | ||
[], | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
], | ||
[ | ||
'/.drush-use', | ||
'/.idea', | ||
'/.travis.yml', | ||
'/.vagrant', | ||
'/acquia-pipelines.yml', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
} |