3
3
4
4
use Codeception \Specify \Config ;
5
5
use Codeception \Specify \ConfigBuilder ;
6
- use Codeception \Specify \ObjectProperty ;
7
6
8
- trait Specify
9
- {
7
+ trait Specify {
10
8
11
9
private $ beforeSpecify = array ();
12
10
private $ afterSpecify = array ();
@@ -29,7 +27,7 @@ private function specifyInit()
29
27
if (!$ this ->specifyConfig ) $ this ->specifyConfig = Config::create ();
30
28
}
31
29
32
- function specify ($ specification , \Closure $ callable = null , $ params = [])
30
+ function specify ($ specification , \Closure $ callable = null , $ params = [])
33
31
{
34
32
if (!$ callable ) return ;
35
33
$ this ->specifyInit ();
@@ -40,7 +38,7 @@ function specify($specification, \Closure $callable = null, $params = [])
40
38
41
39
$ this ->setName ($ newName );
42
40
43
- $ properties = $ this -> getSpecifyObjectProperties ( );
41
+ $ properties = get_object_vars ( $ this );
44
42
45
43
// prepare for execution
46
44
$ throws = $ this ->getSpecifyExpectedException ($ params );
@@ -60,12 +58,13 @@ function specify($specification, \Closure $callable = null, $params = [])
60
58
if ($ closure instanceof \Closure) $ closure ->__invoke ();
61
59
}
62
60
}
63
-
64
61
$ this ->specifyExecute ($ test , $ throws , $ example );
65
62
66
63
// restore object properties
67
- $ this ->specifyRestoreProperties ($ properties );
68
-
64
+ foreach ($ properties as $ property => $ val ) {
65
+ if ($ this ->specifyConfig ->propertyIgnored ($ property )) continue ;
66
+ $ this ->$ property = $ val ;
67
+ }
69
68
if (!empty ($ this ->afterSpecify ) && is_array ($ this ->afterSpecify )) {
70
69
foreach ($ this ->afterSpecify as $ closure ) {
71
70
if ($ closure instanceof \Closure) $ closure ->__invoke ();
@@ -121,10 +120,8 @@ private function specifyExecute($test, $throws = false, $examples = array())
121
120
}
122
121
123
122
$ result = $ this ->getTestResultObject ();
124
-
125
123
try {
126
124
call_user_func_array ($ test , $ examples );
127
- $ this ->specifyCheckMockObjects ();
128
125
} catch (\PHPUnit_Framework_AssertionFailedError $ e ) {
129
126
if ($ throws !== get_class ($ e )){
130
127
$ result ->addFailure (clone ($ this ), $ e , $ result ->time ());
@@ -182,86 +179,29 @@ function cleanSpecify()
182
179
}
183
180
184
181
/**
185
- * @param ObjectProperty[] $properties
182
+ * @param $properties
183
+ * @return array
186
184
*/
187
185
private function specifyCloneProperties ($ properties )
188
186
{
189
- foreach ($ properties as $ property ) {
190
- $ propertyName = $ property -> getName ();
191
- $ propertyValue = $ property -> getValue () ;
192
-
193
- if ($ this ->specifyConfig ->classIgnored ($ propertyValue )) {
187
+ foreach ($ properties as $ property => $ val ) {
188
+ if ( $ this -> specifyConfig -> propertyIgnored ( $ property )) {
189
+ continue ;
190
+ }
191
+ if ($ this ->specifyConfig ->classIgnored ($ val )) {
194
192
continue ;
195
193
}
196
194
197
- if ($ this ->specifyConfig ->propertyIsShallowCloned ($ propertyName )) {
198
- if (is_object ($ propertyValue )) {
199
- $ property -> setValue ( clone $ propertyValue ) ;
195
+ if ($ this ->specifyConfig ->propertyIsShallowCloned ($ property )) {
196
+ if (is_object ($ val )) {
197
+ $ this -> $ property = clone $ val ;
200
198
} else {
201
- $ property -> setValue ( $ propertyValue ) ;
199
+ $ this -> $ property = $ val ;
202
200
}
203
201
}
204
-
205
- if ($ this ->specifyConfig ->propertyIsDeeplyCloned ($ propertyName )) {
206
- $ property ->setValue ($ this ->copier ->copy ($ propertyValue ));
202
+ if ($ this ->specifyConfig ->propertyIsDeeplyCloned ($ property )) {
203
+ $ this ->$ property = $ this ->copier ->copy ($ val );
207
204
}
208
205
}
209
206
}
210
-
211
- /**
212
- * @param ObjectProperty[] $properties
213
- */
214
- private function specifyRestoreProperties ($ properties )
215
- {
216
- foreach ($ properties as $ property ) {
217
- $ property ->restoreValue ();
218
- }
219
- }
220
-
221
- /**
222
- * @return ObjectProperty[]
223
- */
224
- private function getSpecifyObjectProperties ()
225
- {
226
- $ properties = [];
227
-
228
- foreach (get_object_vars ($ this ) as $ property => $ value ) {
229
- if ($ this ->specifyConfig ->propertyIgnored ($ property )) {
230
- continue ;
231
- }
232
-
233
- $ properties [] = new ObjectProperty ($ this , $ property , $ value );
234
- }
235
-
236
- // isolate mockObjects property from PHPUnit_Framework_TestCase
237
- if (($ phpUnitReflection = $ this ->specifyGetPhpUnitReflection ()) !== null ) {
238
- $ properties [] = $ mockObjects = new ObjectProperty (
239
- $ this , $ phpUnitReflection ->getProperty ('mockObjects ' )
240
- );
241
-
242
- // remove all mock objects inherited from parent scope(s)
243
- $ mockObjects ->setValue ([]);
244
- }
245
-
246
- return $ properties ;
247
- }
248
-
249
- private function specifyCheckMockObjects ()
250
- {
251
- if (($ phpUnitReflection = $ this ->specifyGetPhpUnitReflection ()) !== null ) {
252
- $ verifyMockObjects = $ phpUnitReflection ->getMethod ('verifyMockObjects ' );
253
- $ verifyMockObjects ->setAccessible (true );
254
- $ verifyMockObjects ->invoke ($ this );
255
- }
256
- }
257
-
258
- /**
259
- * @return \ReflectionClass|null
260
- */
261
- private function specifyGetPhpUnitReflection ()
262
- {
263
- if ($ this instanceof \PHPUnit_Framework_TestCase) {
264
- return new \ReflectionClass ('\PHPUnit_Framework_TestCase ' );
265
- }
266
- }
267
207
}
0 commit comments