I am trying to write tests for a date helper class. I am wondering what is best practice for this.
Here is an example in PHP.
public static function get_date($offset = 0){
$date = mktime(0, 0, 0, date('m') , date('d') + $offset, date('Y'));
return array(
'day' => date('D',$date),
'month' => date('M',$date),
'year' => date('Y',$date)
);
}
public static function today(){
return self::get_date();
}
public static function tomorrow(){
return self::get_date(1);
}
public static function yesterday(){
return self::get_date(-1);
}
So what I am looking for is examples of tests that could test these functions or a new way to write these functions so they are intuitively testable.
I have found examples in Java but they seem pretty inelegant and I really don't know Java, unless you count Actionscript 3 as Java ;)
Solutions in Javascript or Ruby would also be super helpful as examples but my class is written in PHP so that would be ideal.
Thanks!