File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 10
10
- ' 7.1'
11
11
- ' 7.2'
12
12
- ' 7.3'
13
+ - ' 7.4'
13
14
- nightly
14
15
15
16
matrix :
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace DeepCopy \f009 ;
4
+
5
+ class TypedProperty
6
+ {
7
+ public int $ foo ;
8
+ }
Original file line number Diff line number Diff line change @@ -237,6 +237,12 @@ function ($object) {
237
237
}
238
238
239
239
$ property ->setAccessible (true );
240
+
241
+ // Ignore uninitialized properties (for PHP >7.4)
242
+ if (method_exists ($ property , 'isInitialized ' ) && !$ property ->isInitialized ($ object )) {
243
+ return ;
244
+ }
245
+
240
246
$ propertyValue = $ property ->getValue ($ object );
241
247
242
248
// Copy the property
Original file line number Diff line number Diff line change 16
16
use DeepCopy \f006 ;
17
17
use DeepCopy \f007 ;
18
18
use DeepCopy \f008 ;
19
+ use DeepCopy \f009 ;
19
20
use DeepCopy \Filter \KeepFilter ;
20
21
use DeepCopy \Filter \SetNullFilter ;
21
22
use DeepCopy \Matcher \PropertyNameMatcher ;
@@ -434,6 +435,35 @@ public function test_it_can_prepend_filter()
434
435
$ this ->assertNull ($ copy ->getFoo ());
435
436
}
436
437
438
+ /**
439
+ * @ticket https://github.com/myclabs/DeepCopy/issues/143
440
+ * @requires PHP 7.4
441
+ */
442
+ public function test_it_clones_typed_properties ()
443
+ {
444
+ $ object = new f009 \TypedProperty ();
445
+ $ object ->foo = 123 ;
446
+
447
+ $ deepCopy = new DeepCopy ();
448
+ $ copy = $ deepCopy ->copy ($ object );
449
+
450
+ $ this ->assertSame (123 , $ copy ->foo );
451
+ }
452
+
453
+ /**
454
+ * @ticket https://github.com/myclabs/DeepCopy/issues/143
455
+ * @requires PHP 7.4
456
+ */
457
+ public function test_it_ignores_uninitialized_typed_properties ()
458
+ {
459
+ $ object = new f009 \TypedProperty ();
460
+
461
+ $ deepCopy = new DeepCopy ();
462
+ $ copy = $ deepCopy ->copy ($ object );
463
+
464
+ $ this ->assertFalse (isset ($ copy ->foo ));
465
+ }
466
+
437
467
private function assertEqualButNotSame ($ expected , $ val )
438
468
{
439
469
$ this ->assertEquals ($ expected , $ val );
You can’t perform that action at this time.
0 commit comments