function NestedArrayTest::testMergeExplicitKeys

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
  3. 11.x 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 200

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeExplicitKeys() : void {
    $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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.