LoginActionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 45.83 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 22
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A runAction() 0 6 1
A testViewLogin() 0 5 1
A testLoginSuccess() 11 11 1
A testLoginError() 11 11 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 yii2mod\user\tests\actions;
4
5
use Yii;
6
use yii2mod\user\actions\LoginAction;
7
use yii2mod\user\tests\TestCase;
8
9
/**
10
 * Class LoginActionTest
11
 *
12
 * @package yii2mod\user\tests\actions
13
 */
14
class LoginActionTest extends TestCase
15
{
16
    /**
17
     * Runs the action.
18
     *
19
     * @param array $config
20
     *
21
     * @return string
22
     */
23
    protected function runAction(array $config = [])
24
    {
25
        $action = new LoginAction('login', $this->createController(), $config);
26
27
        return $action->run();
28
    }
29
30
    // Tests:
31
32
    public function testViewLogin()
33
    {
34
        $response = $this->runAction();
35
        $this->assertEquals('@vendor/yii2mod/yii2-user/views/login', $response['view']);
36
    }
37
38 View Code Duplication
    public function testLoginSuccess()
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...
39
    {
40
        Yii::$app->request->bodyParams = [
41
            'LoginForm' => [
42
                'email' => '[email protected]',
43
                'password' => 'password',
44
            ],
45
        ];
46
        $this->runAction();
47
        $this->assertFalse(Yii::$app->user->isGuest);
48
    }
49
50 View Code Duplication
    public function testLoginError()
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...
51
    {
52
        Yii::$app->request->bodyParams = [
53
            'LoginForm' => [
54
                'email' => '[email protected]',
55
                'password' => 'failed-password',
56
            ],
57
        ];
58
        $this->runAction();
59
        $this->assertTrue(Yii::$app->user->isGuest);
60
    }
61
}
62