From 68cf006888b39945ec03446d9eba4e90e480dfd5 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 13 Jun 2017 23:24:37 +0200 Subject: [PATCH] add some tests --- test/ActiveRecordWriteTest.php | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/ActiveRecordWriteTest.php b/test/ActiveRecordWriteTest.php index c0351413d..c84d6dbe1 100644 --- a/test/ActiveRecordWriteTest.php +++ b/test/ActiveRecordWriteTest.php @@ -441,4 +441,46 @@ public function test_update_our_datetime() $this->assert_true($our_datetime === $author->some_date); } + public function test_touch() + { + $author = Author::create(array('name' => 'MC Hammer')); + $updated_at = $author->updated_at = new DateTime('yesterday'); + $author->save(); + $author->touch(); + $this->assertGreaterThan($updated_at, $author->updated_at); + } + + /** + * @expectedException ActiveRecord\ActiveRecordException + * @expectedExceptionMessage Cannot touch on a new record object + */ + public function test_touch_on_new_record() + { + $author = new Author(array('name' => 'MC Hammer')); + $author->touch(); + } + + public function test_touch_with_additional_keys() + { + $author = Author::create(array('name' => 'MC Hammer')); + $updated_at = $author->updated_at = new DateTime('yesterday'); + $some_date = $author->some_date = new DateTime('yesterday'); + $author->save(); + $author->touch(array('some_date')); + $this->assertGreaterThan($updated_at, $author->updated_at); + $this->assertGreaterThan($some_date, $author->some_date); + } + + public function test_touch_with_scalar() + { + $author = Author::create(array('name' => 'MC Hammer')); + $updated_at = $author->updated_at = new DateTime('yesterday'); + $some_date = $author->some_date = new DateTime('yesterday'); + $author->save(); + $author->touch('some_date'); + $this->assertGreaterThan($updated_at, $author->updated_at); + $this->assertGreaterThan($some_date, $author->some_date); + } + + }