@@ -25,7 +25,7 @@ public function it_can_set_new_field_for_each_item_of_multiarray()
25
25
}
26
26
27
27
/** @test */
28
- public function and_it_takes_multiarray_param_by_reference ()
28
+ public function it_takes_multiarray_param_by_reference ()
29
29
{
30
30
$ multiarray = [
31
31
['name ' => 'Mercedes-Benz ' ],
@@ -43,4 +43,58 @@ public function and_it_takes_multiarray_param_by_reference()
43
43
44
44
$ this ->assertEquals ($ expected , $ multiarray );
45
45
}
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
+ }
46
100
}
0 commit comments