File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace DeepCopy \f007 ;
4
+
5
+ use DateTimeZone ;
6
+
7
+ class FooDateTimeZone extends DateTimeZone
8
+ {
9
+ public $ cloned = false ;
10
+
11
+ public function __clone ()
12
+ {
13
+ $ this ->cloned = true ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change 3
3
namespace DeepCopy ;
4
4
5
5
use DateTimeInterface ;
6
+ use DateTimeZone ;
6
7
use DeepCopy \Exception \CloneException ;
7
8
use DeepCopy \Filter \Filter ;
8
9
use DeepCopy \Matcher \Matcher ;
9
- use DeepCopy \TypeFilter \Spl \SplDoublyLinkedList ;
10
+ use DeepCopy \TypeFilter \Spl \SplDoublyLinkedListFilter ;
10
11
use DeepCopy \TypeFilter \TypeFilter ;
11
12
use DeepCopy \TypeMatcher \TypeMatcher ;
12
13
use ReflectionObject ;
13
14
use ReflectionProperty ;
14
15
use DeepCopy \Reflection \ReflectionHelper ;
16
+ use SplDoublyLinkedList ;
15
17
16
18
/**
17
19
* @final
@@ -55,7 +57,7 @@ public function __construct($useCloneMethod = false)
55
57
{
56
58
$ this ->useCloneMethod = $ useCloneMethod ;
57
59
58
- $ this ->addTypeFilter (new SplDoublyLinkedList ($ this ), new TypeMatcher (' SplDoublyLinkedList ' ));
60
+ $ this ->addTypeFilter (new SplDoublyLinkedListFilter ($ this ), new TypeMatcher (SplDoublyLinkedList::class ));
59
61
}
60
62
61
63
/**
@@ -184,7 +186,7 @@ private function copyObject($object)
184
186
return $ newObject ;
185
187
}
186
188
187
- if ($ newObject instanceof DateTimeInterface) {
189
+ if ($ newObject instanceof DateTimeInterface || get_class ( $ newObject ) === DateTimeZone::class ) {
188
190
return $ newObject ;
189
191
}
190
192
Original file line number Diff line number Diff line change 4
4
5
5
use DateTime ;
6
6
use DateTimeImmutable ;
7
+ use DateTimeZone ;
7
8
use DeepCopy \DeepCopy ;
8
9
use DeepCopy \Exception \CloneException ;
9
10
use DeepCopy \f001 ;
@@ -132,18 +133,35 @@ public function test_dynamic_properties_are_copied()
132
133
133
134
/**
134
135
* @ticket https://github.com/myclabs/DeepCopy/issues/38
136
+ * @ticket https://github.com/myclabs/DeepCopy/pull/70
135
137
*/
136
138
public function test_it_can_copy_an_object_with_a_date_object_property ()
137
139
{
138
140
$ object = new stdClass ();
139
141
140
142
$ object ->d1 = new DateTime ();
141
143
$ object ->d2 = new DateTimeImmutable ();
144
+ $ object ->dtz = new DateTimeZone ('UTC ' );
142
145
143
146
$ copy = deep_copy ($ object );
144
147
145
148
$ this ->assertEqualButNotSame ($ object ->d1 , $ copy ->d1 );
146
149
$ this ->assertEqualButNotSame ($ object ->d2 , $ copy ->d2 );
150
+ $ this ->assertEqualButNotSame ($ object ->dtz , $ copy ->dtz );
151
+ }
152
+
153
+ /**
154
+ * @ticket https://github.com/myclabs/DeepCopy/pull/70g
155
+ */
156
+ public function test_it_does_not_skip_the_copy_for_userland_datetimezone ()
157
+ {
158
+ $ object = new stdClass ();
159
+
160
+ $ object ->dtz = new DateTimeZone ('UTC ' );
161
+
162
+ $ copy = deep_copy ($ object );
163
+
164
+ $ this ->assertEqualButNotSame ($ object ->dtz , $ copy ->dtz );
147
165
}
148
166
149
167
public function test_it_copies_the_private_properties_of_the_parent_class ()
You can’t perform that action at this time.
0 commit comments