followed Style CI code styke recommendations
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PrivateBin\Filter;
|
||||
use Eris\Generator;
|
||||
use PrivateBin\Filter;
|
||||
|
||||
class FilterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -23,8 +23,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
'sec', 'second', 'seconds'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
function ($int, $unit) {
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' second' . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
@@ -35,8 +34,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
'min', 'minute', 'minutes'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
function ($int, $unit) {
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' minute' . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
@@ -48,8 +46,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
'month', 'months', 'year', 'years'
|
||||
)
|
||||
)->then(
|
||||
function ($int, $unit)
|
||||
{
|
||||
function ($int, $unit) {
|
||||
$suffix = $int === 1 ? '' : 's';
|
||||
$this->assertEquals($int . ' ' . rtrim($unit, 's') . $suffix, Filter::formatHumanReadableTime($int . $unit));
|
||||
}
|
||||
@@ -65,8 +62,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
$this->forAll(
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string)
|
||||
{
|
||||
function ($string) {
|
||||
Filter::formatHumanReadableTime($string);
|
||||
}
|
||||
);
|
||||
@@ -77,85 +73,79 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
$this->forAll(
|
||||
Generator\neg()
|
||||
)->then(
|
||||
function ($int)
|
||||
{
|
||||
function ($int) {
|
||||
$this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = 0;
|
||||
$from = 0;
|
||||
$exponent = 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to)
|
||||
)->then(
|
||||
function ($int)
|
||||
{
|
||||
function ($int) {
|
||||
$this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' KiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' MiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' GiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' TiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' PiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
|
||||
// on 64bit systems, this gets larger then PHP_INT_MAX, so PHP casts it
|
||||
// to double and the "choose" generator can't handle it
|
||||
if ($to > PHP_INT_MAX) {
|
||||
@@ -173,32 +163,29 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' EiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' ZiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
$from = $exponent;
|
||||
$from = $exponent;
|
||||
$exponent *= 1024;
|
||||
$to = $exponent - 1;
|
||||
$to = $exponent - 1;
|
||||
$this->forAll(
|
||||
Generator\choose($from, $to),
|
||||
$from
|
||||
)->then(
|
||||
function ($int, $divisor)
|
||||
{
|
||||
function ($int, $divisor) {
|
||||
$this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' YiB', Filter::formatHumanReadableSize($int));
|
||||
}
|
||||
);
|
||||
@@ -210,40 +197,35 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
$this->forAll(
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string)
|
||||
{
|
||||
function ($string) {
|
||||
$this->assertTrue(Filter::slowEquals($string, $string), 'same string');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\int()
|
||||
)->then(
|
||||
function ($int)
|
||||
{
|
||||
function ($int) {
|
||||
$this->assertTrue(Filter::slowEquals($int, $int), 'same integer');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\float()
|
||||
)->then(
|
||||
function ($float)
|
||||
{
|
||||
function ($float) {
|
||||
$this->assertTrue(Filter::slowEquals($float, $float), 'same float');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string)
|
||||
{
|
||||
function ($string) {
|
||||
$this->assertFalse(Filter::slowEquals($string, true), 'string and boolean true');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string)
|
||||
{
|
||||
function ($string) {
|
||||
// false is casted into an empty string
|
||||
if ($string !== '') {
|
||||
$this->assertFalse(Filter::slowEquals($string, false), 'string and boolean false');
|
||||
@@ -263,8 +245,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
Generator\string(),
|
||||
Generator\float()
|
||||
)->then(
|
||||
function ($string, $float)
|
||||
{
|
||||
function ($string, $float) {
|
||||
$this->assertFalse(Filter::slowEquals($string, $float), 'string and float');
|
||||
}
|
||||
);
|
||||
@@ -272,8 +253,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
Generator\string(),
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string1, $string2)
|
||||
{
|
||||
function ($string1, $string2) {
|
||||
if ($string1 !== $string2) {
|
||||
$this->assertFalse(Filter::slowEquals($string1, $string2), 'different strings');
|
||||
}
|
||||
@@ -282,27 +262,25 @@ class FilterTest extends PHPUnit_Framework_TestCase
|
||||
$this->forAll(
|
||||
Generator\string()
|
||||
)->then(
|
||||
function ($string)
|
||||
{
|
||||
function ($string) {
|
||||
$this->assertFalse(Filter::slowEquals($string, ' ' . $string), 'strings with space');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\float()
|
||||
)->then(
|
||||
function ($float)
|
||||
{
|
||||
function ($float) {
|
||||
$this->assertFalse(Filter::slowEquals(strval($float), $float . '0'), 'floats as strings');
|
||||
}
|
||||
);
|
||||
$this->forAll(
|
||||
Generator\int()
|
||||
)->then(
|
||||
function ($int)
|
||||
{
|
||||
function ($int) {
|
||||
$this->assertFalse(Filter::slowEquals($int . 'e3', $int . '000'), 'integers as strings');
|
||||
}
|
||||
);
|
||||
|
||||
// these two tests would be compared equal if casted to integers as they are larger then PHP_INT_MAX
|
||||
$this->assertFalse(Filter::slowEquals('9223372036854775807', '9223372036854775808'), 'large integers as strings');
|
||||
$this->assertFalse(Filter::slowEquals('61529519452809720693702583126814', '61529519452809720000000000000000'), 'larger integers as strings');
|
||||
|
||||
Reference in New Issue
Block a user