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

ArrayGetTest::testWillReturnDefaultIfNotAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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