1
1
<?php
2
- use ActiveRecord \DateTime as DateTime ;
3
2
use ActiveRecord \DatabaseException ;
3
+ use ActiveRecord \DateTime as DateTime ;
4
4
5
5
class DateTimeTest extends SnakeCase_PHPUnit_Framework_TestCase
6
6
{
@@ -15,13 +15,20 @@ public function tear_down()
15
15
DateTime::$ DEFAULT_FORMAT = $ this ->original_format ;
16
16
}
17
17
18
- private function assert_dirtifies ( $ method /*, method params, ...*/ )
18
+ private function get_model ( )
19
19
{
20
20
try {
21
21
$ model = new Author ();
22
22
} catch (DatabaseException $ e ) {
23
23
$ this ->mark_test_skipped ('failed to connect. ' .$ e ->getMessage ());
24
24
}
25
+
26
+ return $ model ;
27
+ }
28
+
29
+ private function assert_dirtifies ($ method /*, method params, ...*/ )
30
+ {
31
+ $ model = $ this ->get_model ();
25
32
$ datetime = new DateTime ();
26
33
$ datetime ->attribute_of ($ model ,'some_date ' );
27
34
@@ -153,7 +160,7 @@ public function test_create_from_format_with_tz()
153
160
public function test_native_date_time_attribute_copies_exact_tz ()
154
161
{
155
162
$ dt = new \DateTime (null , new \DateTimeZone ('America/New_York ' ));
156
- $ model = new Author ();
163
+ $ model = $ this -> get_model ();
157
164
158
165
// Test that the data transforms without modification
159
166
$ model ->assign_attribute ('updated_at ' , $ dt );
@@ -167,7 +174,7 @@ public function test_native_date_time_attribute_copies_exact_tz()
167
174
public function test_ar_date_time_attribute_copies_exact_tz ()
168
175
{
169
176
$ dt = new DateTime (null , new \DateTimeZone ('America/New_York ' ));
170
- $ model = new Author ();
177
+ $ model = $ this -> get_model ();
171
178
172
179
// Test that the data transforms without modification
173
180
$ model ->assign_attribute ('updated_at ' , $ dt );
@@ -177,5 +184,33 @@ public function test_ar_date_time_attribute_copies_exact_tz()
177
184
$ this ->assert_equals ($ dt ->getTimeZone (), $ dt2 ->getTimeZone ());
178
185
$ this ->assert_equals ($ dt ->getTimeZone ()->getName (), $ dt2 ->getTimeZone ()->getName ());
179
186
}
187
+
188
+ public function test_clone ()
189
+ {
190
+ $ model = $ this ->get_model ();
191
+ $ model_attribute = 'some_date ' ;
192
+
193
+ $ datetime = new DateTime ();
194
+ $ datetime ->attribute_of ($ model , $ model_attribute );
195
+
196
+ $ cloned_datetime = clone $ datetime ;
197
+
198
+ // Assert initial state
199
+ $ this ->assert_false ($ model ->attribute_is_dirty ($ model_attribute ));
200
+
201
+ $ cloned_datetime ->add (new DateInterval ('PT1S ' ));
202
+
203
+ // Assert that modifying the cloned object didn't flag the model
204
+ $ this ->assert_false ($ model ->attribute_is_dirty ($ model_attribute ));
205
+
206
+ $ datetime ->add (new DateInterval ('PT1S ' ));
207
+
208
+ // Assert that modifying the model-attached object did flag the model
209
+ $ this ->assert_true ($ model ->attribute_is_dirty ($ model_attribute ));
210
+
211
+ // Assert that the dates are equal but not the same instance
212
+ $ this ->assert_equals ($ datetime , $ cloned_datetime );
213
+ $ this ->assert_not_same ($ datetime , $ cloned_datetime );
214
+ }
180
215
}
181
216
?>
0 commit comments