| Total Complexity | 4 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
|
| 53 |