1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Gesdinet\JWTRefreshTokenBundle\Request; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
|
8
|
|
|
class RequestRefreshTokenSpec extends ObjectBehavior |
9
|
|
|
{ |
10
|
|
|
const TOKEN_PARAMETER_NAME = 'refresh_token'; |
11
|
|
|
|
12
|
|
View Code Duplication |
public function it_gets_from_query_param() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$request = Request::createFromGlobals(); |
15
|
|
|
$request->attributes->set(self::TOKEN_PARAMETER_NAME, 'abcd'); |
16
|
|
|
|
17
|
|
|
$this::getRefreshToken($request, self::TOKEN_PARAMETER_NAME)->shouldBe('abcd'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
View Code Duplication |
public function it_gets_from_body() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$request = Request::createFromGlobals(); |
23
|
|
|
$request->request->set(self::TOKEN_PARAMETER_NAME, 'abcd'); |
24
|
|
|
|
25
|
|
|
$this::getRefreshToken($request, self::TOKEN_PARAMETER_NAME)->shouldBe('abcd'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function it_gets_from_json() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array(self::TOKEN_PARAMETER_NAME => 'abcd'))); |
31
|
|
|
$request->headers->set('content_type', 'application/json'); |
32
|
|
|
|
33
|
|
|
$this::getRefreshToken($request, self::TOKEN_PARAMETER_NAME)->shouldBe('abcd'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function it_gets_from_json_x() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array(self::TOKEN_PARAMETER_NAME => 'abcd'))); |
39
|
|
|
$request->headers->set('content_type', 'application/x-json'); |
40
|
|
|
|
41
|
|
|
$this::getRefreshToken($request, self::TOKEN_PARAMETER_NAME)->shouldBe('abcd'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function it_gets_from_json_parameter() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array(self::TOKEN_PARAMETER_NAME => 'abcd'))); |
47
|
|
|
$request->headers->set('content_type', 'application/json;charset=UTF-8'); |
48
|
|
|
|
49
|
|
|
$this::getRefreshToken($request, self::TOKEN_PARAMETER_NAME)->shouldBe('abcd'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
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.