Skip to content

Commit 6acf329

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

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Illuminated\Helpers\HelperFunctions\Tests\ArrayTests;
4+
5+
use Illuminated\Helpers\HelperFunctions\Tests\TestCase;
6+
7+
class MultiarraySetTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_can_set_new_field_for_each_item_of_multiarray()
11+
{
12+
$multiarray = [
13+
['name' => 'Mercedes-Benz'],
14+
['name' => 'BMW'],
15+
['name' => 'Porsche'],
16+
];
17+
18+
$expected = [
19+
['name' => 'Mercedes-Benz', 'country' => 'Germany'],
20+
['name' => 'BMW', 'country' => 'Germany'],
21+
['name' => 'Porsche', 'country' => 'Germany'],
22+
];
23+
24+
$this->assertEquals($expected, multiarray_set($multiarray, 'country', 'Germany'));
25+
}
26+
27+
/** @test */
28+
public function and_it_takes_multiarray_param_by_reference()
29+
{
30+
$multiarray = [
31+
['name' => 'Mercedes-Benz'],
32+
['name' => 'BMW'],
33+
['name' => 'Porsche'],
34+
];
35+
36+
$expected = [
37+
['name' => 'Mercedes-Benz', 'country' => 'Germany'],
38+
['name' => 'BMW', 'country' => 'Germany'],
39+
['name' => 'Porsche', 'country' => 'Germany'],
40+
];
41+
42+
multiarray_set($multiarray, 'country', 'Germany');
43+
44+
$this->assertEquals($expected, $multiarray);
45+
}
46+
}

0 commit comments

Comments
 (0)