/
FrameworkObjectTest.php
141 lines (106 loc) · 3.32 KB
/
FrameworkObjectTest.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
require_once 'PHPUnit/Framework.php';
Library::import('recess.lang.Object');
class MyObject extends Object {
/** !Wrappable argumentFree */
public function wrappedArgumentFree() {
return 'argumentFree';
}
/** !Wrappable singleArgument */
public function wrappedSingleArgument($argument) {
return "Arg:$argument";
}
/** !Wrappable testWrapper */
public function wrappedTestWrapper() {
return 0;
}
/** !Wrappable testWrappers */
public function wrappedTestWrappers() {
return 0;
}
}
class Add1ToAnnotation extends Annotation implements IWrapper {
protected $method;
function init($array) { $this->method = $array[0]; }
function shapeDescriptor($class, $reflection, $descriptor) {
$descriptor->addWrapper($this->method, $this);
}
function combine(IWrapper $requiredWrapper) {}
function before($object, &$args) {}
function after($object, $result) { return $result + 1; }
}
class ConcatAnnotation extends Annotation implements IWrapper {
protected $prepend;
protected $append;
protected $method;
function init($array) {
$this->prepend = $array[0];
$this->append = $array[1];
$this->method = $array[2];
}
function shapeDescriptor($class, $reflection, $descriptor) {
$descriptor->addWrapper($this->method, $this);
}
function combine(IWrapper $requiredWrapper) {}
function before($object, &$args) { $args[1] = $this->prepend . $args[1]; }
function after($object, $result) { return $result . $this->append; }
}
/**
* !Add1To testWrapper
* !Add1To testWrappers
* !Add1To testWrappers
* !Concat "Hello ", "!!!", stringConcat
* !Concat "{", "}", twoConcats
* !Concat "[", "]", twoConcats
* !Concat "(", ")", twoConcats
**/
class MyExtendedObject extends MyObject {
/** !Wrappable singleArgument */
public function wrappedSingleArgument($argument) {
return parent::wrappedSingleArgument($argument);
}
/** !Wrappable stringConcat */
public function wrappedStringConcat($string) {
return $string . ' World';
}
/** !Wrappable twoConcats */
public function theConventionDoesntMatter($string) {
return $string . ' World';
}
}
class ObjectTest extends PHPUnit_Framework_TestCase {
function testSimpleWrappedMethod() {
$obj = new MyObject();
$this->assertEquals('argumentFree', $obj->argumentFree());
$this->assertEquals('argumentFree', $obj->wrappedArgumentFree());
}
function testSingleArgumentWrappedMethod() {
$obj = new MyObject();
$this->assertEquals('Arg:Hello World', $obj->singleArgument('Hello World'));
}
function testShadowedSingleArgumentWrappedMethod() {
$obj = new MyExtendedObject();
$this->assertEquals('Arg:Hello World2', $obj->singleArgument('Hello World2'));
}
function testParentWrapped() {
$obj = new MyExtendedObject();
$this->assertEquals('argumentFree', $obj->argumentFree());
}
function testWrapperAfter() {
$obj = new MyExtendedObject();
$this->assertEquals(1, $obj->testWrapper());
}
function testWrappersAfter() {
$obj = new MyExtendedObject();
$this->assertEquals(2, $obj->testWrappers());
}
function testStringConcat() {
$obj = new MyExtendedObject();
$this->assertEquals('Hello Wrappable World!!!', $obj->stringConcat('Wrappable'));
}
function testMultipleStringConcats() {
$obj = new MyExtendedObject();
$this->assertEquals('([{Wrappable World}])', $obj->twoConcats('Wrappable'));
}
}
?>