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() |
|
|
|
|
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() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$resp = new JsonAuthenticationSuccessResponse(); |
29
|
|
|
$resp->setProxyGrantingTicket('ticket1'); |
|
|
|
|
30
|
|
|
$data = $this->getData($resp); |
31
|
|
|
$this->assertEquals( |
32
|
|
|
['serviceResponse' => ['authenticationSuccess' => ['proxyGrantingTicket' => 'ticket1']]], |
33
|
|
|
$data |
34
|
|
|
); |
35
|
|
|
$resp->setProxyGrantingTicket('ticket2'); |
|
|
|
|
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
|
|
|
|
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.