public function NestedArrayTest::testMergeExplicitKeys in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()
- 9 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\UtilityCode
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.');
}