AddrTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAddr() 0 12 1
A testGetAddrForwarded() 0 15 1
A testGetAddrForwardedNotTrusted() 0 15 1
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bouncer;
13
14
use Bouncer\Request;
15
16
class AddrTest extends \PHPUnit_Framework_TestCase
17
{
18
19
    public function testGetAddr()
20
    {
21
        $addr = '46.105.7.208';
22
23
        $server = array();
24
        $server['REMOTE_ADDR'] = $addr;
25
26
        $request = new Request;
27
        $request->initialize(array(), array(), array(), array(), array(), $server);
28
29
        $this->assertEquals($request->getAddr(), $addr);
30
    }
31
32
    public function testGetAddrForwarded()
33
    {
34
        $addr = '46.105.7.208';
35
36
        $server = array();
37
        $server['REMOTE_ADDR'] = '127.0.0.1';
38
        $server['HTTP_X_FORWARDED_FOR'] = $addr;
39
40
        Request::setTrustedProxies(array('127.0.0.1'));
41
42
        $request = new Request;
43
        $request->initialize(array(), array(), array(), array(), array(), $server);
44
45
        $this->assertEquals($request->getAddr(), $addr);
46
    }
47
48
    public function testGetAddrForwardedNotTrusted()
49
    {
50
        $addr = '46.105.7.208';
51
52
        $server = array();
53
        $server['REMOTE_ADDR'] = '127.0.0.1';
54
        $server['HTTP_X_FORWARDED_FOR'] = $addr;
55
56
        Request::setTrustedProxies(array());
57
58
        $request = new Request;
59
        $request->initialize(array(), array(), array(), array(), array(), $server);
60
61
        $this->assertNotEquals($request->getAddr(), $addr);
62
    }
63
64
}
65