Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Jun 13, 2017
1 parent b7ee409 commit 68cf006
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/ActiveRecordWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


}

0 comments on commit 68cf006

Please sign in to comment.