Kint_Object_MethodTest::testGetParams()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 18
nc 2
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
class Kint_Object_MethodTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style introduced by
Kint_Object_MethodTest 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...
4
{
5
    public function testConstruct()
6
    {
7
        $reflection = new ReflectionMethod('TestClass', 'mix');
8
        $m = new Kint_Object_Method($reflection);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
9
        $this->assertEquals('mix', $m->name);
10
        $this->assertEquals($reflection->getFilename(), $m->filename);
11
        $this->assertEquals($reflection->getStartLine(), $m->startline);
12
        $this->assertEquals($reflection->getEndLine(), $m->endline);
13
        $this->assertEquals(false, $m->internal);
14
        $this->assertEquals($reflection->getDocComment(), $m->docstring);
15
        $this->assertEquals(Kint_Object::OPERATOR_STATIC, $m->operator);
16
        $this->assertEquals(Kint_Object::ACCESS_PROTECTED, $m->access);
17
        $this->assertEquals('TestClass', $m->owner_class);
18
        $this->assertTrue($m->static);
19
        $this->assertTrue($m->final);
20
        $this->assertFalse($m->abstract);
21
        $this->assertFalse($m->internal);
22
23
        $reflection = new ReflectionMethod('ChildTestClass', '__construct');
24
        $parent_reflection = new ReflectionMethod('TestClass', '__construct');
0 ignored issues
show
Coding Style introduced by
$parent_reflection 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...
25
        $m = new Kint_Object_Method($reflection);
26
        $this->assertEquals($parent_reflection->getDocComment(), $m->docstring);
0 ignored issues
show
Coding Style introduced by
$parent_reflection 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...
27
        $this->assertEquals(Kint_Object::OPERATOR_OBJECT, $m->operator);
28
        $this->assertEquals(Kint_Object::ACCESS_PUBLIC, $m->access);
29
        $this->assertEquals('TestClass', $m->owner_class);
30
31
        $reflection = new ReflectionFunction('explode');
32
        $m = new Kint_Object_Method($reflection);
33
        $this->assertTrue($m->internal);
34
        $this->assertEquals(Kint_Object::OPERATOR_NONE, $m->operator);
35
        $this->assertEquals(Kint_Object::ACCESS_NONE, $m->access);
36
        $this->assertEquals(null, $m->owner_class);
37
    }
38
39
    /**
40
     * @expectedException \InvalidArgumentException
41
     */
42
    public function testConstructWrongType()
43
    {
44
        $m = new Kint_Object_Method(new stdClass());
0 ignored issues
show
Unused Code introduced by
$m is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
45
    }
46
47
    public function testSetAccessPathFrom()
48
    {
49
        $o = Kint_Object::blank('$tc');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. 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...
50
        $o = $o->transplant(new Kint_Object_Instance());
51
        $o->classname = 'TestClass';
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
52
53
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__construct'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
54
        $this->assertNull($m->getAccessPath());
55
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
56
        $this->assertEquals('new \\TestClass()', $m->getAccessPath());
57
58
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'static_method'));
59
        $this->assertNull($m->getAccessPath());
60
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
61
        $this->assertEquals('\\TestClass::static_method()', $m->getAccessPath());
62
63
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'final_method'));
64
        $this->assertNull($m->getAccessPath());
65
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
66
        $this->assertEquals('$tc->final_method()', $m->getAccessPath());
67
68
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix'));
69
        $this->assertNull($m->getAccessPath());
70
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
71
        $this->assertEquals(
72
            '\\TestClass::mix(array &$x, TestClass $y = null, $z = array(...), $_ = \'string\')',
73
            $m->getAccessPath()
74
        );
75
76
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__clone'));
77
        $this->assertNull($m->getAccessPath());
78
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
79
        $this->assertEquals('clone $tc', $m->getAccessPath());
80
81
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__invoke'));
82
        $this->assertNull($m->getAccessPath());
83
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
84
        $this->assertEquals('$tc($x)', $m->getAccessPath());
85
86
        // Tests both tostring and case insensitivity
87
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__tostring'));
88
        $this->assertNull($m->getAccessPath());
89
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
90
        $this->assertEquals('__ToStRiNg', $m->name);
91
        $this->assertEquals('(string) $tc', $m->getAccessPath());
92
93
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__get'));
94
        $this->assertNull($m->getAccessPath());
95
        $m->setAccessPathFrom($o);
0 ignored issues
show
Compatibility introduced by
$o of type object<Kint_Object> is not a sub-type of object<Kint_Object_Instance>. It seems like you assume a child class of the class Kint_Object to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
96
        $this->assertNull($m->getAccessPath());
97
    }
98
99
    public function testGetValueShort()
100
    {
101
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', '__construct'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
102
        $this->assertEquals(
103
            'This is a constructor for a TestClass with the first line of the docstring split into two different lines.',
104
            $m->getValueShort()
105
        );
106
    }
107
108
    public function testGetModifiers()
109
    {
110
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'static_method'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
111
        $this->assertEquals('private static', $m->getModifiers());
112
113
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'final_method'));
114
        $this->assertEquals('final public', $m->getModifiers());
115
116
        $m = new Kint_Object_Method(new ReflectionMethod('ReflectionFunctionAbstract', '__toString'));
117
        $this->assertEquals('abstract public', $m->getModifiers());
118
119
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix'));
120
        $this->assertEquals('final protected static', $m->getModifiers());
121
    }
122
123
    public function testGetAccessPath()
124
    {
125
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'array_hint'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
126
        $this->assertNull($m->getAccessPath());
127
        $m->access_path = '$m->array_hint';
128
        $this->assertEquals('$m->array_hint(array $x)', $m->getAccessPath());
129
    }
130
131
    public function testGetParams()
132
    {
133
        $m = new Kint_Object_Method(new ReflectionFunction('explode'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
134
        if (defined('HHVM_VERSION')) {
135
            $this->assertStringStartsWith('HH\\string $delimiter, HH\\string $str, HH\\int $limit = ', $m->getParams());
136
        } else {
137
            $this->assertEquals('$separator, $str, $limit', $m->getParams());
138
        }
139
140
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'array_hint'));
141
        $this->assertEquals('array $x', $m->getParams());
142
143
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'class_hint'));
144
        $this->assertEquals('TestClass $x', $m->getParams());
145
146
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'ref'));
147
        $this->assertEquals('&$x', $m->getParams());
148
149
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'default_method'));
150
        $this->assertEquals('$x = 1234', $m->getParams());
151
152
        $m = new Kint_Object_Method(new ReflectionMethod('TestClass', 'mix'));
153
        $this->assertEquals(
154
            'array &$x, TestClass $y = null, $z = array(...), $_ = \'string\'',
155
            $m->getParams()
156
        );
157
    }
158
159
    public function testGetPhpDocUrl()
160
    {
161
        $m = new Kint_Object_Method(new ReflectionMethod('ReflectionMethod', '__construct'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
162
        $this->assertEquals(
163
            'https://secure.php.net/reflectionmethod.construct',
164
            $m->getPhpDocUrl()
165
        );
166
    }
167
168
    public function testGetPhpDocUrlParent()
169
    {
170
        $m = new Kint_Object_Method(new ReflectionMethod('ReflectionMethod', '__clone'));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
171
        $this->assertEquals(
172
            'https://secure.php.net/reflectionfunctionabstract.clone',
173
            $m->getPhpDocUrl()
174
        );
175
    }
176
177
    public function testGetPhpDocUrlUserDefined()
178
    {
179
        $m = new Kint_Object_Method(new ReflectionMethod(__CLASS__, __FUNCTION__));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. 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...
180
        $this->assertNull($m->getPhpDocUrl());
181
    }
182
}
183