@@ -441,4 +441,46 @@ public function test_update_our_datetime()
441441 $ this ->assert_true ($ our_datetime === $ author ->some_date );
442442 }
443443
444+ public function test_touch ()
445+ {
446+ $ author = Author::create (array ('name ' => 'MC Hammer ' ));
447+ $ updated_at = $ author ->updated_at = new DateTime ('yesterday ' );
448+ $ author ->save ();
449+ $ author ->touch ();
450+ $ this ->assertGreaterThan ($ updated_at , $ author ->updated_at );
451+ }
452+
453+ /**
454+ * @expectedException ActiveRecord\ActiveRecordException
455+ * @expectedExceptionMessage Cannot touch on a new record object
456+ */
457+ public function test_touch_on_new_record ()
458+ {
459+ $ author = new Author (array ('name ' => 'MC Hammer ' ));
460+ $ author ->touch ();
461+ }
462+
463+ public function test_touch_with_additional_keys ()
464+ {
465+ $ author = Author::create (array ('name ' => 'MC Hammer ' ));
466+ $ updated_at = $ author ->updated_at = new DateTime ('yesterday ' );
467+ $ some_date = $ author ->some_date = new DateTime ('yesterday ' );
468+ $ author ->save ();
469+ $ author ->touch (array ('some_date ' ));
470+ $ this ->assertGreaterThan ($ updated_at , $ author ->updated_at );
471+ $ this ->assertGreaterThan ($ some_date , $ author ->some_date );
472+ }
473+
474+ public function test_touch_with_scalar ()
475+ {
476+ $ author = Author::create (array ('name ' => 'MC Hammer ' ));
477+ $ updated_at = $ author ->updated_at = new DateTime ('yesterday ' );
478+ $ some_date = $ author ->some_date = new DateTime ('yesterday ' );
479+ $ author ->save ();
480+ $ author ->touch ('some_date ' );
481+ $ this ->assertGreaterThan ($ updated_at , $ author ->updated_at );
482+ $ this ->assertGreaterThan ($ some_date , $ author ->some_date );
483+ }
484+
485+
444486}
0 commit comments