Passed
Pull Request — master (#5)
by Jonas
01:28
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 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