1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleORM; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-12-09 at 18:42:14. |
7
|
|
|
*/ |
8
|
|
|
class AbstractDataMapperTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var AbstractDataMapper |
14
|
|
|
*/ |
15
|
|
|
protected $object; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Sets up the fixture, for example, opens a network connection. |
19
|
|
|
* This method is called before a test is executed. |
20
|
|
|
*/ |
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->object = $this->getMockBuilder('SimpleORM\AbstractDataMapper') |
24
|
|
|
//->disableOriginalConstructor()//можно отключать |
|
|
|
|
25
|
|
|
// ->setConstructorArgs([ |
26
|
|
|
// $DI, |
27
|
|
|
// $adapter |
28
|
|
|
// ])//в конструктор |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
//->setMethods(null) |
31
|
|
|
->setMethods(['setMappingFields','createEntity']) |
32
|
|
|
//->setMethods(null) //не использовать заглушки методов иначе буде возвращать NULL |
|
|
|
|
33
|
|
|
->getMock(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Tears down the fixture, for example, closes a network connection. |
38
|
|
|
* This method is called after a test is executed. |
39
|
|
|
*/ |
40
|
|
|
protected function tearDown() |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @covers SimpleORM\AbstractDataMapper::AddMappingField |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testAddMappingField_SimpleField(){ |
|
|
|
|
49
|
|
|
|
50
|
|
|
\TestHelper::callMethod($this->object,'addMappingField',['myfield']); |
51
|
|
|
|
52
|
|
|
$correct = [ |
53
|
|
|
'myfield' => [ |
54
|
|
|
'field' => 'myfield' |
55
|
|
|
] |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
//----------------- |
59
|
|
|
$mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->assertEquals($mapping_fields, $correct); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers SimpleORM\AbstractDataMapper::AddMappingField |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function testAddMappingField_FieldAndAlias(){ |
|
|
|
|
68
|
|
|
|
69
|
|
|
\TestHelper::callMethod($this->object,'addMappingField',['myfield','tb_mayfield']); |
70
|
|
|
|
71
|
|
|
$correct = [ |
72
|
|
|
'myfield' => [ |
73
|
|
|
'field' => 'tb_mayfield' |
74
|
|
|
] |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
//----------------- |
78
|
|
|
$mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
|
|
|
79
|
|
|
|
80
|
|
|
$this->assertEquals($mapping_fields, $correct); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @covers SimpleORM\AbstractDataMapper::AddMappingField |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function testAddMappingField_ArrayField(){ |
|
|
|
|
87
|
|
|
|
88
|
|
|
\TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
89
|
|
|
'field' => 'tb_mayfield' |
90
|
|
|
]]); |
91
|
|
|
|
92
|
|
|
$correct = [ |
93
|
|
|
'myfield' => [ |
94
|
|
|
'field' => 'tb_mayfield' |
95
|
|
|
] |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
//----------------- |
99
|
|
|
$mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$this->assertEquals($mapping_fields, $correct); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @covers SimpleORM\AbstractDataMapper::AddMappingField |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function testAddMappingField_PrimaryKey(){ |
|
|
|
|
108
|
|
|
|
109
|
|
|
\TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
110
|
|
|
'field' => 'tb_mayfield', |
111
|
|
|
'primary' => true |
112
|
|
|
]]); |
113
|
|
|
|
114
|
|
|
$correct = [ |
115
|
|
|
'myfield' => [ |
116
|
|
|
'field' => 'tb_mayfield', |
117
|
|
|
'primary' => true |
118
|
|
|
] |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
//----------------- |
122
|
|
|
$mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$this->assertEquals($mapping_fields, $correct); |
125
|
|
|
|
126
|
|
|
$key_field = \TestHelper::getProtectedAttribute($this->object,'key'); |
|
|
|
|
127
|
|
|
$this->assertEquals($key_field, 'tb_mayfield'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @covers SimpleORM\AbstractDataMapper::AddMappingField |
132
|
|
|
*/ |
133
|
|
View Code Duplication |
public function testAddMappingField_SoftDelete(){ |
|
|
|
|
134
|
|
|
|
135
|
|
|
\TestHelper::callMethod($this->object,'addMappingField',['myfield',[ |
136
|
|
|
'field' => 'tb_mayfield', |
137
|
|
|
'softdelete' => true |
138
|
|
|
]]); |
139
|
|
|
|
140
|
|
|
$correct = [ |
141
|
|
|
'myfield' => [ |
142
|
|
|
'field' => 'tb_mayfield', |
143
|
|
|
'softdelete' => true |
144
|
|
|
] |
145
|
|
|
]; |
146
|
|
|
|
147
|
|
|
//----------------- |
148
|
|
|
$mapping_fields = \TestHelper::getProtectedAttribute($this->object,'mapping_fields'); |
|
|
|
|
149
|
|
|
|
150
|
|
|
$this->assertEquals($mapping_fields, $correct); |
151
|
|
|
|
152
|
|
|
$soft_delete_key = \TestHelper::getProtectedAttribute($this->object,'soft_delete_key'); |
|
|
|
|
153
|
|
|
$this->assertEquals($soft_delete_key, 'tb_mayfield'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @covers SimpleORM\AbstractDataMapper::getAdapter |
158
|
|
|
* @todo Implement testGetAdapter(). |
159
|
|
|
*/ |
160
|
|
|
public function testGetAdapter() |
161
|
|
|
{ |
162
|
|
|
// Remove the following lines when you implement this test. |
163
|
|
|
$this->markTestIncomplete( |
164
|
|
|
'This test has not been implemented yet.' |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @covers SimpleORM\AbstractDataMapper::setAdapter |
170
|
|
|
* @todo Implement testSetAdapter(). |
171
|
|
|
*/ |
172
|
|
|
public function testSetAdapter() |
173
|
|
|
{ |
174
|
|
|
// Remove the following lines when you implement this test. |
175
|
|
|
$this->markTestIncomplete( |
176
|
|
|
'This test has not been implemented yet.' |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @covers SimpleORM\AbstractDataMapper::findById |
182
|
|
|
* @todo Implement testFindById(). |
183
|
|
|
*/ |
184
|
|
|
public function testFindById() |
185
|
|
|
{ |
186
|
|
|
// Remove the following lines when you implement this test. |
187
|
|
|
$this->markTestIncomplete( |
188
|
|
|
'This test has not been implemented yet.' |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @covers SimpleORM\AbstractDataMapper::save |
194
|
|
|
* @todo Implement testSave(). |
195
|
|
|
*/ |
196
|
|
|
public function testSave() |
197
|
|
|
{ |
198
|
|
|
// Remove the following lines when you implement this test. |
199
|
|
|
$this->markTestIncomplete( |
200
|
|
|
'This test has not been implemented yet.' |
201
|
|
|
); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @covers SimpleORM\AbstractDataMapper::getFieldAlias |
206
|
|
|
* @todo Implement testGetFieldAlias(). |
207
|
|
|
*/ |
208
|
|
|
public function testGetFieldAlias() |
209
|
|
|
{ |
210
|
|
|
// Remove the following lines when you implement this test. |
211
|
|
|
$this->markTestIncomplete( |
212
|
|
|
'This test has not been implemented yet.' |
213
|
|
|
); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @covers SimpleORM\AbstractDataMapper::findBySpecification |
218
|
|
|
* @todo Implement testFindBySpecification(). |
219
|
|
|
*/ |
220
|
|
|
public function testFindBySpecification() |
221
|
|
|
{ |
222
|
|
|
// Remove the following lines when you implement this test. |
223
|
|
|
$this->markTestIncomplete( |
224
|
|
|
'This test has not been implemented yet.' |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @covers SimpleORM\AbstractDataMapper::delete |
230
|
|
|
* @todo Implement testDelete(). |
231
|
|
|
*/ |
232
|
|
|
public function testDelete() |
233
|
|
|
{ |
234
|
|
|
// Remove the following lines when you implement this test. |
235
|
|
|
$this->markTestIncomplete( |
236
|
|
|
'This test has not been implemented yet.' |
237
|
|
|
); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @covers SimpleORM\AbstractDataMapper::findAllBySpecification |
242
|
|
|
* @todo Implement testFindAllBySpecification(). |
243
|
|
|
*/ |
244
|
|
|
public function testFindAllBySpecification() |
245
|
|
|
{ |
246
|
|
|
// Remove the following lines when you implement this test. |
247
|
|
|
$this->markTestIncomplete( |
248
|
|
|
'This test has not been implemented yet.' |
249
|
|
|
); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @covers SimpleORM\AbstractDataMapper::findAll |
254
|
|
|
* @todo Implement testFindAll(). |
255
|
|
|
*/ |
256
|
|
|
public function testFindAll() |
257
|
|
|
{ |
258
|
|
|
// Remove the following lines when you implement this test. |
259
|
|
|
$this->markTestIncomplete( |
260
|
|
|
'This test has not been implemented yet.' |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @covers SimpleORM\AbstractDataMapper::useJoins |
266
|
|
|
* @todo Implement testUseJoins(). |
267
|
|
|
*/ |
268
|
|
|
public function testUseJoins() |
269
|
|
|
{ |
270
|
|
|
// Remove the following lines when you implement this test. |
271
|
|
|
$this->markTestIncomplete( |
272
|
|
|
'This test has not been implemented yet.' |
273
|
|
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @covers SimpleORM\AbstractDataMapper::withDelete |
278
|
|
|
* @todo Implement testWithDelete(). |
279
|
|
|
*/ |
280
|
|
|
public function testWithDelete() |
281
|
|
|
{ |
282
|
|
|
// Remove the following lines when you implement this test. |
283
|
|
|
$this->markTestIncomplete( |
284
|
|
|
'This test has not been implemented yet.' |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.