turning Filter::formatHumanReadableTime() test case into property based one, clarifying the allowed units

This commit is contained in:
El RIDO
2017-02-26 12:47:54 +01:00
parent e41f0a7561
commit 79dafd5af4
3 changed files with 47 additions and 13 deletions

View File

@@ -1,9 +1,12 @@
<?php
use PrivateBin\Filter;
use Eris\Generator;
class FilterTest extends PHPUnit_Framework_TestCase
{
use Eris\TestTrait;
public function testFilterStripsSlashesDeeply()
{
$this->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));
}
);
}
/**