IdentityTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequest() 0 20 1
A testGetIdentity() 0 10 1
A testIdentityStatus() 0 11 1
A getBouncer() 0 9 1
A testGetIdentityAddress() 0 12 1
A testGetIdentitySignature() 0 12 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\Resource\Identity;
15
16
class IdentityTest extends \PHPUnit_Framework_TestCase
17
{
18
19
    public function getRequest()
20
    {
21
        $ip = '92.78.176.182';
22
        $ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36';
23
24
        $server = array();
25
        $server['REMOTE_ADDR'] = $ip;
26
        $server['HTTP_USER_AGENT'] = $ua;
27
        $server['HTTP_HOST'] = 'bouncer.h6e.net';
28
        $server['REQUEST_URI'] = '/test';
29
        $server['SERVER_PROTOCOL'] = 'HTTP/1.1';
30
        $server['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
31
        $server['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.8';
32
        $server['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, sdch';
33
34
        $request = new \Bouncer\Request;
35
        $request->initialize(array(), array(), array(), array(), array(), $server);
36
37
        return $request;
38
    }
39
40
    public function getBouncer($request)
41
    {
42
        $bouncer = new Bouncer(array(
43
            'request' => $request,
44
            'profile' => new \Bouncer\Profile\TestProfile,
45
        ));
46
47
        return $bouncer;
48
    }
49
50
    public function testGetIdentity()
51
    {
52
        $request = $this->getRequest();
53
54
        $bouncer = $this->getBouncer($request);
55
56
        $identity = $bouncer->getIdentity();
57
58
        $this->assertEquals('688926c9994666d5d5d4cf7e2429aabd', $identity->getId());
59
    }
60
61
    public function testGetIdentityAddress()
62
    {
63
        $request = $this->getRequest();
64
65
        $bouncer = $this->getBouncer($request);
66
67
        $identity = $bouncer->getIdentity();
68
69
        $address = $identity->getAddress();
70
71
        $this->assertEquals('e90d9f20cce9c203f439129b0943a8bb', $address->getId());
72
    }
73
74
75
    public function testGetIdentitySignature()
76
    {
77
        $request = $this->getRequest();
78
79
        $bouncer = $this->getBouncer($request);
80
81
        $identity = $bouncer->getIdentity();
82
83
        $signature = $identity->getSignature();
84
85
        $this->assertEquals('5a8433a81c1290cc5399eb60f26172d4', $signature->getId());
86
    }
87
88
    public function testIdentityStatus()
89
    {
90
        $identity = new Identity(array(
91
            'reputation' => array(
92
                'threats' => array(),
93
                'status'  => 'bad',
94
            )
95
        ));
96
97
        $this->assertEquals('bad', $identity->getStatus());
98
    }
99
100
}
101