Skip to content

Commit 13172eb

Browse files
committed
IHF: multiarray_set tests added.
1 parent 6acf329 commit 13172eb

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

tests/HelperFunctions/array/MultiarraySetTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function it_can_set_new_field_for_each_item_of_multiarray()
2525
}
2626

2727
/** @test */
28-
public function and_it_takes_multiarray_param_by_reference()
28+
public function it_takes_multiarray_param_by_reference()
2929
{
3030
$multiarray = [
3131
['name' => 'Mercedes-Benz'],
@@ -43,4 +43,58 @@ public function and_it_takes_multiarray_param_by_reference()
4343

4444
$this->assertEquals($expected, $multiarray);
4545
}
46+
47+
/** @test */
48+
public function it_can_set_existing_field_for_each_item_of_multiarray()
49+
{
50+
$multiarray = [
51+
['name' => 'Mercedes-Benz', 'country' => 'Unknown'],
52+
['name' => 'BMW', 'country' => 'Unknown'],
53+
['name' => 'Porsche', 'country' => 'Unknown'],
54+
];
55+
56+
$expected = [
57+
['name' => 'Mercedes-Benz', 'country' => 'Germany'],
58+
['name' => 'BMW', 'country' => 'Germany'],
59+
['name' => 'Porsche', 'country' => 'Germany'],
60+
];
61+
62+
$this->assertEquals($expected, multiarray_set($multiarray, 'country', 'Germany'));
63+
}
64+
65+
/** @test */
66+
public function it_can_set_new_field_for_each_item_of_multiarray_using_dot_notation()
67+
{
68+
$multiarray = [
69+
['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV']],
70+
['name' => 'BMW', 'details' => ['type' => 'SUV']],
71+
['name' => 'Porsche', 'details' => ['type' => 'SUV']],
72+
];
73+
74+
$expected = [
75+
['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
76+
['name' => 'BMW', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
77+
['name' => 'Porsche', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
78+
];
79+
80+
$this->assertEquals($expected, multiarray_set($multiarray, 'details.country', 'Germany'));
81+
}
82+
83+
/** @test */
84+
public function it_can_set_existing_field_for_each_item_of_multiarray_using_dot_notation()
85+
{
86+
$multiarray = [
87+
['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV', 'country' => 'Unknown']],
88+
['name' => 'BMW', 'details' => ['type' => 'SUV', 'country' => 'Unknown']],
89+
['name' => 'Porsche', 'details' => ['type' => 'SUV', 'country' => 'Unknown']],
90+
];
91+
92+
$expected = [
93+
['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
94+
['name' => 'BMW', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
95+
['name' => 'Porsche', 'details' => ['type' => 'SUV', 'country' => 'Germany']],
96+
];
97+
98+
$this->assertEquals($expected, multiarray_set($multiarray, 'details.country', 'Germany'));
99+
}
46100
}

0 commit comments

Comments
 (0)