Completed
Push — master ( 7fcbe3...50e2ca )
by Guillaume
23:24
created

AuthStrategyTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 55.93 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 33
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFormAuthStrategy() 17 17 1
A testQueryAuthStrategy() 16 16 1
A testHttpBasicAuthStrategy() 0 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
1 ignored issue
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...
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()
1 ignored issue
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...
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