diff --git a/lib/Filter.php b/lib/Filter.php index 60f6f17..d0f1c33 100644 --- a/lib/Filter.php +++ b/lib/Filter.php @@ -39,7 +39,9 @@ class Filter /** * format a given time string into a human readable label (localized) * - * accepts times in the format "[integer][time unit]" + * accepts times in the format "[integer][time unit]", valid time units are: + * sec, second, seconds, min, minute, minutes, hour, hours, day, days, week, + * weeks, month, months, year, years * * @access public * @static diff --git a/tst/FilterTest.php b/tst/FilterTest.php index 63cc8f8..1b40998 100644 --- a/tst/FilterTest.php +++ b/tst/FilterTest.php @@ -1,9 +1,12 @@ assertEquals( @@ -14,10 +17,43 @@ class FilterTest extends PHPUnit_Framework_TestCase public function testFilterMakesTimesHumanlyReadable() { - $this->assertEquals('5 minutes', Filter::formatHumanReadableTime('5min')); - $this->assertEquals('90 seconds', Filter::formatHumanReadableTime('90sec')); - $this->assertEquals('1 week', Filter::formatHumanReadableTime('1week')); - $this->assertEquals('6 months', Filter::formatHumanReadableTime('6months')); + $this->forAll( + Generator\nat(), + Generator\oneOf( + 'sec', 'second', 'seconds' + ) + )->then( + function ($int, $unit) + { + $suffix = $int === 1 ? '' : 's'; + $this->assertEquals($int . ' second' . $suffix, Filter::formatHumanReadableTime($int . $unit)); + } + ); + $this->forAll( + Generator\nat(), + Generator\oneOf( + 'min', 'minute', 'minutes' + ) + )->then( + function ($int, $unit) + { + $suffix = $int === 1 ? '' : 's'; + $this->assertEquals($int . ' minute' . $suffix, Filter::formatHumanReadableTime($int . $unit)); + } + ); + $this->forAll( + Generator\nat(), + Generator\oneOf( + 'hour', 'hours', 'day', 'days', 'week', 'weeks', + 'month', 'months', 'year', 'years' + ) + )->then( + function ($int, $unit) + { + $suffix = $int === 1 ? '' : 's'; + $this->assertEquals($int . ' ' . rtrim($unit, 's') . $suffix, Filter::formatHumanReadableTime($int . $unit)); + } + ); } /** diff --git a/tst/Vizhash16x16Test.php b/tst/Vizhash16x16Test.php index 6a6c8a7..a8db074 100644 --- a/tst/Vizhash16x16Test.php +++ b/tst/Vizhash16x16Test.php @@ -41,16 +41,14 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase $vz = new Vizhash16x16(); $pngdata = $vz->generate($string1); - if (empty($string1)) - { + if (empty($string1)) { $this->assertEquals($pngdata, ''); } else { $this->assertNotEquals($pngdata, ''); file_put_contents($this->_file, $pngdata); $finfo = new finfo(FILEINFO_MIME_TYPE); $this->assertEquals('image/png', $finfo->file($this->_file)); - if ($string1 !== $string2) - { + if ($string1 !== $string2) { $this->assertNotEquals($pngdata, $string2); } } @@ -73,8 +71,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase file_put_contents($this->_file, $pngdata); $finfo = new finfo(FILEINFO_MIME_TYPE); $this->assertEquals('image/png', $finfo->file($this->_file)); - if ($hash1 !== $hash2) - { + if ($hash1 !== $hash2) { $this->assertNotEquals($pngdata, $vz->generate($hash2)); } $this->assertEquals($pngdata, $vz->generate($hash1)); @@ -96,8 +93,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase file_put_contents($this->_file, $pngdata); $finfo = new finfo(FILEINFO_MIME_TYPE); $this->assertEquals('image/png', $finfo->file($this->_file)); - if ($hash1 !== $hash2) - { + if ($hash1 !== $hash2) { $this->assertNotEquals($pngdata, $vz->generate($hash2)); } $this->assertEquals($pngdata, $vz->generate($hash1));