1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\PHPSA; |
4
|
|
|
|
5
|
|
|
use PHPSA\ScopePointer; |
6
|
|
|
|
7
|
|
|
class ScopePointerTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @covers \PHPSA\ScopePointer::__construct |
11
|
|
|
*/ |
12
|
|
|
public function testConstructor() |
13
|
|
|
{ |
14
|
|
|
$object = new \stdClass; |
15
|
|
|
$scopePointer = new ScopePointer($object); |
16
|
|
|
|
17
|
|
|
$this->assertInstanceOf('\PHPSA\ScopePointer', $scopePointer); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @covers \PHPSA\ScopePointer::getObject |
22
|
|
|
*/ |
23
|
|
|
public function testGetObject() |
24
|
|
|
{ |
25
|
|
|
$object = new \stdClass; |
26
|
|
|
$scopePointer = new ScopePointer($object); |
27
|
|
|
|
28
|
|
|
$this->assertSame($object, $scopePointer->getObject()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @covers \PHPSA\ScopePointer::isClassMethod() |
33
|
|
|
*/ |
34
|
|
|
public function testIsClassMethod() |
35
|
|
|
{ |
36
|
|
|
$class = $this->getMockBuilder('\PHPSA\Definition\ClassMethod') |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
$scopePointer = new ScopePointer($class); |
40
|
|
|
|
41
|
|
|
$this->assertTrue($scopePointer->isClassMethod()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers \PHPSA\ScopePointer::isClassMethod() |
46
|
|
|
* @dataProvider notClassMethodDataProvider |
47
|
|
|
*/ |
48
|
|
|
public function testIsNotClassMethod($object) |
49
|
|
|
{ |
50
|
|
|
$scopePointer = new ScopePointer($object); |
51
|
|
|
|
52
|
|
|
$this->assertFalse($scopePointer->isClassMethod()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers \PHPSA\ScopePointer::isFunction() |
57
|
|
|
*/ |
58
|
|
|
public function testIsFunction() |
59
|
|
|
{ |
60
|
|
|
$function = $this->getMockBuilder('\PHPSA\Definition\FunctionDefinition') |
61
|
|
|
->disableOriginalConstructor() |
62
|
|
|
->getMock(); |
63
|
|
|
$scopePointer = new ScopePointer($function); |
64
|
|
|
|
65
|
|
|
$this->assertTrue($scopePointer->isFunction()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @covers \PHPSA\ScopePointer::isFunction() |
70
|
|
|
* @dataProvider notFunctionDataProvider |
71
|
|
|
*/ |
72
|
|
|
public function testIsNotFunction($object) |
73
|
|
|
{ |
74
|
|
|
$scopePointer = new ScopePointer($object); |
75
|
|
|
|
76
|
|
|
$this->assertFalse($scopePointer->isFunction()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function notClassMethodDataProvider() |
80
|
|
|
{ |
81
|
|
|
$function = $this->getMockBuilder('\PHPSA\Definition\FunctionDefinition') |
82
|
|
|
->disableOriginalConstructor() |
83
|
|
|
->getMock(); |
84
|
|
|
|
85
|
|
|
return [ |
86
|
|
|
'String' => ['Random characters'], |
87
|
|
|
'Integer' => [42], |
88
|
|
|
'Float' => [pi()], |
89
|
|
|
'StdClass' => [new \StdClass], |
90
|
|
|
'FunctionDefinition' => [$function] |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function notFunctionDataProvider() |
95
|
|
|
{ |
96
|
|
|
$class = $this->getMockBuilder('\PHPSA\Definition\ClassMethod') |
97
|
|
|
->disableOriginalConstructor() |
98
|
|
|
->getMock(); |
99
|
|
|
|
100
|
|
|
return [ |
101
|
|
|
'String' => ['Random characters'], |
102
|
|
|
'Integer' => [42], |
103
|
|
|
'Float' => [pi()], |
104
|
|
|
'StdClass' => [new \StdClass], |
105
|
|
|
'ClassMethod' => [$class] |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|