Passed
Pull Request — master (#5)
by Jonas
01:28
created

ArrayGetTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 44
ccs 24
cts 24
cp 1
rs 10
1
<?php
2
3
namespace ArrayHelpers;
4
5
use PHPUnit\Framework\TestCase;
6
7
class ArrayGetTest extends TestCase
8
{
9 1
    public function testWillReturnDefaultIfNotAvailable()
10
    {
11 1
        $data = [];
12 1
        $key = 'foo';
13 1
        $default = 'bar';
14 1
        $result = Arr::get($data, $key, $default);
15 1
        $this->assertEquals($default, $result);
16 1
    }
17
18 1
    public function testWillReturnNullIfNoDefaultSpecified()
19
    {
20 1
        $data = [];
21 1
        $key = 'foo';
22 1
        $result = Arr::get($data, $key);
23 1
        $this->assertNull($result);
24 1
    }
25
26 1
    public function testWillReturnValueForKey()
27
    {
28
        $data = [
29 1
            'foo' => 'fighters',
30
            'bar' => 'tenders',
31
        ];
32 1
        $key = 'foo';
33 1
        $result = Arr::get($data, $key);
34 1
        $this->assertEquals('fighters', $result);
35 1
    }
36
37 1
    public function testWillFindUsingDotNotation()
38
    {
39
        $data = [
40 1
            'i' => [
41
                "can't" => [
42
                    'get' => [
43
                        'no' => 'satisfaction',
44
                    ],
45
                ],
46
            ],
47
        ];
48 1
        $key = "i.can't.get.no";
49 1
        $result = Arr::get($data, $key);
50 1
        $this->assertEquals('satisfaction', $result);
51 1
    }
52
}
53