Test Setup Failed
Push — test ( 4e9ef0...2bbcf6 )
by Jonathan
02:51
created

KintTest::testSettings()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
nc 3
nop 0
dl 0
loc 27
rs 8.5806
c 0
b 0
f 0
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');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
17
18
        $props = $r->getProperties(ReflectionProperty::IS_STATIC);
19
        $props_array = array();
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
20
        foreach ($props as $prop) {
21
            if ($prop->isPublic() && $prop->isStatic()) {
22
                $props_array[$prop->getName()] = $prop->getValue();
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
23
            }
24
        }
25
26
        $props = $r->getStaticProperties();
27
28
        $this->assertEquals($props_array, $stash = Kint::settings());
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
29
30
        $props_array['enabled_mode'] = Kint::$enabled_mode = false;
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
31
        $props_array['file_link_format'] = Kint::$file_link_format = 'linky';
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
32
        $props_array['app_root_dirs'] = Kint::$app_root_dirs = array('/' => '<fsroot>');
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
33
        $props_array['max_depth'] = Kint::$max_depth = 0;
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
        $props_array['expanded'] = Kint::$expanded = true;
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
35
        $props_array['cli_detection'] = Kint::$cli_detection = false;
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
36
37
        $this->assertNotEquals($props, $r->getStaticProperties());
38
        $this->assertEquals($props_array, Kint::settings($stash));
0 ignored issues
show
Coding Style introduced by
$props_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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