Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Written sample unit test using simpletest
- Loading branch information
1 parent
5b2faea
commit 244ccaf
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
|
||
} | ||
|
||
?> |