12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- declare(strict_types=1);
- namespace Fgm\Drupal\Composer;
- use PHPUnit\Framework\TestCase;
- final class MergeParamsCommandTest extends TestCase {
- /**
- * Test MergeParamsCommand::merge().
- *
- * @covers \Fgm\Drupal\Composer\MergeParamsCommand::merge
- */
- public function testMerge() {
- // Base array (like a dist.params.local.yml).
- $dist = [
- 'keyedArray1' => [
- 'key1' => 'dist1',
- 'key2' => 'dist2',
- 'key3' => 'dist3',
- ],
- 'indexedArray1' => [
- 'dist1',
- 'dist2',
- 'dist3',
- ],
- ];
- // Overriding array (like params.local.yml).
- $local = [
- 'keyedArray1' => [
- 'key1' => 'local1',
- 'key3' => NULL,
- 'key4' => 'local4',
- ],
- 'keyedArray2' => [
- 'key1' => 'local1',
- ],
- 'indexedArray1' => [
- 'local1',
- 'local2',
- ],
- ];
- // Merged array (like merged.params.local.yml).
- $merged = MergeParamsCommand::mergeDeepArray([$dist, $local]);
- $expected = [
- 'keyedArray1' => [
- // Key1 : Dist value is overrided by local value.
- 'key1' => 'local1',
- // Key2 : No overriding in local, dist value is transmitted.
- 'key2' => 'dist2',
- // Key3 : Dist value is overrided with a NULL value: key3 is removed.
- // Key4 : No key4 in dist array, local Key4 is added.
- 'key4' => 'local4',
- ],
- // No Array2 in dist, local Array2 is added.
- 'keyedArray2' => [
- 'key1' => 'local1',
- ],
- // Dist indexed array is replaced by local index array.
- 'indexedArray1' => [
- 'local1',
- 'local2',
- ],
- ];
- $this->assertEquals($expected, $merged);
- }
- }
|