22
33namespace DeepCopyTest ;
44
5+ use DateInterval ;
56use DateTime ;
67use DateTimeImmutable ;
78use DateTimeZone ;
1314use DeepCopy \f004 ;
1415use DeepCopy \f005 ;
1516use DeepCopy \f006 ;
17+ use DeepCopy \f007 ;
1618use DeepCopy \f008 ;
1719use DeepCopy \Filter \KeepFilter ;
1820use DeepCopy \Filter \SetNullFilter ;
@@ -136,6 +138,7 @@ public function test_it_copies_dynamic_properties()
136138 /**
137139 * @ticket https://github.com/myclabs/DeepCopy/issues/38
138140 * @ticket https://github.com/myclabs/DeepCopy/pull/70
141+ * @ticket https://github.com/myclabs/DeepCopy/pull/76
139142 */
140143 public function test_it_can_copy_an_object_with_a_date_object_property ()
141144 {
@@ -144,26 +147,54 @@ public function test_it_can_copy_an_object_with_a_date_object_property()
144147 $ object ->d1 = new DateTime ();
145148 $ object ->d2 = new DateTimeImmutable ();
146149 $ object ->dtz = new DateTimeZone ('UTC ' );
150+ $ object ->di = new DateInterval ('P2D ' );
147151
148152 $ copy = deep_copy ($ object );
149153
150154 $ this ->assertEqualButNotSame ($ object ->d1 , $ copy ->d1 );
151155 $ this ->assertEqualButNotSame ($ object ->d2 , $ copy ->d2 );
152156 $ this ->assertEqualButNotSame ($ object ->dtz , $ copy ->dtz );
157+ $ this ->assertEqualButNotSame ($ object ->di , $ copy ->di );
153158 }
154159
155160 /**
156- * @ticket https://github.com/myclabs/DeepCopy/pull/70g
161+ * @ticket https://github.com/myclabs/DeepCopy/pull/70
157162 */
158- public function test_it_does_not_skip_the_copy_for_userland_datetimezone ()
163+ public function test_it_skips_the_copy_for_userland_datetimezone ()
159164 {
165+ $ deepCopy = new DeepCopy ();
166+ $ deepCopy ->addFilter (
167+ new SetNullFilter (),
168+ new PropertyNameMatcher ('cloned ' )
169+ );
170+
160171 $ object = new stdClass ();
161172
162- $ object ->dtz = new DateTimeZone ('UTC ' );
173+ $ object ->dtz = new f007 \ FooDateTimeZone ('UTC ' );
163174
164- $ copy = deep_copy ($ object );
175+ $ copy = $ deepCopy -> copy ($ object );
165176
166- $ this ->assertEqualButNotSame ($ object ->dtz , $ copy ->dtz );
177+ $ this ->assertTrue ($ copy ->dtz ->cloned );
178+ }
179+
180+ /**
181+ * @ticket https://github.com/myclabs/DeepCopy/pull/76
182+ */
183+ public function test_it_skips_the_copy_for_userland_dateinterval ()
184+ {
185+ $ deepCopy = new DeepCopy ();
186+ $ deepCopy ->addFilter (
187+ new SetNullFilter (),
188+ new PropertyNameMatcher ('cloned ' )
189+ );
190+
191+ $ object = new stdClass ();
192+
193+ $ object ->di = new f007 \FooDateInterval ('P2D ' );
194+
195+ $ copy = $ deepCopy ->copy ($ object );
196+
197+ $ this ->assertFalse ($ copy ->di ->cloned );
167198 }
168199
169200 public function test_it_copies_the_private_properties_of_the_parent_class ()
0 commit comments