forked from Runalyze/Runalyze
/
ObjectTest.php
176 lines (140 loc) · 3.69 KB
/
ObjectTest.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace Runalyze\Model;
class Object_MockTester extends Object {
public function properties() {
return array('a', 'b', 'c');
}
}
class ObjectWithArrays_MockTester extends Object {
public function properties() {
return array ('a', 'b', 'c');
}
public function isArray($key) {
return ($key == 'b');
}
protected function canSet($key) {
return ($key != 'c');
}
}
class ObjectWithEmptyNumerics_MockTester extends Object {
public function properties() {
return array ('int', 'string');
}
public function synchronize($default = 0) {
$this->ensureNumericValue('int', $default);
}
}
/**
* Generated by hand
*/
class ObjectTest extends \PHPUnit_Framework_TestCase {
public function testStaticArrayMethods() {
$TestArray = array(1, 2, 3);
$this->assertEquals( $TestArray, Object::explode(Object::implode($TestArray)) );
}
public function testSimpleObject() {
$O = new Object_MockTester(array(
'a' => 1,
'b' => '',
'c' => true
));
$this->assertEquals(1, $O->get('a'));
$this->assertEquals('', $O->get('b'));
$this->assertEquals(true, $O->get('c'));
$this->assertEquals(true, $O->has('a'));
$this->assertEquals(false, $O->has('b'));
$this->assertEquals(true, $O->has('c'));
$this->assertEquals(array(
'a' => 1,
'b' => '',
'c' => true
), $O->completeData());
$this->assertEquals(0, $O->num());
}
public function testSimpleObjectWithArray() {
$O = new ObjectWithArrays_MockTester(array(
'a' => 1,
'b' => array(1, 2, 3),
'c' => true
));
$this->assertEquals(array(1,2,3), $O->get('b'));
$this->assertTrue($O->has('b'));
$this->assertEquals(3, $O->num());
$O->set('b', array());
$this->assertFalse($O->has('b'));
$this->assertEquals(0, $O->num());
}
public function testClearing() {
$O = new ObjectWithArrays_MockTester(array(
'a' => 1,
'b' => array(1, 2, 3),
'c' => true
));
$O->clear();
$this->assertEmpty($O->get('a'));
$this->assertEmpty($O->get('b'));
$this->assertEmpty($O->get('c'));
$this->assertTrue($O->isEmpty());
}
public function testSimpleObjectWithArrayAsString() {
$O = new ObjectWithArrays_MockTester(array(
'b' => '1'.Object::ARRAY_SEPARATOR.'2'.Object::ARRAY_SEPARATOR.'3'
));
$this->assertEquals(array(1,2,3), $O->get('b'));
}
public function testDefaultValues() {
$O = new ObjectWithArrays_MockTester();
$this->assertEquals('', $O->get('a'));
$this->assertEquals(array(), $O->get('b'));
$this->assertEquals('', $O->get('c'));
$this->assertTrue($O->isEmpty());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testHasException() {
$O = new Object_MockTester();
$O->has('foo');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testGetException() {
$O = new Object_MockTester();
$O->get('foo');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testSetException() {
$O = new Object_MockTester();
$O->set('foo', 'bar');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidSetException() {
$O = new ObjectWithArrays_MockTester();
$O->set('c', 'd');
}
/**
* @expectedException \RuntimeException
*/
public function testArraySetException() {
$O = new ObjectWithArrays_MockTester();
$O->set('b', 'no-array');
}
public function testEnsuringNumericalValues() {
$O = new ObjectWithEmptyNumerics_MockTester();
$this->assertEquals('', $O->get('int'));
$O->synchronize();
$this->assertEquals(0, $O->get('int'));
$this->assertEquals('', $O->get('string'));
$O->set('int', 3.14);
$O->synchronize();
$this->assertEquals(3.14, $O->get('int'));
$O->set('int', '');
$O->synchronize(1);
$this->assertEquals(1, $O->get('int'));
}
}