Completed
Push — master ( 3e963f...fbd0cf )
by Yann
02:04
created

InformationGuesserTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A guesser() 0 4 1
A it_return_empty_array_if_no_master_request() 0 8 1
A it_return_array_with_ip_from_master_request() 0 11 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Tests\InformationGuesser;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesser;
8
9
/**
10
 * @author Yann Eugoné <[email protected]>
11
 */
12
class InformationGuesserTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @param RequestStack $requestStack
16
     *
17
     * @return InformationGuesser
18
     */
19
    protected function guesser(RequestStack $requestStack)
20
    {
21
        return new InformationGuesser($requestStack);
22
    }
23
24
    /**
25
     * @test
26
     */
27
    public function it_return_empty_array_if_no_master_request()
28
    {
29
        $requestStack = new RequestStack();
30
31
        $info = $this->guesser($requestStack)->get();
32
33
        self::assertSame([], $info);
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function it_return_array_with_ip_from_master_request()
40
    {
41
        $requestStack = new RequestStack();
42
        $requestStack->push(new Request([], [], [], [], [], ['REMOTE_ADDR' => '88.88.88.88']));
43
44
        $info = $this->guesser($requestStack)->get();
45
46
        self::assertArrayHasKey('ip', $info);
47
        self::assertSame('88.88.88.88', $info['ip']);
48
        self::assertArrayHasKey('host', $info);
49
    }
50
}
51