Failed Conditions
Pull Request — master (#75)
by
unknown
03:37
created

UrlTest::filter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Filter\Url
9
 */
10
final class UrlTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @covers ::filter
15
     */
16
    public function filter()
17
    {
18
        $url = 'http://www.example.com';
19
        $this->assertSame($url, Url::filter($url));
20
    }
21
22
    /**
23
     * @test
24
     * @expectedException \TraderInteractive\Filter\Exception
25
     * @expectedExceptionMessage Value '1' is not a string
26
     * @covers ::filter
27
     */
28
    public function filterNonstring()
29
    {
30
        Url::filter(1);
31
    }
32
33
    /**
34
     * @test
35
     * @expectedException \TraderInteractive\Filter\Exception
36
     * @expectedExceptionMessage Value 'www.example.com' is not a valid url
37
     * @covers ::filter
38
     */
39
    public function filterNotValid()
40
    {
41
        Url::filter('www.example.com');
42
    }
43
44
    /**
45
     * @test
46
     * @covers ::filter
47
     */
48
    public function filterNullPass()
49
    {
50
        $this->assertSame(null, Url::filter(null, true));
51
    }
52
53
    /**
54
     * @test
55
     * @expectedException Exception
56
     * @expectedExceptionMessage Value 'NULL' is not a string
57
     * @covers ::filter
58
     */
59
    public function filterNullFail()
60
    {
61
        Url::filter(null);
62
    }
63
64
    /**
65
     * @test
66
     * @expectedException InvalidArgumentException
67
     * @expectedExceptionMessage $allowNull was not a boolean value
68
     * @covers ::filter
69
     */
70
    public function filterAllowNullNotBoolean()
71
    {
72
        Url::filter('a', 5);
0 ignored issues
show
Documentation introduced by
5 is of type integer, but the function expects a boolean.

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...
73
    }
74
}
75