File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -223,10 +223,16 @@ private function specifyRestoreProperties($properties)
223
223
*/
224
224
private function getSpecifyObjectProperties ()
225
225
{
226
+ $ objectReflection = new \ReflectionObject ($ this );
227
+ $ propertiesToClone = $ objectReflection ->getProperties ();
228
+
229
+ if (($ classProperties = $ this ->specifyGetClassPrivateProperties ()) !== []) {
230
+ $ propertiesToClone = array_merge ($ propertiesToClone , $ classProperties );
231
+ }
232
+
226
233
$ properties = [];
227
- $ myReflection = new \ReflectionObject ($ this );
228
234
229
- foreach ($ myReflection -> getProperties () as $ property ) {
235
+ foreach ($ propertiesToClone as $ property ) {
230
236
if ($ this ->specifyConfig ->propertyIgnored ($ property ->getName ())) {
231
237
continue ;
232
238
}
@@ -256,6 +262,20 @@ private function specifyCheckMockObjects()
256
262
}
257
263
}
258
264
265
+ private function specifyGetClassPrivateProperties ()
266
+ {
267
+ static $ properties = [];
268
+
269
+ if (!isset ($ properties [__CLASS__ ])) {
270
+ $ reflection = new \ReflectionClass (__CLASS__ );
271
+
272
+ $ properties [__CLASS__ ] = (get_class ($ this ) !== __CLASS__ )
273
+ ? $ reflection ->getProperties (\ReflectionProperty::IS_PRIVATE ) : [];
274
+ }
275
+
276
+ return $ properties [__CLASS__ ];
277
+ }
278
+
259
279
/**
260
280
* @return \ReflectionClass|null
261
281
*/
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ class SpecifyTest extends \SpecifyUnitTest
4
4
{
5
5
protected $ user ;
6
6
protected $ a ;
7
- protected $ private = false ;
7
+
8
+ private $ private = false ;
8
9
9
10
public function testSpecification ()
10
11
{
@@ -231,12 +232,16 @@ function testPropertyRestore()
231
232
232
233
$ this ->assertEquals (['hello ' , 'world ' ], $ this ->testOne ->prop );
233
234
$ this ->assertFalse ($ this ->private );
235
+ $ this ->assertTrue ($ this ->getPrivateProperty ());
234
236
235
237
$ this ->specify ('property $private should be restored properly ' , function () {
236
238
$ this ->private = 'i \'m protected ' ;
239
+ $ this ->setPrivateProperty ('i \'m private ' );
240
+ $ this ->assertEquals ('i \'m private ' , $ this ->getPrivateProperty ());
237
241
});
238
242
239
243
$ this ->assertFalse ($ this ->private );
244
+ $ this ->assertTrue ($ this ->getPrivateProperty ());
240
245
}
241
246
242
247
public function testExamplesIndexInName ()
Original file line number Diff line number Diff line change @@ -5,4 +5,19 @@ class SpecifyUnitTest extends \PHPUnit_Framework_TestCase
5
5
use Codeception \Specify;
6
6
7
7
private $ private = true ;
8
+
9
+ /**
10
+ * @param mixed $private
11
+ */
12
+ protected function setPrivateProperty ($ private )
13
+ {
14
+ $ this ->private = $ private ;
15
+ }
16
+ /**
17
+ * @return mixed
18
+ */
19
+ protected function getPrivateProperty ()
20
+ {
21
+ return $ this ->private ;
22
+ }
8
23
}
You can’t perform that action at this time.
0 commit comments