function NestedArrayTest::testMergeImplicitKeys

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeImplicitKeys()
  2. 10 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeImplicitKeys()
  3. 11.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeImplicitKeys()

Tests that arrays with implicit keys are appended, not merged.

@covers ::mergeDeepArray

File

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

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeImplicitKeys() {
    $a = [
        'subkey' => [
            'X',
            'Y',
        ],
    ];
    $b = [
        'subkey' => [
            'X',
        ],
    ];
    // Drupal core behavior.
    $expected = [
        'subkey' => [
            'X',
            'Y',
            'X',
        ],
    ];
    $actual = NestedArray::mergeDeepArray([
        $a,
        $b,
    ]);
    $this->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the implicit sequence.');
}

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