FallbacksTest::testPopulateFallbacks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Tests\Service;
4
5
use SumoCoders\FrameworkCoreBundle\Service\Fallbacks;
6
7
class FallbacksTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Fallbacks
11
     */
12
    private $fallbacks;
13
14
    /**
15
     * @var array
16
     */
17
    private $defaultData = [
18
        'foo' => 'bar',
19
        'name' => [
20
            'first' => 'John',
21
            'last' => 'Doe',
22
        ],
23
        'servers' => [
24
            'web01',
25
            'web02',
26
        ],
27
        'a' => [
28
            'very' => [
29
                'deep' => [
30
                    'array' => [
31
                        'x' => 0,
32
                        'y' => 0,
33
                    ],
34
                ],
35
            ],
36
        ],
37
        'errorcodes' => [
38
            404 => 'Not Found',
39
            500 => 'Internal server error',
40
        ],
41
    ];
42
43
    /**
44
     * Test Fallbacks()
45
     */
46
    public function testPopulateFallbacks()
47
    {
48
        $this->fallbacks = new Fallbacks();
49
        $this->assertNull($this->fallbacks->get('foo')); // we no data is passed we can't grab anything
50
    }
51
52
    /**
53
     * Tests Fallbacks->get()
54
     */
55
    public function testGet()
56
    {
57
        $this->fallbacks = new Fallbacks($this->defaultData);
58
59
        $this->assertEquals($this->defaultData['foo'], $this->fallbacks->get('foo'));
60
        $this->assertEquals($this->defaultData['name']['first'], $this->fallbacks->get('name')['first']);
61
        $this->assertEquals($this->defaultData['servers'], $this->fallbacks->get('servers'));
62
        $this->assertEquals(
63
            $this->defaultData['a']['very']['deep']['array']['x'],
64
            $this->fallbacks->get('a')['very']['deep']['array']['x']
65
        );
66
        $this->assertEquals(
67
            $this->defaultData['errorcodes'][404],
68
            $this->fallbacks->get('errorcodes')[404]
69
        );
70
    }
71
}
72