Passed
Push — master ( 3e0ba1...df5150 )
by El
20:25 queued 10:25
created

tst/filter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class filterTest extends PHPUnit_Framework_TestCase
3
{
4
    public function testFilterStripsSlashesDeeply()
5
    {
6
        $this->assertEquals(
7
            array("f'oo", "b'ar", array("fo'o", "b'ar")),
8
            filter::stripslashes_deep(array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")))
9
        );
10
    }
11
12
    public function testFilterMakesTimesHumanlyReadable()
13
    {
14
        $this->assertEquals('5 minutes', filter::time_humanreadable('5min'));
15
        $this->assertEquals('90 seconds', filter::time_humanreadable('90sec'));
16
        $this->assertEquals('1 week', filter::time_humanreadable('1week'));
17
        $this->assertEquals('6 months', filter::time_humanreadable('6months'));
18
    }
19
20
    /**
21
     * @expectedException Exception
22
     * @expectedExceptionCode 30
23
     */
24
    public function testFilterFailTimesHumanlyReadable()
25
    {
26
        filter::time_humanreadable('five_minutes');
27
    }
28
29
    public function testFilterMakesSizesHumanlyReadable()
30
    {
31
        $this->assertEquals('1 B', filter::size_humanreadable(1));
32
        $this->assertEquals('1 000 B', filter::size_humanreadable(1000));
33
        $this->assertEquals('1.00 KiB', filter::size_humanreadable(1024));
34
        $this->assertEquals('1.21 KiB', filter::size_humanreadable(1234));
35
        $exponent = 1024;
36
        $this->assertEquals('1 000.00 KiB', filter::size_humanreadable(1000 * $exponent));
37
        $this->assertEquals('1.00 MiB', filter::size_humanreadable(1024 * $exponent));
38
        $this->assertEquals('1.21 MiB', filter::size_humanreadable(1234 * $exponent));
39
        $exponent *= 1024;
40
        $this->assertEquals('1 000.00 MiB', filter::size_humanreadable(1000 * $exponent));
41
        $this->assertEquals('1.00 GiB', filter::size_humanreadable(1024 * $exponent));
42
        $this->assertEquals('1.21 GiB', filter::size_humanreadable(1234 * $exponent));
43
        $exponent *= 1024;
44
        $this->assertEquals('1 000.00 GiB', filter::size_humanreadable(1000 * $exponent));
45
        $this->assertEquals('1.00 TiB', filter::size_humanreadable(1024 * $exponent));
46
        $this->assertEquals('1.21 TiB', filter::size_humanreadable(1234 * $exponent));
47
        $exponent *= 1024;
48
        $this->assertEquals('1 000.00 TiB', filter::size_humanreadable(1000 * $exponent));
49
        $this->assertEquals('1.00 PiB', filter::size_humanreadable(1024 * $exponent));
50
        $this->assertEquals('1.21 PiB', filter::size_humanreadable(1234 * $exponent));
51
        $exponent *= 1024;
52
        $this->assertEquals('1 000.00 PiB', filter::size_humanreadable(1000 * $exponent));
53
        $this->assertEquals('1.00 EiB', filter::size_humanreadable(1024 * $exponent));
54
        $this->assertEquals('1.21 EiB', filter::size_humanreadable(1234 * $exponent));
55
        $exponent *= 1024;
56
        $this->assertEquals('1 000.00 EiB', filter::size_humanreadable(1000 * $exponent));
57
        $this->assertEquals('1.00 ZiB', filter::size_humanreadable(1024 * $exponent));
58
        $this->assertEquals('1.21 ZiB', filter::size_humanreadable(1234 * $exponent));
59
        $exponent *= 1024;
60
        $this->assertEquals('1 000.00 ZiB', filter::size_humanreadable(1000 * $exponent));
61
        $this->assertEquals('1.00 YiB', filter::size_humanreadable(1024 * $exponent));
62
        $this->assertEquals('1.21 YiB', filter::size_humanreadable(1234 * $exponent));
63
    }
64
65
    public function testSlowEquals()
66
    {
67
        $this->assertTrue(filter::slow_equals('foo', 'foo'), 'same string');
68
        $this->assertFalse(filter::slow_equals('foo', true), 'string and boolean');
0 ignored issues
show
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        $this->assertFalse(filter::slow_equals('foo', 0), 'string and integer');
70
        $this->assertFalse(filter::slow_equals('123foo', 123), 'string and integer');
71
        $this->assertFalse(filter::slow_equals('123foo', '123'), 'different strings');
72
        $this->assertFalse(filter::slow_equals('6', ' 6'), 'strings with space');
73
        $this->assertFalse(filter::slow_equals('4.2', '4.20'), 'floats as strings');
74
        $this->assertFalse(filter::slow_equals('1e3', '1000'), 'integers as strings');
75
        $this->assertFalse(filter::slow_equals('9223372036854775807', '9223372036854775808'), 'large integers as strings');
76
        $this->assertFalse(filter::slow_equals('61529519452809720693702583126814', '61529519452809720000000000000000'), 'larger integers as strings');
77
    }
78
}
79