$results = array($tiS->greatestExactUnit('short'), $tiMin->greatestExactUnit('short'), $tiH->greatestExactUnit('short'), $tiD->greatestExactUnit('short'), $tiW->greatestExactUnit('short'), $tiM->greatestExactUnit('short'), $tiY->greatestExactUnit('short'), $tiCase1->greatestExactUnit('long'), $tiCase2->greatestExactUnit('long'), $tiCase3->greatestExactUnit('long')); return $results == $expected; }; $unitTests['All Units in All Formats Present'] = function () { $expected = array('short' => array('s', 'm', 'h', 'd', 'w', 'M', 'y'), 'abbrev' => array('secs.', 'mins.', 'hours', 'days', 'weeks', 'months', 'years'), 'long' => array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years')); foreach (array('short', 'abbrev', 'long') as $format) { if (SimpleTimeInterval::units($format) != $expected[$format]) { return false; } } return true; }; $unitTests['Singularize Units'] = function () { $expected = array('short' => array('s', 'm', 'h', 'd', 'w', 'M', 'y'), 'abbrev' => array('sec.', 'min.', 'hour', 'day', 'week', 'month', 'year'), 'long' => array('second', 'minute', 'hour', 'day', 'week', 'month', 'year')); foreach (array('short', 'abbrev', 'long') as $format) { $singular_units = array_map(array('SimpleTimeInterval', 'singularize'), SimpleTimeInterval::units($format)); if ($singular_units != $expected[$format]) { return false; } } return true; }; $passedCount = 0; foreach ($unitTests as $name => $test) { $testResult = call_user_func($test); echo $name . ' Test ... ' . ($testResult ? 'passed' : 'failed') . PHP_EOL; if ($testResult) { $passedCount++; } } echo '---' . PHP_EOL;