1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eljam\GuzzleJwt\Tests\Strategy\Auth; |
4
|
|
|
|
5
|
|
|
use Eljam\GuzzleJwt\Strategy\Auth\FormAuthStrategy; |
6
|
|
|
use Eljam\GuzzleJwt\Strategy\Auth\HttpBasicAuthStrategy; |
7
|
|
|
use Eljam\GuzzleJwt\Strategy\Auth\QueryAuthStrategy; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Guillaume Cavavana <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class AuthStrategyTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* testFormAuthStrategy. |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
public function testFormAuthStrategy() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$authStrategy = new FormAuthStrategy( |
20
|
|
|
[ |
21
|
|
|
'username' => 'admin', |
22
|
|
|
'password' => 'admin', |
23
|
|
|
'form_fields' => ['login', 'password'], |
24
|
|
|
] |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->assertTrue(array_key_exists('login', $authStrategy->getRequestOptions()['form_params'])); |
28
|
|
|
|
29
|
|
|
$this->assertTrue(array_key_exists('password', $authStrategy->getRequestOptions()['form_params'])); |
30
|
|
|
|
31
|
|
|
$this->assertEquals('admin', $authStrategy->getRequestOptions()['form_params']['login']); |
32
|
|
|
$this->assertEquals('admin', $authStrategy->getRequestOptions()['form_params']['password']); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* tesQueryAuthStrategy. |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testQueryAuthStrategy() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$authStrategy = new QueryAuthStrategy( |
41
|
|
|
[ |
42
|
|
|
'username' => 'admin', |
43
|
|
|
'password' => 'admin', |
44
|
|
|
'query_fields' => ['username', 'password'], |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertTrue(array_key_exists('username', $authStrategy->getRequestOptions()['query'])); |
49
|
|
|
$this->assertTrue(array_key_exists('password', $authStrategy->getRequestOptions()['query'])); |
50
|
|
|
|
51
|
|
|
$this->assertEquals('admin', $authStrategy->getRequestOptions()['query']['username']); |
52
|
|
|
$this->assertEquals('admin', $authStrategy->getRequestOptions()['query']['password']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* testHttpBasicAuthStrategy. |
57
|
|
|
*/ |
58
|
|
|
public function testHttpBasicAuthStrategy() |
59
|
|
|
{ |
60
|
|
|
$authStrategy = new HttpBasicAuthStrategy( |
61
|
|
|
[ |
62
|
|
|
'username' => 'admin', |
63
|
|
|
'password' => 'password', |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->assertEquals('admin', $authStrategy->getRequestOptions()['auth'][0]); |
68
|
|
|
$this->assertEquals('password', $authStrategy->getRequestOptions()['auth'][1]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.