Completed
Push — master ( 6a6e14...e9047f )
by Julián
02:21
created

IPTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 9
Bugs 1 Features 0
Metric Value
wmc 5
c 9
b 1
f 0
lcom 1
cbo 4
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreation() 0 5 1
A testBadIp() 0 4 1
A testBadProxyIp() 0 4 1
A testIsExcluded() 0 8 1
A testIsNotExcluded() 0 8 1
1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Test\Excluder;
11
12
use Janitor\Excluder\IP;
13
use Zend\Diactoros\ServerRequestFactory;
14
15
/**
16
 * Class IPTest
17
 */
18
class IPTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $excludedIPs = [
24
        '98.139.183.24',
25
        '74.125.230.5',
26
        '204.79.197.200',
27
    ];
28
29
    public function testCreation()
30
    {
31
        $excluder = new IP;
32
        self::assertFalse($excluder->isExcluded(ServerRequestFactory::fromGlobals()));
33
    }
34
35
    /**
36
     * @expectedException \InvalidArgumentException
37
     */
38
    public function testBadIp()
39
    {
40
        new IP(['invalidIP']);
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testBadProxyIp()
47
    {
48
        new IP(null, 'badIp');
49
    }
50
51
    public function testIsExcluded()
52
    {
53
        $request = ServerRequestFactory::fromGlobals(['REMOTE_ADDR' => '74.125.230.5']);
54
        $request = $request->withHeader('Client-Ip', '74.125.230.5');
55
        $excluder = new IP($this->excludedIPs);
56
57
        self::assertTrue($excluder->isExcluded($request));
58
    }
59
60
    public function testIsNotExcluded()
61
    {
62
        $request = ServerRequestFactory::fromGlobals();
63
        $request = $request->withHeader('X-Forwarded', '80.80.80.80');
64
        $excluder = new IP($this->excludedIPs, ['10.10.10.10']);
65
66
        self::assertFalse($excluder->isExcluded($request));
67
    }
68
}
69