Test Failed
Branch master (f21e35)
by Jonas
03:39
created

ArrayGetTest::testWillFindUsingDotNotation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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
    }
17
18
    public function testWillReturnNullIfNoDefaultSpecified()
19
    {
20
        $data = [];
21
        $key = 'foo';
22
        $result = Arr::get($data, $key);
23
        $this->assertNull($result);
24
    }
25
26
    public function testWillReturnValueForKey()
27
    {
28
        $data = [
29
            'foo' => 'fighters',
30
            'bar' => 'tenders',
31
        ];
32
        $key = 'foo';
33
        $result = Arr::get($data, $key);
34
        $this->assertEquals('fighters', $result);
35
    }
36
37
    public function testWillFindUsingDotNotation()
38
    {
39
        $data = [
40
            'i' => [
41
                "can't" => [
42
                    'get' => [
43
                        'no' => 'satisfaction',
44
                    ],
45
                ],
46
            ],
47
        ];
48
        $key = "i.can't.get.no";
49
        $result = Arr::get($data, $key);
50
        $this->assertEquals('satisfaction', $result);
51
    }
52
}
53