Completed
Branch proxy (a8ed88)
by leo
08:29
created

testSetProxies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 1
b 0
f 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: leo108
5
 * Date: 2016/10/25
6
 * Time: 14:40
7
 */
8
9
namespace Leo108\CAS\Responses;
10
11
use TestCase;
12
13
class JsonAuthenticationSuccessResponseTest extends TestCase
14
{
15 View Code Duplication
    public function testSetUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $resp = new JsonAuthenticationSuccessResponse();
18
        $resp->setUser('test name');
19
        $data = $this->getData($resp);
20
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['user' => 'test name']]], $data);
21
        $resp->setUser('test name2');
22
        $data = $this->getData($resp);
23
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['user' => 'test name2']]], $data);
24
    }
25
26 View Code Duplication
    public function testSetProxyGrantingTicket()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $resp = new JsonAuthenticationSuccessResponse();
29
        $resp->setProxyGrantingTicket('ticket1');
0 ignored issues
show
Documentation introduced by
'ticket1' is of type string, but the function expects a array.

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...
30
        $data = $this->getData($resp);
31
        $this->assertEquals(
32
            ['serviceResponse' => ['authenticationSuccess' => ['proxyGrantingTicket' => 'ticket1']]],
33
            $data
34
        );
35
        $resp->setProxyGrantingTicket('ticket2');
0 ignored issues
show
Documentation introduced by
'ticket2' is of type string, but the function expects a array.

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...
36
        $data = $this->getData($resp);
37
        $this->assertEquals(
38
            ['serviceResponse' => ['authenticationSuccess' => ['proxyGrantingTicket' => 'ticket2']]],
39
            $data
40
        );
41
    }
42
43
    public function testSetProxies()
44
    {
45
        $resp     = new JsonAuthenticationSuccessResponse();
46
        $proxies1 = ['http://proxy1.com', 'http://proxy2.com'];
47
        $resp->setProxies($proxies1);
48
        $data = $this->getData($resp);
49
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['proxies' => $proxies1]]], $data);
50
51
        $proxies2 = ['http://proxy3.com', 'http://proxy4.com'];
52
        $resp->setProxies($proxies2);
53
        $data = $this->getData($resp);
54
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['proxies' => $proxies2]]], $data);
55
    }
56
57
    public function testSetAttributes()
58
    {
59
        $resp  = new JsonAuthenticationSuccessResponse();
60
        $attr1 = ['key1' => 'value1', 'key2' => 'value2'];
61
        $resp->setAttributes($attr1);
62
        $data = $this->getData($resp);
63
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr1]]], $data);
64
65
        $attr2 = ['key3' => 'value3', 'key4' => 'value4'];
66
        $resp->setAttributes($attr2);
67
        $data = $this->getData($resp);
68
        $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr2]]], $data);
69
    }
70
71
    protected function getData(JsonAuthenticationSuccessResponse $resp)
72
    {
73
        $property = self::getNonPublicProperty($resp, 'data');
74
75
        return $property->getValue($resp);
76
    }
77
}
78