You are here

public function NestedArrayTest::testMergeExplicitKeys in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
  2. 10 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()

Tests that even with explicit keys, values are appended, not merged.

@covers ::mergeDeepArray

File

core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php, line 194

Class

NestedArrayTest
@coversDefaultClass \Drupal\Component\Utility\NestedArray @group Utility

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeExplicitKeys() {
  $a = [
    'subkey' => [
      0 => 'A',
      1 => 'B',
    ],
  ];
  $b = [
    'subkey' => [
      0 => 'C',
      1 => 'D',
    ],
  ];

  // Drupal core behavior.
  $expected = [
    'subkey' => [
      0 => 'A',
      1 => 'B',
      2 => 'C',
      3 => 'D',
    ],
  ];
  $actual = NestedArray::mergeDeepArray([
    $a,
    $b,
  ]);
  $this
    ->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the explicit sequence.');
}