MergeParamsCommandTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. namespace Fgm\Drupal\Composer;
  4. use PHPUnit\Framework\TestCase;
  5. final class MergeParamsCommandTest extends TestCase {
  6. /**
  7. * Test MergeParamsCommand::merge().
  8. *
  9. * @covers \Fgm\Drupal\Composer\MergeParamsCommand::mergeDeepArray
  10. */
  11. public function testMergeDeepArray() {
  12. // Base array (like a dist.params.local.yml).
  13. $dist = [
  14. 'keyedArray1' => [
  15. 'key1' => 'dist1',
  16. 'key2' => 'dist2',
  17. 'key3' => 'dist3',
  18. ],
  19. 'indexedArray1' => [
  20. 'dist1',
  21. 'dist2',
  22. 'dist3',
  23. ],
  24. ];
  25. // Overriding array (like params.local.yml).
  26. $local = [
  27. 'keyedArray1' => [
  28. 'key1' => 'local1',
  29. 'key3' => NULL,
  30. 'key4' => 'local4',
  31. ],
  32. 'keyedArray2' => [
  33. 'key1' => 'local1',
  34. ],
  35. 'indexedArray1' => [
  36. 'local1',
  37. 'local2',
  38. ],
  39. ];
  40. // Merged array (like merged.params.local.yml).
  41. $merged = MergeParamsCommand::mergeDeepArray([$dist, $local]);
  42. $expected = [
  43. 'keyedArray1' => [
  44. // Key1 : Dist value is overrided by local value.
  45. 'key1' => 'local1',
  46. // Key2 : No overriding in local, dist value is transmitted.
  47. 'key2' => 'dist2',
  48. // Key3 : Dist value is overrided with a NULL value: key3 is removed.
  49. // Key4 : No key4 in dist array, local Key4 is added.
  50. 'key4' => 'local4',
  51. ],
  52. // No Array2 in dist, local Array2 is added.
  53. 'keyedArray2' => [
  54. 'key1' => 'local1',
  55. ],
  56. // Dist indexed array is replaced by local index array.
  57. 'indexedArray1' => [
  58. 'local1',
  59. 'local2',
  60. ],
  61. ];
  62. $this->assertEquals($expected, $merged);
  63. }
  64. }