Skip to content

Commit

Permalink
Written sample unit test using simpletest
Browse files Browse the repository at this point in the history
  • Loading branch information
morshedalam committed Feb 29, 2012
1 parent 5b2faea commit 244ccaf
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions unit_test.php
@@ -0,0 +1,40 @@
<?php

require_once('simpletest/autorun.php');
require_once('date_time_helper.php');

class TestOfDateTimeHelper extends UnitTestCase {

private function printTestInfo($func) {
print ucfirst(preg_replace('/^test /', '',
strtolower(preg_replace('/(?<!\ )[A-Z]/', ' $0', $func))
)) . "<br />";
}

function testTimeDifferenceShouldBeZero() {
$this->printTestInfo(__FUNCTION__);
$helper = new DateTimeHelper();
$this->assertEqual($helper->timeDifference(), new DateInterval('PT0S'));
}

function testTimeDiffAsWordsShouldBeNull() {
$this->printTestInfo(__FUNCTION__);
$helper = new DateTimeHelper();
$this->assertEqual($helper->timeDiffAsWords(), '');
}

function testTimeDiffAsWordsShouldBeLessThanAMinute() {
$this->printTestInfo(__FUNCTION__);
$helper = new DateTimeHelper();
$this->assertEqual($helper->timeDiffAsWords(date('Y-m-d H:i:s')), 'less than a minute ago');
}

function testTimeDiffAsWordsShouldBeAboutOneHour() {
$this->printTestInfo(__FUNCTION__);
$helper = new DateTimeHelper();
$this->assertEqual($helper->timeDiffAsWords('2012-02-01 10:00:10', '2012-02-01 11:00:01'), 'about an hour ago');
}

}

?>

0 comments on commit 244ccaf

Please sign in to comment.