Test Setup Failed
Push — test ( 24878d...6ecee8 )
by Jonathan
02:38
created

KintTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 137
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 2
1
<?php
2
3
namespace Kint\Test;
4
5
use Kint;
6
use ReflectionClass;
7
use ReflectionProperty;
8
9
class KintTest extends KintTestCase
10
{
11
    /**
12
     * @covers \Kint::settings
13
     */
14
    public function testSettings()
15
    {
16
        $r = new ReflectionClass('Kint');
17
18
        $props = $r->getProperties(ReflectionProperty::IS_STATIC);
19
        $props_array = array();
20
        foreach ($props as $prop) {
21
            if ($prop->isPublic() && $prop->isStatic()) {
22
                $props_array[$prop->getName()] = $prop->getValue();
23
            }
24
        }
25
26
        $props = $r->getStaticProperties();
27
28
        $this->assertEquals($props_array, $stash = Kint::settings());
29
30
        $props_array['enabled_mode'] = Kint::$enabled_mode = false;
31
        $props_array['file_link_format'] = Kint::$file_link_format = 'linky';
32
        $props_array['app_root_dirs'] = Kint::$app_root_dirs = array('/' => '<fsroot>');
33
        $props_array['max_depth'] = Kint::$max_depth = 0;
34
        $props_array['expanded'] = Kint::$expanded = true;
35
        $props_array['cli_detection'] = Kint::$cli_detection = false;
36
37
        $this->assertNotEquals($props, $r->getStaticProperties());
38
        $this->assertEquals($props_array, Kint::settings($stash));
39
        $this->assertEquals($props, $r->getStaticProperties());
40
    }
41
42
    public function pathProvider()
43
    {
44
        return array(
45
            'standard file' => array(
46
                'path' => __FILE__,
47
                'expect' => '<tests>/KintTest.php',
48
            ),
49
            'standard dir' => array(
50
                'path' => __DIR__,
51
                'expect' => '<tests>',
52
            ),
53
            'parent dir' => array(
54
                'path' => KINT_DIR,
55
                'expect' => '<kint>',
56
            ),
57
            'sub file' => array(
58
                'path' => KINT_DIR.'/src//test',
59
                'expect' => '<kint>/src/test',
60
            ),
61
            'common path' => array(
62
                'path' => dirname(KINT_DIR).'/test/',
63
                'expect' => '.../test',
64
            ),
65
            'root path' => array(
66
                'path' => '/',
67
                'expect' => '/',
68
            ),
69
            'no common path' => array(
70
                'path' => '/asdfasdf/test/',
71
                'expect' => '/asdfasdf/test',
72
            ),
73
        );
74
    }
75
76
    /**
77
     * @dataProvider pathProvider
78
     * @covers \Kint::shortenPath
79
     */
80
    public function testShortenPath($path, $expect)
81
    {
82
        Kint::$app_root_dirs = array(
83
            KINT_DIR => '<kint>',
84
            KINT_DIR.'/test' => '<test>',
85
            __DIR__ => '<tests>',
86
            KINT_DIR.'/tes' => '<tes>',
87
        );
88
89
        $this->assertEquals($expect, Kint::shortenPath($path));
90
    }
91
92
    /**
93
     * @covers \Kint::getIdeLink
94
     */
95
    public function testGetIdeLink()
96
    {
97
        Kint::$file_link_format = '<a href="%f:%l">%f:%l</a>';
98
99
        $file = uniqid('', true);
100
        $line = uniqid('', true);
101
102
        $this->assertEquals('<a href="'.$file.':'.$line.'">'.$file.':'.$line.'</a>', Kint::getIdeLink($file, $line));
103
    }
104
105
    public function setUp()
106
    {
107
        parent::setUp();
108
109
        if ($this->getName() === 'testComposerGetExtras' && !getenv('KINT_FILE')) {
110
            rename(KINT_DIR.'/composer.json', KINT_DIR.'/composer.json.bak');
111
112
            file_put_contents(KINT_DIR.'/composer.json', json_encode(array(
113
                'extra' => array(
114
                    'kint' => array('test' => 'data'),
115
                ),
116
            )));
117
        }
118
    }
119
120
    public function tearDown()
121
    {
122
        parent::tearDown();
123
124
        if ($this->getName() === 'testComposerGetExtras' && !getenv('KINT_FILE')) {
125
            rename(KINT_DIR.'/composer.json.bak', KINT_DIR.'/composer.json');
126
        }
127
    }
128
129
    /**
130
     * Test Kint::composerGetExtras.
131
     *
132
     * This is a flimsy test but it's as good as it gets without altering
133
     * composer.json mid-test without a proper setup/teardown in place
134
     *
135
     * @covers \Kint::composerGetExtras
136
     */
137
    public function testComposerGetExtras()
138
    {
139
        if (getenv('KINT_FILE')) {
140
            $this->markTestSkipped('Not testing composerGetExtras in single file build');
141
        }
142
143
        $this->assertEquals(array('test' => 'data'), Kint::composerGetExtras('kint'));
144
    }
145
}
146