/
AccessibleObjectTest.php
118 lines (96 loc) · 3.17 KB
/
AccessibleObjectTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
require_once 'PHPUnit/Extensions/Helper/AccessibleObject.php';
class Tests_Extensions_Helper_AccessibleObjectTest
extends PHPUnit_Framework_TestCase {
private $accessible_object;
protected function setUp() {
parent::setUp();
$this->accessibleObject = new PHPUnit_Extensions_Helper_AccessibleObject(
new Tests_Extensions_Helper_AccessibleObject_Object()
);
}
/**
* @expectedException ReflectionException
*/
public function testPrivateMethod_inaccessible() {
$this->accessibleObject->privateMethod();
}
public function testPrivateMethod_accessible() {
$this->assertEquals(
'accessible private called',
$this->accessibleObject->accessiblePrivateMethod()
);
}
/**
* @expectedException ReflectionException
*/
public function testProtectedMethod_inaccessible() {
$this->accessibleObject->protectedMethod();
}
public function testProtectedMethod_accessible() {
$this->assertEquals(
'accessible protected called',
$this->accessibleObject->accessibleProtectedMethod()
);
}
public function testPublicMethod() {
$this->assertEquals(
'public called',
$this->accessibleObject->publicMethod()
);
}
public function testPublicVar_setGet() {
$this->accessibleObject->public_var = 3;
$this->assertEquals(3, $this->accessibleObject->public_var);
}
public function testPublicVar_issetNo() {
$this->assertFalse(isset($this->accessibleObject->public_var));
}
public function testPublicVar_issetYes() {
$this->accessibleObject->public_var = 3;
$this->assertTrue(isset($this->accessibleObject->public_var));
}
public function testPublicVar_unset() {
$this->accessibleObject->public_var = 3;
unset($this->accessibleObject->public_var);
$this->assertFalse(isset($this->accessibleObject->public_var));
}
public function testProtectedMultipleCommentMethod_accessible() {
$this->assertEquals(
'accessible protected multi comment called',
$this->accessibleObject->accessibleMultiCommentMethod()
);
}
}
class Tests_Extensions_Helper_AccessibleObject_Object {
public $public_var;
/** @accessibleForTesting cannot have more on line */
private function privateMethod() {
return 'private called';
}
/** @accessibleForTesting */
private function accessiblePrivateMethod() {
return 'accessible private called';
}
protected function protectedMethod() {
return 'protected called';
}
/**
* @accessibleForTesting
*/
protected function accessibleProtectedMethod() {
return 'accessible protected called';
}
public function publicMethod() {
return 'public called';
}
/**
* This is a test function
*
* @accessibleForTesting
* @return string
*/
protected function accessibleMultiCommentMethod() {
return 'accessible protected multi comment called';
}
}