Completed
Pull Request — master (#4)
by
unknown
06:23
created

AuthStrategyTest::testFormAuthStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
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\JsonAuthStrategy;
8
use Eljam\GuzzleJwt\Strategy\Auth\QueryAuthStrategy;
9
10
/**
11
 * @author Guillaume Cavavana <[email protected]>
12
 */
13
class AuthStrategyTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * testFormAuthStrategy.
17
     */
18 View Code Duplication
    public function testFormAuthStrategy()
19
    {
20
        $authStrategy = new FormAuthStrategy(
21
            [
22
                'username' => 'admin',
23
                'password' => 'admin',
24
                'form_fields' => ['login', 'password'],
25
            ]
26
        );
27
28
        $this->assertTrue(array_key_exists('login', $authStrategy->getRequestOptions()['form_params']));
29
30
        $this->assertTrue(array_key_exists('password', $authStrategy->getRequestOptions()['form_params']));
31
32
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['form_params']['login']);
33
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['form_params']['password']);
34
    }
35
36
    /**
37
     * tesQueryAuthStrategy.
38
     */
39 View Code Duplication
    public function testQueryAuthStrategy()
40
    {
41
        $authStrategy = new QueryAuthStrategy(
42
            [
43
                'username' => 'admin',
44
                'password' => 'admin',
45
                'query_fields' => ['username', 'password'],
46
            ]
47
        );
48
49
        $this->assertTrue(array_key_exists('username', $authStrategy->getRequestOptions()['query']));
50
        $this->assertTrue(array_key_exists('password', $authStrategy->getRequestOptions()['query']));
51
52
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['query']['username']);
53
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['query']['password']);
54
    }
55
56
    /**
57
     * testHttpBasicAuthStrategy.
58
     */
59
    public function testHttpBasicAuthStrategy()
60
    {
61
        $authStrategy = new HttpBasicAuthStrategy(
62
            [
63
                'username' => 'admin',
64
                'password' => 'password',
65
            ]
66
        );
67
68
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['auth'][0]);
69
        $this->assertEquals('password', $authStrategy->getRequestOptions()['auth'][1]);
70
    }
71
72
    /**
73
     * testJsonAuthStrategy.
74
     */
75 View Code Duplication
    public function testJsonAuthStrategy()
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...
76
    {
77
        $authStrategy = new JsonAuthStrategy(
78
            [
79
                'username' => 'admin',
80
                'password' => 'admin',
81
                'form_fields' => ['login', 'password'],
82
            ]
83
        );
84
85
        $this->assertTrue(array_key_exists('login', $authStrategy->getRequestOptions()['json']));
86
87
        $this->assertTrue(array_key_exists('password', $authStrategy->getRequestOptions()['json']));
88
89
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['json']['login']);
90
        $this->assertEquals('admin', $authStrategy->getRequestOptions()['json']['password']);
91
    }
92
}
93