1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Gesdinet\JWTRefreshTokenBundle\Request; |
4
|
|
|
|
5
|
|
|
use Gesdinet\JWTRefreshTokenBundle\NameGenerator\NameGeneratorInterface; |
6
|
|
|
use PhpSpec\ObjectBehavior; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
|
9
|
|
|
class RequestRefreshTokenSpec extends ObjectBehavior |
10
|
|
|
{ |
11
|
|
|
function let(NameGeneratorInterface $nameGenerator) |
12
|
|
|
{ |
13
|
|
|
$this->beConstructedWith($nameGenerator); |
14
|
|
|
|
15
|
|
|
$nameGenerator->generateName('refresh_token') |
16
|
|
|
->willReturn('refresh_token'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function it_gets_from_query_param() |
21
|
|
|
{ |
22
|
|
|
$request = Request::createFromGlobals(); |
23
|
|
|
$request->attributes->set('refresh_token', 'abcd'); |
24
|
|
|
|
25
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function it_gets_from_body() |
29
|
|
|
{ |
30
|
|
|
$request = Request::createFromGlobals(); |
31
|
|
|
$request->request->set('refresh_token', 'abcd'); |
32
|
|
|
|
33
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function it_gets_from_json() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd'))); |
39
|
|
|
$request->headers->set('content_type', 'application/json'); |
40
|
|
|
|
41
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function it_gets_from_json_x() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd'))); |
47
|
|
|
$request->headers->set('content_type', 'application/x-json'); |
48
|
|
|
|
49
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function it_gets_from_json_parameter() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd'))); |
55
|
|
|
$request->headers->set('content_type', 'application/json;charset=UTF-8'); |
56
|
|
|
|
57
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
View Code Duplication |
public function it_gets_from_query_param_using_camel_case_naming(NameGeneratorInterface $nameGenerator) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$nameGenerator->generateName('refresh_token') |
64
|
|
|
->willReturn('refreshToken'); |
65
|
|
|
|
66
|
|
|
$request = Request::createFromGlobals(); |
67
|
|
|
$request->attributes->set('refreshToken', 'abcd'); |
68
|
|
|
|
69
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function it_gets_from_body_using_camel_case_naming(NameGeneratorInterface $nameGenerator) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$nameGenerator->generateName('refresh_token') |
75
|
|
|
->willReturn('refreshToken'); |
76
|
|
|
|
77
|
|
|
$request = Request::createFromGlobals(); |
78
|
|
|
$request->request->set('refreshToken', 'abcd'); |
79
|
|
|
|
80
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function it_gets_from_json_using_camel_case_naming(NameGeneratorInterface $nameGenerator) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$nameGenerator->generateName('refresh_token') |
86
|
|
|
->willReturn('refreshToken'); |
87
|
|
|
|
88
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd'))); |
89
|
|
|
$request->headers->set('content_type', 'application/json'); |
90
|
|
|
|
91
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function it_gets_from_json_x_using_camel_case_naming(NameGeneratorInterface $nameGenerator) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$nameGenerator->generateName('refresh_token') |
97
|
|
|
->willReturn('refreshToken'); |
98
|
|
|
|
99
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd'))); |
100
|
|
|
$request->headers->set('content_type', 'application/x-json'); |
101
|
|
|
|
102
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function it_gets_from_json_parameter_using_camel_case_naming(NameGeneratorInterface $nameGenerator) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$nameGenerator->generateName('refresh_token') |
108
|
|
|
->willReturn('refreshToken'); |
109
|
|
|
|
110
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd'))); |
111
|
|
|
$request->headers->set('content_type', 'application/json;charset=UTF-8'); |
112
|
|
|
|
113
|
|
|
$this->getRefreshToken($request)->shouldBe('abcd'); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
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.